Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / sed.ps1
Last active September 14, 2018 14:53
sed-like PowerShell command to null out hex codes in registry dumps before diffing
cat .\hklm-after-scm-client-but-before-reboot.reg `
| % {$_ -replace '([0-9a-f][0-9a-f](,|$))+','hex-codes'} `
> ..\RegistryHijinks.edited\hklm-after-scm-client-but-before-reboot.reg
@JohnL4
JohnL4 / sed.cmd
Last active September 14, 2018 14:53
Invoking Cygwin sed via cmd.exe from kdiff3
c:\bin\sed -E /([0-9a-f][0-9a-f],)+\/d
@JohnL4
JohnL4 / ArrayLiteral.java
Created February 21, 2018 04:11
Array literals in Java
someMethod( 12, new String[] {"aaa","bbb","ccc"}, FontType.Bold);
@JohnL4
JohnL4 / Set-JavaHome.ps1
Last active February 2, 2018 16:43
Set string environment variable (e.g., $env:JAVA_HOME) to most-recently-created subdirectory
# So, we're not dependent on filename sort order ("9" > "10").
if (Test-Path "c:/usr/local/Java") {
$env:JAVA_HOME = $(ls c:/usr/local/Java | sort CreationTime -desc | select -first 1 FullName).FullName
}
else {
Write-Warning "No Java"
}
# TODO: could probably use a list of directories to search (e.g., @("c:/usr/local/Java", "c:/Program Files/Java")).
@JohnL4
JohnL4 / install-multiple-dlls.cmd
Last active December 13, 2019 16:02
cmd.exe line to loop over multiple files, installing them to the GAC (since my cmd-fu is weak)
rem (Run Visual Studio Developer Command Prompt as admin)
for %f in (Infragist*.dll) do gacutil -i %f
rem Verify...
gacutil -l | find /i "infragist" | find /i "17.1"
@JohnL4
JohnL4 / literals.ps1
Last active May 26, 2022 18:51
PowerShell syntax for complex literals (array, hash), custom objects and calculated properties
# Hash table syntax is @{ name = value; name = value; ... } -- Curly braces and semicolons
$map = @{ key1 = "value1"; key2 = 3.14 }
echo $map.key1 # "value1"
echo $map["key2"] # 3.14
# Coerce it to a new object
[PSCustomObject] $map
# Btw, you can SELECT a "calculated property" (or synthetic property, if that's how your brain works):
@JohnL4
JohnL4 / od.sh
Created October 25, 2017 19:14
Bash od(1) cmd to show one-byte hex codes + encoded characters.
od -t x1 -t c 'Allscripts Visit Record.htm' | less
# Produces output like the following:
#
# 0000000 ef bb bf 3c 21 44 4f 43 54 59 50 45 20 48 54 4d
# 357 273 277 < ! D O C T Y P E H T M
# 0000020 4c 3e 0d 0a 3c 21 2d 2d 20 73 61 76 65 64 20 66
# L > \r \n < ! - - s a v e d f
# 0000040 72 6f 6d 20 75 72 6c 3d 28 30 33 38 38 29 68 74
# r o m u r l = ( 0 3 8 8 ) h t
@JohnL4
JohnL4 / reveal-header.org
Last active October 18, 2017 17:14
Sample org-mode file header for reveal.js presentations (some some of my standard stuff commented out). (View Raw to see the actual code.)

TypeScript

@JohnL4
JohnL4 / javascript-injection.html
Last active October 4, 2017 14:50
A little piece of Javascript to be entered by users to demonstrate what a problem this can be.
<html>
<head>
</head>
<body>
<script>alert("hi, this is some javascript keyed in by the user");</script>
</body>
@JohnL4
JohnL4 / json-map.ts
Last active January 3, 2018 00:05
Make several kinds of objects to see which is the best type for use with JSON. Includes pattern for making new "naked" objects that can be serialized as JSON.
// An experiment in making several types of objects in order to see what is the best one for use with JSON.
// Object types created are:
// - Object.create(null) - totally blank object, not even inheritance from Object (i.e., not even
// hasOwnProperty()). THIS IS PROBABLY THE WAY TO GO FOR MAKING JSON OBJECTS.
// - new Object() - inherits all base capabilities and properties
// - new Map() - can't be stringified to JSON
//-----------------------------------------------------------------------------------------------------------------
scribble("================ Object.create(null)");
let obj = Object.create(null);