Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Changing codepage simplified

This is an automated version of the codepage changing instructions in snippet 414 ( http://codesnippets.joyent.com/posts/show/414 ). Be sure to read the comments on that snippet for the potential hazards of changing codepage settings.

Save the code as a .bat file and run without parameters for usage instructions.

@echo off
::GOTOs are considered harmful, so I'm a mean, dirty killer ;)
:: Seriously though, I should've used "CALL" and "GOTO :EOF"

REM Read switches

if X%1 == X-view (
  goto ViewCP
)

if X%1 == X-edit (
  goto EditCP
)

REM Catchall: show switch options
goto Usage

:::::::
:ViewCP
REM echo active codepage
chcp
REM echo default codepage:
For /F "Tokens=1,2,3 Delims=	" %%A In ('reg query HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage /v OEMCP ^|findstr OEMCP 

') do @echo Current default codepage: %%C
goto Exit

:::::::
:EditCP
REM Check that a codepage value has been provided
if X%2 == X (
  goto NoParam
) ELSE (
  goto Param  
)

:Param
echo Changing active and default codepages to: %2
echo (usually requires admin rights)
echo.
chcp %2 >nul
reg add HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage /v OEMCP /t REG_SZ /d %2 /f >nul
goto ViewCP
goto Exit

:NoParam
echo ERROR: You must specify a codepage value, e.g. 1252 when using the -edit switch
goto Exit

::::::
:Usage
echo.
echo CodePageChanger Usage
echo.
echo %0 -view
echo %0 -edit CODEPAGENUMBER
echo.
echo (English WinXP default: 850, WinLatin1: 1252)
echo.

:Exit

Log website response times with cURL in windows

This code snippet should be saved as a batch file and run in Windows. It can be set up as a scheduled task to log response times at a fixed interval. It takes one argument, the URL, which should be enclosed in quotes or Windows will barf on URLs with = (equals) signs in. If you don't supply any arguments, you will be prompted. Binary versions of curl are available via google.

If you have ISA:
REM measure response times for a site:
@echo off
IF a%1 == a (
  SET /P varHost=Enter the address, e.g. http://google.com: 
) ELSE (
  SET varHost=%1
)
SET startTime=%date% %time%
curl.exe --proxy-ntlm --proxy yourISAproxy:8080 --proxy-user username:password -s %varHost% > fulloutput.txt
echo %startTime%,%date% %time%,%varHost% >> respTimeLog.txt


If you have no proxy:
REM measure response times for a site:
@echo off
IF a%1 == a (
  SET /P varHost=Enter the address, e.g. http://google.com: 
) ELSE (
  SET varHost=%1
)
SET startTime=%date% %time%
curl -s %varHost% > fulloutput.txt
echo %startTime%,%date% %time%,%varHost% >> respTimeLog.txt