Perl: get file checksum

use Digest::MD5;
use IO::File;

my $chk = Digest::MD5->new();

foreach my $file (@ARGV)
{
    $chk->addfile(IO::File->new($file));

    print "$file -> ",$chk->hexdigest,"\n";
}

The additional details could be found on [...]

Reading password in Unix shell

print -n "Enter Your password:"
stty_orig=`stty -g`
trap "stty ${stty_orig}; exit" 1 2 3 15
stty -echo >&- 2>&-
read PASS
stty ${stty_orig} >&- 2>&-
trap 1 2 3 15
print

trap :catches interruptions. I.e. if the user presses Ctrl+C, the normal stty mode is set before stopping the program
stty -echo :switches off the display echo
>&- 2>&- :helps to avoid [...]

Using the clipboard in WSH

How to get the text from the clipboard

set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
textFromClipboard = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
WScript.Echo textFromClipboard

How to put the text into clipboard

textIntoClipboard = "Some text" & VbCrLf & "Some more text"
 
Set objIE = WScript.CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
Do Until objIE.ReadyState = 4
    WScript.Sleep 100
Loop
 
objIE.document.ParentWindow.ClipboardData.SetData "text", textIntoClipboard
objIE.Quit

The detailed explanation could be [...]

Unix shell: workaround for loop problem

It’s not possible to get the value of the loop variables in some versions of ksh.

Example:

#!/bin/ksh

num=0
cat $0 | while read line ; do
 let num=num+1
done

echo "Number=$num"

This script will return “Number=0″ as the result on some Linux machines.

Here is the workaround for the problem: You should change the redirection method for the input file.

#!/bin/ksh

l=0
while read line ; do
 let [...]

JavaScript: edit web page in browser

Here is small bookmarklet, which allows to edit the web page for any site (ok, You could save the results on Your local machine only).

javascript:document.body.contentEditable=’true’; document.designMode=’on’; [...]

JavaScript: Soundex implementation

There is a special algorithm for comparision strings, which sound similar (Soundex).

Here is JavaScript Soundex implementation:

function soundex ( s_src )
{    
 var s_rez = "0000" ;
 var new_code, prev, idx
 
 a_codes = { "bfpv": 1, "cgjkqsxz":2, "dt": 3, "l": 4, "mn": 5, "r": 6 };
 
 s_src = s_src.toLowerCase().replace(/ /g,"")
 
 if ( s_src.length < 1) {
   return(s_rez);
 }
 
 s_rez = s_src.substr(0,1);
 prev = "0";
 
 for [...]

Office: check if PowerPoint is running

Dim objAPP, sMsg

On Error Resume Next

Set objAPP = GetObject(, "PowerPoint.Application")

If TypeName(objAPP) = "Empty" Then
    sMsg = "not started"
Else
    sMsg = "started"
End If

MsgBox "PowerPoint is " & sMsg, vbInformation, "PowerPoint"

if sMsg = "started" then objAPP.Visible [...]

WMI: list of the methods and properties

strComputer = "."
Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
For Each objclass in objWMIService.SubclassesOf()
    intCounter=0
    If Left(objClass.Path_.Class,5) = "Win32" Then
        For Each Qualifier in objClass.Qualifiers_
            If UCase(Trim(Qualifier.Name)) = "ASSOCIATION" Then
                intCounter = 1
            End If
    [...]

WMI: get the information about the system

Option Explicit
On Error Resume Next

Dim strComputer, objWMIService
Dim colItems, objItem

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
 strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

For Each objItem in colItems
WScript.Echo "Machine Name: " & objItem.CSName & VbCr & _
"===================================" & vbCr & _
"Description: " & objItem.Description & VbCr & _
"Manufacturer: " & objItem.Manufacturer [...]

WMI+VBS: how to get the domain name

Option Explicit
On Error Resume Next

Dim strComputer, objNetwork, objWMIService
Dim colItems, objItem

Set objNetwork = WScript.CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
WScript.Echo "Computer = " & strComputer

Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&strComputer&"\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objItem in colItems
 Wscript.Echo "Domain = " & objItem.domain
Next

There is also WMI FAQ on [...]