Duplex Printing With Two Sides Per Page
Save the following code with a .hta extension and run. Yeah, I know, really advanced error handling. But who cares? It works for me ;-)
<html>
<head>
<title>Two Pages/Sheet Duplex Printing</title>
<HTA:APPLICATION
ID="DuplexPrinting"
APPLICATIONNAME="DuplexPrinting"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<SCRIPT Language="VBScript">
' Program Start
Sub Window_onLoad
window.resizeTo 450,400
End Sub
'Displays formatted information in a new window
Sub RunScript
intPageCount = NumberOfPagesToPrint.Value
If ( intPageCount < 5 ) or ( not IsNumeric( intPageCount ) ) Then WScript.Quit 0 End If
intStart = intPageCount
intEnd = intPageCount
If ( intPageCount Mod 2 = 0 ) Then
REM Page count is even
If ( intPageCount / 2 ) Mod 2 = 0 Then
REM All pages will be fully printed
intEnd = intPageCount - 3
intStart = intPageCount - 5
strLastRun = intPageCount - 1 & "-" & intPageCount
Else
REM Last Page of first run shoult not be used as first page for last run --> skip it
strIntermediateStep = "Remove last page (top most) from stack"
intEnd = intPageCount
intStart = intPageCount - 7
strLastRun = intPageCount - 3 & "-" & intPageCount - 2
End If
Else
REM Page count is odd
If ( ( intPageCount + 1 ) / 2 ) Mod 2 = 0 Then
REM Single page on second side
strLastRun = intPageCount - 4 & "-" & intPageCount - 3
intStart = intPageCount - 8
strPostfix = ""
REM Add Intermediate Step - otherwise two pages would be printed on first sheet
strIntermediateStep = intPageCount
Else
REM Single page on first side
intEnd = intPageCount - 4
strLastRun = intPageCount - 2 & "-" & intPageCount - 1
intStart = intPageCount - 6
strPostfix = ", " & intPageCount
REM Remove last page - otherwise a blank first second side of first sheet would appear
strIntermediateStep = "Remove last page from stack"
End If
End If
REM Create First Run =============
strFirstRun = "1-2"
For i = 5 to intEnd Step 4
strFirstRun = strFirstRun & ", " & i & "-" & i + 1
Next
strFirstRun = strFirstRun & strPostfix
REM ==============================
REM Create First Run =============
For i = intStart to 3 Step -4
strLastRun = strLastRun & ", " & i & "-" & i + 1
Next
REM ==============================
BasicTextArea.Value = strFirstRun & vbCrLf & vbCrLf & strIntermediateStep & vbCrLf & vbCrLf & strLastRun
End Sub
</SCRIPT>
<body>
<div align="center">
<p>Please enter the number of pages you will be printing:
<p>
<input type="text" name="NumberOfPagesToPrint" size="10">
<input id=calculatebutton class="button" type="button" value="Calculate" name="calculate_button" onClick="RunScript">
</p><p>
<textarea name="BasicTextArea" rows="15" cols="50" style="border:none; " readonly="readonly">
</p>
</div>
</body>
</html>
Cool commandline moves
FOR /L %f IN (1,1,254) DO ping -w 500 -n 1 192.168.1.%f | findstr /I reply >> %TEMP%\ping_results.txt
T-SQL Simple Timestamp With Leading Zeros
I just had to create a simple string in MS T-SQL that would look like the following:
200812041613
or
yyyymmddhhmm
I solved it this way but I have no idea if this is a good solution (comments welcome):
DECLARE @timestamp AS varchar(12) -- Create Timestamp with leading zeros -- Year SET @timestamp = CONVERT( varchar(4), DATEPART(year, GETDATE() ) ) -- Month IF DATEPART( month, GETDATE() ) < 10 SET @timestamp = @timestamp + '0' + CONVERT( varchar, DATEPART( month, GETDATE() ) ) ELSE SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( month, GETDATE() ) ) -- Day IF DATEPART( day, GETDATE() ) < 10 SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( day, GETDATE() ) ) ELSE SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( day, GETDATE() ) ) -- Hour IF DATEPART( hour, GETDATE() ) < 10 SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( hour, GETDATE() ) ) ELSE SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( hour, GETDATE() ) ) -- Minute IF DATEPART( minute, GETDATE() ) < 10 SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( minute, GETDATE() ) ) ELSE SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( minute, GETDATE() ) ) -- Done creating timestamp print N'' + @timestamp
Automatically Create IIS Application Pools
Here is the script for the AppPools
@ECHO OFF ECHO. FOR /F "eol=# delims=; tokens=1,2*" %%f in (apppools.txt) DO ( ECHO Creating AppPool "%%f" with user identity "%%g" CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS CREATE "w3svc/AppPools/%%f" IIsApplicationPool CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserName" "%%g" CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserPass" "%%h" CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/AppPoolIdentityType" 3 ECHO. ) pause
And the correspondign text file:
# # ";"-delimited file to create application pools # Beware of strange characters in password, # though ; should work # Structure is # # AppPool Name ; User ; Password tmpAppPool;tmpUser;tmpPass
Automatically Create IIS Websites
I had to create quite a lot websites on a Microsoft IIS webserver and of course there is a nice scripting solution to it. Here is how I did it:
Batch code:
@ECHO OFF SET webRoot=D:\websites ECHO. ECHO Creating directories ECHO and websites ECHO. FOR /F "eol=# delims=; tokens=1,2*" %%f in (websites.txt) DO ( ECHO Creating Dir %webRoot%\%%f\%%g and website %%g in appPool %%h MD "%webRoot%\%%f\%%g" iisweb /create "%webRoot%\%%f\%%g" "%%g" /i 192.168.228.30 /d %%g.perimeterless.org /ap %%h ECHO. ) pause
and here is the text file that goes with it:
# # ";"-delimited file to create directory structure, # websites and application pools # # Structure is # # Subdirectory ; Sitename ; AppPool testing;test1;DefaultAppPool testing;test2;DefaultAppPool testing;test3;DefaultAppPool
Mount ISO images in Konqueror / Dolphin
I didn’t want to bring up a console every time I had to mount an ISO image. So I browsed the web a lil’ bit and found a good solution for my needs. I am a big fan of context menus or service menus as they are called in KDE. These menus are configured through .desktop files. To create such a file only a few steps are necessary:
- Find out the location of .desktop files
- Learn about the syntax of a .desktop file
- Check the mime type of the file where the context menu should appear
- Some eye candy with Icons and submenus
In the end you will have entries under Actions when you right-click on and ISO image that look somewhat like this:

1. Where are these files?
You can use
kde-config --prefix
to find out where your KDE has been installed. You will then find a folder
/usr/share/apps/konqueror/servicemenus (in my case)
Here you create a file with any name you like it only must end with .desktop
Since there now also is a noob file manager Dolphin there also is a folder
/usr/share/apps/d3lphin/servicemenus
Anyway, I used a symbolic link to only have to configure one file for both apps.
2. File syntax
Mine looks like this:
[Desktop Entry] ServiceTypes=application/x-iso Actions=mountIsoImage;umountIsoImage X-KDE-Submenu=ISO Image [Desktop Action mountIsoImage] Name=Mount Icon=cdrom_mount Exec=kdesu -c 'mount -o loop -t iso9660 %f /mnt/iso' [Desktop Action umountIsoImage] Name=Unmount Icon=cdrom_unmount Exec=kdesu -c 'umount %f'
Here you’ll find a good explanation of the file options.
3. MIME type
As you can see you must declare a ServiceType in the .desktop file. This defines when the context menu should appear. A good way to search for these types is to go to Settings -> Configure Konqueror -> File Associations and use the search feature.
4. Eye candy
You may use you own icon images but if you want to use the system icons I suggest editing a K-Menu entry, clicking on the icon and then using the icon browser to find a name of an icon you like.
REMARK
This is tested with Kubuntu Gutsy Gibbon. But I guess it should also work with other distributions.
IMPROVEMENTS
Instead of using the mount command more or less directly one could use a script to create a temporary folder at the current location where the ISO is then mounted. Unmounting would delete the folder again.
