Rss Directory > Programming > Code > dewww
 
  Tue, 14 Nov 2006 15:55:00 +0100
CLR v2 uses FIPS validated cryptographic algorithms as default(SHA for hashing)
Cryptographic hash function
#hasher.ps1
#http://dewww.blogspot.com/
#
#Examples
#hasher.ps1 "dewww" md5 ascii
#hasher.ps1 C:\boot.ini SHA512
#
function hashScript([string]$target, [string]$alg=$("SHA"), [string]$enc=$("ascii"))
{
$result
$data
        if ([System.IO.File]::Exists($target))
        {
        $data=new-object System.IO.FileStream($target, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read)
        }
        else
        {
        $data=[System.Text.Encoding]::GetEncoding($enc).GetBytes($target)
        }

        foreach($b in [System.Security.Cryptography.HashAlgorithm]::Create($alg).ComputeHash($data))
        {
        $result+=[String]::Format("{0:X}",$b)
        }
return ($result.toLower())
}

function usage()
{
return "Computes hash
        hasher.ps1 arg [alg [enc]]

        arg = file | string
                is file if exists else string

        alg = MD5 | SHA | SHA256 | SHA384 | SHA512
                dafault is SHA(FIPS)

        enc = unicode | UTF-16BE | windows-1252 | utf-7 | utf-8 | ascii | GB18030
                used if arg is string
                dafault is ascii"
}

##### main #####
        if ( $args.Length -eq 1 -and $args[0] -ne "?" -and $args[0] -ne "/?" -and $args[0] -ne "-?")
        {
                write-output $(hashScript $args[0])
        }
        elseif ( $args.Length -eq 2 )
        {
                write-output $(hashScript $args[0] $args[1])
        }
        elseif ( $args.Length -eq 3 )
        {
                write-output $(hashScript $args[0] $args[1] $args[2])
        }
        else
        {
                write-output $(usage)
        }

"This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms."
Turn off FIPSAlgorithmPolicy for managed HashAlgorithms(MD5/SHA256/SHA384/SHA512)

Registry
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"FIPSAlgorithmPolicy"=dword:00000000

GUI
start -> Control Panel -> Administrative Tools -> Local Security Policy -> Local Policies -> Security Options ->
System Cryptography: Use FIPS compilant algorithms for encryption, hashing, and signing -> Disabled

Ref
Enforcing FIPS Certified Cryptography
  Sat, 11 Nov 2006 18:04:00 +0100
IP to Base 10/Base10 to IP scripts

IP to Base 10
#ip2b10.ps1
#http://dewww.blogspot.com/
#ip2b10.ps1 <ipaddress>
$ip=$args[0].Split(".")
$a=([int64]::Parse($ip[0]).ToString("x2"))
$b=([int64]::Parse($ip[1]).ToString("x2"))
$c=([int64]::Parse($ip[2]).ToString("x2"))
$d=([int64]::Parse($ip[3]).ToString("x2"))
Write-Output $([int64]::Parse($a+$b+$c+$d, [System.Globalization.NumberStyles]::HexNumber))

Ip to Base 10 alternate method
#ip2b10pow.ps1
#http://dewww.blogspot.com/
#ip2b10exp.ps1 <ipaddress>
$ip=$args[0].Split(".")
write-output $(
[int64]::Parse($ip[0])*[math]::Pow(256,3) +
[int64]::Parse($ip[1])*[math]::Pow(256,2) +
[int64]::Parse($ip[2])*[math]::Pow(256,1) +
[int64]::Parse($ip[3])
)

Base10 to IP
#b102ip.ps1
#http://dewww.blogspot.com/
#b102ip.ps1 <base10>
$tmp=[int64]::Parse($args[0]).ToString("x8")
$hex=[System.Globalization.NumberStyles]::HexNumber
$a=[int64]::Parse($tmp.substring(0,2), $hex)
$b=[int64]::Parse($tmp.substring(2,2), $hex)
$c=[int64]::Parse($tmp.substring(4,2), $hex)
$d=[int64]::Parse($tmp.substring(6,2), $hex)
Write-Output $([string]::Format("{0}.{1}.{2}.{3}", $a, $b, $c, $d))

Ref
Abc of an IP Address
  Fri, 10 Nov 2006 22:30:00 +0100
Countdown to wii release date script
wii
#wii.ps1
#http://dewww.blogspot.com/
Write-Output $([string]::Format("{0} days to wii North American launch (November 19 2006)",
$([System.DateTime]::Parse("11/19/2006")-[System.DateTime]::Now.Date).days
))

Write-Output $([string]::Format("{0} days to wii Japan launch (December 2 2006)",
$([System.DateTime]::Parse("12/2/2006")-[System.DateTime]::Now.Date).days
))

Write-Output $([string]::Format("{0} days to wii European launch (December 8 2006)",
$([System.DateTime]::Parse("12/8/2006")-[System.DateTime]::Now.Date).days
))
  Thu, 09 Nov 2006 10:10:00 +0100
Make svg scale inside host container(viewing client or html object)
Scalable Vector Graphics

using sample
http://upload.wikimedia.org/wikipedia/commons/6/62/PD-icon.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
        "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="220px" height="220px" xmlns="http://www.w3.org/2000/svg" version="1.1">
        <circle cx="110" cy="110" r="98" fill="#808080"/>
        <circle cx="110" cy="110" r="78" fill="white"/>
        <circle cx="110" cy="110" r="55" fill="#808080"/>
        <circle cx="110" cy="110" r="27" fill="white"/>
        <rect x="135" y="97" width="31" height="25" fill="white"/>
        <path d="M 140,61 L 61,140 L 83,159 L 161,81 z" fill="white"/>
        <path d="M 160,44 L 44,160 L 62,177 L 177,62 z" fill="#808080"/>
</svg>

change
<svg width="220px" height="220px" xmlns="http://www.w3.org/2000/svg" version="1.1">

to
<svg viewBox="0 0 <width> <height>" xmlns="http://www.w3.org/2000/svg" version="1.1">

done
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
        "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 220 220" xmlns="http://www.w3.org/2000/svg" version="1.1">
        <circle cx="110" cy="110" r="98" fill="#808080"/>
        <circle cx="110" cy="110" r="78" fill="white"/>
        <circle cx="110" cy="110" r="55" fill="#808080"/>
        <circle cx="110" cy="110" r="27" fill="white"/>
        <rect x="135" y="97" width="31" height="25" fill="white"/>
        <path d="M 140,61 L 61,140 L 83,159 L 161,81 z" fill="white"/>
        <path d="M 160,44 L 44,160 L 62,177 L 177,62 z" fill="#808080"/>
</svg>

Render it proportional(ViewBox) inside host container(html object)
<object type="image/svg+xml" data="http://<domain>/PD-icon.svg" width="400" height="400">
your web browser does not interpret SVG images
</object>

Ref
ViewBoxAttribute
carto:net - Example for viewbox control
  Tue, 07 Nov 2006 22:43:00 +0100
Powershell supply pipeline or arguments to cmdlet scripts
#pipe_args.ps1
#http://dewww.blogspot.com/
#
#Examples
#echo "foo bar" "bar foo" "foo" | pipe_args.ps1
#pipe_args.ps1 foo bar
#
begin
{
#logic
        function parseParamsCallMain([string]$caller, [array]$params)
        {
                if (1 -eq $params.length)
                {
                        #check if user wants help
                        if ("?" -eq $params[0] -or "/?" -eq $params[0] -or "-?" -eq $params[0])
                        {
                        write-host "help"
                        write-host "usage varA [varB]"
                        }
                        else
                        {
                        main $caller $params[0]
                        }
                }
                elseif (2 -eq $params.length)
                {
                main $caller $params[0] $params[1]
                }
                else
                {
                write-host "syntax error"
                write-host "usage varA [varB]"
                }
        }

        function main([string]$caller=$("no_callers"), [string]$varA=$("varA_is_empty"), [string]$varB=$("varB_is_empty"))
        {
        Write-Output $([string]::Format("caller:{0} | varA:{1} | varB:{2}", $caller, $varA, $varB))
        }

}
process
{
        #check pipeline
        if ($_)
        {
        parseParamsCallMain "pipeline" $_.Split(" ")
        }
}
end
{
        #check args
        if ($args)
        {
        parseParamsCallMain "arguments" $args
        }
        else
        {
                #args and pipeline is empty
                if (!$_)
                {
                write-host "pipe or supply args"
                write-host "usage varA [varB]"
                }
        }
}

Ref
MSH: Get Extended Properties of a File
Accepting Pipeline Input in PowerShell Scripts and Functions
  Sat, 04 Nov 2006 21:09:00 +0100
  Fri, 03 Nov 2006 20:28:00 +0100
Bookmark shoutcast stations or other playlists in winamp
winamp / playlist / shoutcast / .pls

Path
%ProgramFiles%\winamp\winamp.bm

Format
http://<domain>/<filename>.pls
<playlistname>
  Thu, 02 Nov 2006 11:01:00 +0100
Block ad/malware servers
hosts file / Firefox  / adblock / adblock plus / Opera

Filters
the MVPS HOSTs File
hosts

Andrew Short (sh0rtie) - the Hosts File Project
hosts / adblock

Dan Pollock - how to make the internet not suck (as much)
hosts

Mike Skallas - Mike's Ad Blocking Hosts file
hosts

James Moberg - How To Block Ads (& Web Bugs) Without Extra Software
hosts

Peter Lowe - adservers
hosts / adblock / urlfilter

Bluetack's HOSTS File
hosts

Fanboy
adblock / urlfilter

Andre Correa - Malware Block List
hosts agressive test / adblock regular

Malware URL List
http://isc.sans.org/urllist.php

Share your Adblock list !
adblock

Adblock Filterset Generator (beta)
adblock

filtersetX
adblock

trackersetX
adblock

Gunnars Filter
adblock

Adrian G. Kousz
adblock

Al Redzs
adblock W-bug-Blocker(beta) /adblock WBB-Whitelist(beta) /adblock P-Blocker(beta) /adblock Website blacklist(beta)

FiltersetP
adblock

Suda
adblock

Known Adblock Plus subscriptions
EasyList
EasyElement
Cédrics Liste
dutchblock
Filters by Dr. Evil
Filters by Dr. Evil - "Element Hiding"
Fanboy’s List
adblock.free.fr complete
adblock.free.fr basic
ChinaList
Corset
RU AdList
JAB Creations
jamieplucinski.com

Paths
Windows 95/98/Me hosts
%windir%\hosts

Windows NT/2000/XP/Vista hosts
%SystemRoot%\system32\drivers\etc\hosts

Firefox(about:config)
%AppData%\Mozilla\Firefox\Profiles\<xxxxxxxx>.default\prefs.js

Firefox adblock plus
%AppData%\Mozilla\Firefox\Profiles\<xxxxxxxx>.default\adblockplus\patterns.ini

Opera
%AppData%\Opera\Opera\profile\urlfilter.ini

Format
Hosts
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
127.0.0.1 block.ad.servers

Firefox adblock(import/export)
[Adblock]
@@|http://www.mozilla.org/
http://block.ad.servers/*

Firefox adblock(prefs.js/about:config)
# Mozilla User Preferences

/* Do not edit this file.
*
* If you make changes to this file while the application is running,
* the changes will be overwritten when the application exits.
*
* To make a manual change to preferences, you can visit the URL about:config
* For more information, see http://www.mozilla.org/unix/customizing.html#prefs
*/
...
user_pref("adblock.patterns", "http://block.ad.servers/* @@|http://www.mozilla.org/");
...

Firefox adblock plus(import/export/subscription)
(Adblock Plus 0.6.1.2 or higher required) [Adblock]
@@|http://www.mozilla.org/
http://block.ad.servers/*

Firefox adblock plus(patterns.ini)
# Adblock Plus preferences
[User patterns]
@@|http://www.mozilla.org/
http://block.ad.servers/*

Firefox adblock plus(prefs.js/about:config)
# Mozilla User Preferences

/* Do not edit this file.
*
* If you make changes to this file while the application is running,
* the changes will be overwritten when the application exits.
*
* To make a manual change to preferences, you can visit the URL about:config
* For more information, see http://www.mozilla.org/unix/customizing.html#prefs
*/
...
user_pref("extensions.adblockplus.patterns", "http://block.ad.servers/* @@|http://www.mozilla.org/");
...

Opera content filter(urlfilter.ini)
Opera Preferences version 2.1
; Do not edit this file while Opera is running
; This file is stored in UTF-8 encoding

[prefs]
prioritize excludelist=1

[include]
*

[exclude]
http://block.ad.servers/*