Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / scribble.ts
Created July 24, 2017 19:52
In TypeScript playground, a function to write directly to the window, rather than just debugger console.
/**
* Write the given message in a PRE element of the document.
*/
function scribble(aMsg: string): void {
console.log(aMsg);
// Get a reference to the document's PRE element, or null if there isn't one.
var preElt = document.body.querySelector("pre");
if (preElt) {
// Do nothing, we're good
// console.log("got preElt");
@JohnL4
JohnL4 / prompt.cmd
Created August 28, 2017 19:15
Reverse-video cmd.exe prompt; might need ANSICON for this to work in Win 7, but it works out of the box in Win 10.
@rem $E - escape
@rem ESC [ 7 m - reverse video
@rem ESC [ 0 m - normal mode
@rem $P - current path
@rem @G - greater-than sign
@rem $S - space
@prompt $E[7m$P$G$E[0m$S
@JohnL4
JohnL4 / play01.ts
Last active August 30, 2017 18:49
Simple horsing around to demonstrate what TypeScript does (paste into playground at typescriptlang.org)
// ============================================================================================
// Typescript is Javascript annotated with type info.
// "Compilation" of Typescript is (in the simple case)
// stripping out the type annotations.
var someNumber: number;
someNumber = 2;
someNumber = "bad"; // Type mismatch
// A slightly fancy way of telling Typescript that this variable is
@JohnL4
JohnL4 / popup-dialog.ps1
Created August 31, 2017 18:39
Show a dialog box from PowerShell w/out first adding DLLs
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Operation Completed",0,"Done",0x1)
# From https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/04/powertip-use-powershell-to-display-pop-up-window/
@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);
@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 / 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 / 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 / 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 / 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"