Skip to content

Instantly share code, notes, and snippets.

@ijprest
ijprest / guidgen.ahk
Created October 6, 2012 20:00
AutoHotkey (AHK) script to generate & paste a new GUID
; Exposes two hotkeys:
; - Win+G generates & pastes a new lowercase guid
; - Win+Shift+G generates & pastes a new UPPERCASE guid
; In both cases, the guid is left on the clipboard so you can easily paste it more than once.
;
GUID()
{
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
VarSetCapacity(A,16)
@ijprest
ijprest / toupper.bat
Created September 10, 2011 01:52
CMD Batch file implementation of toupper() and tolower()
@echo off & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET STR=Test String
SET STR
call :tolower STR
SET STR
call :toupper STR
set STR
goto :EOF
:: toupper & tolower; makes use of the fact that string
@ijprest
ijprest / tohex.bat
Created September 10, 2011 02:07
CMD Batch file conversion of a decimal number to hex
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set LOOKUP=0123456789abcdef &set HEXSTR=&set PREFIX=
if "%1"=="" echo 0&goto :EOF
set /a A=%* || exit /b 1
if !A! LSS 0 set /a A=0xfffffff + !A! + 1 & set PREFIX=f
:loop
set /a B=!A! %% 16 & set /a A=!A! / 16
set HEXSTR=!LOOKUP:~%B%,1!%HEXSTR%
if %A% GTR 0 goto :loop
echo %PREFIX%%HEXSTR%
@ijprest
ijprest / IniFile.psm1
Created April 13, 2015 00:57
Powershell function to read a standard Windows INI file (using Win32 APIs)
#requires -Version 2
Add-Type -Name _e9b6b3c331bdc58f488487320803ad89 -namespace _e95bcd88febe44bf44ad6600fdd509e7 -MemberDefinition @'
[DllImport("kernel32",CharSet=CharSet.Unicode)] public static extern int GetPrivateProfileStringW(string section, string key, string def, IntPtr retVal, int size, string filePath);
[DllImport("kernel32",CharSet=CharSet.Unicode)] public static extern int GetPrivateProfileStringW(string section, IntPtr key, string def, IntPtr retVal, int size, string filePath);
[DllImport("kernel32",CharSet=CharSet.Unicode)] public static extern int GetPrivateProfileStringW(IntPtr section, IntPtr key, string def, IntPtr retVal, int size, string filePath);
[DllImport("kernel32",CharSet=CharSet.Unicode)] public static extern long WritePrivateProfileStringW(string section, string key, string val, string filePath);
'@
function Read-IniFile {
<#
.SYNOPSIS
@ijprest
ijprest / convert-to-amd.js
Created July 20, 2015 23:49
Very simple script to convert a normal JS module to a RequireJS-compatible AMD module; intended for command-line usage, and integration into build systems.
#!/usr/bin/env node
///
/// Very simple script to convert a normal JS module to a RequireJS-compatible
/// AMD module; intended for command-line usage, and integration into build
/// systems.
///
/// Reads from stdin & writes to stdout; output can be piped to uglifyjs to
/// minify/compress the code.
///
/// Examples:
param (
[string]$UserName = "$((Get-ChildItem Env:USERDOMAIN).Value)\$((Get-ChildItem Env:USERNAME).Value)",
[string]$Password = $(Read-Host "Enter a password for user '$UserName'")
)
# Set up auto-logon
$resumed = 0
$auditing = 0
if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State").ImageState -ne "IMAGE_STATE_COMPLETE") {
$auditing = 1
@ijprest
ijprest / setprompt.bat
Created September 15, 2011 03:14
CMD Batch file to put a separator between each command you run at the prompt
@echo off
for /f "tokens=1,2 delims=: " %%Q IN ('mode con:') DO IF "%%Q"=="Columns" SET _COLS=%%R
SET /A _COLS=%_COLS% - 13
SET _P=
:loop
SET _P=%_P%-
SET /A _COLS=%_COLS% - 1
IF %_COLS% GTR 0 goto :loop
SET PROMPT=%_P%$S$T$_$P$G
@ijprest
ijprest / strlen.bat
Created September 1, 2011 03:41
CMD Batch file implementation of strlen
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
call :strlen "%~1"
echo strlen("%~1") == !ERRORLEVEL!
goto :EOF
:strlen
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set __LEN=0
@ijprest
ijprest / commodore-vic20.kbd.json
Last active August 29, 2015 14:26
Commodore VIC-20
[
{
"backcolor": "#e8e1ca"
},
[
{
"x": 0.25,
"c": "#413c2c",
"t": "#f1ecda",
"p": "SA R1",
@ijprest
ijprest / colors.js
Last active August 29, 2015 14:26 — forked from mikelikespie/colors.js
Quick code to convert sRGB to CIE L*a*b* and back.
var $color = {};
(function () {
function Lab (l, a, b) { this.l = l; this.a = a; this.b = b; }
$color.Lab = function (l,a,b) { return new Lab(l,a,b); };
function XYZ (x, y, z) { this.x = x; this.y = y; this.z = z; }
$color.XYZ = function (l,a,b) { return new XYZ(x, y, z); };
function sRGBLinear (r, g, b) { this.r = r; this.g = g; this.b = b; }
$color.sRGBLinear = function (r,g,b) { return new sRGBLinear(r,g,b); };