Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / TraceSourcePlay.cs
Last active December 9, 2016 21:46
Playing around with .NET TraceSource, a nicer "primitive" way of debug/trace logging than just using {Debug,Trace}.WriteLine(). More "primitive" (and lighter weight) than Enterprise Library logging.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace TraceSourcePlay
{
@JohnL4
JohnL4 / Start-Process-MsiExec.ps1
Last active December 2, 2016 21:55
Running msiexec as Administrator and getting the argument quoting right.
$VerbosePreference="Continue"
ls .\AllscriptsGateway, .\HCServer, .\EntMgr | ? {$_.Name -match '\.msi$'} | % {sudo msiexec ('/f "' + $_.FullName + '"'),'/passive'}
# VERBOSE: Start-Process «msiexec» -ArgumentList «/f "C:\SCM-Setup\Installers\AllscriptsGateway\Allscripts Gateway 16.3 (488).msi"»,«/passive»
# VERBOSE: Start-Process «msiexec» -ArgumentList «/f "C:\SCM-Setup\Installers\HCServer\Helios Connect 16.3.msi"»,«/passive»
# VERBOSE: Start-Process «msiexec» -ArgumentList «/f "C:\SCM-Setup\Installers\EntMgr\Enterprise Manager for Sunrise Enterprise 16.3 (488).msi"»,«/passive»
# Look at me, all fancy with my Unicode guillemet characters!
<#
@JohnL4
JohnL4 / Make-Zips.ps1
Last active February 7, 2020 16:31
PowerShell cmd to zip up a directory while excluding multiple subdirectories
ls -rec | ? {-not ($_.FullName -match '\\(NUnitConsole|TestRun)\\')} | write-zip -output "$(datefn).zip"
#### If you want to get fancier...
# (1) Make a list of files touched in the last hour.
$fs = ls c:\work\sxa\18.4cu2\Projects\VisitRecord\VRDotNet\Portal\SXA.VR.Portal\bin `
| ? {$_.LastWriteTime -ge (Get-Date).AddMinutes(-60)}
# (2) Add to it. The '+=' operator actually makes a new Array by copying the old Array + the entry(ies).
@JohnL4
JohnL4 / tide-config.el
Last active September 26, 2017 11:41
emacs tide (typescript-mode) configuration
(add-hook 'typescript-mode-hook
(lambda ()
(tide-setup)
(flycheck-mode +1)
(eldoc-mode +1)
(company-mode)
(setq fill-column 120)
(local-set-key "\C-j" 'newline)
(local-set-key "\r" 'newline-and-indent) ;Auto-indent.
(local-set-key "\M-o" 'one-line-section-break)
@JohnL4
JohnL4 / lazyfileplay.hs
Created March 18, 2016 14:07
Example of an unused IO operation in a "do" block executed regardless of the fact that it's unused
import System.IO
main = do
inText <- getContents
let inWords = words inText
result <- f ( read (inWords !! 0) :: Int)
putStrLn result
f :: Int -> IO String
f x = do
<#
.SYNOPSIS
Topological sort of dependency graph (or any DAG)
.INPUTS
List of lists of objects (or strings). Each inner list consists of an object (the head of the list) and other
objects ON WHICH it depends. Thing A "depends" on Thing B if Thing B must be processed before Thing A.
.OUTPUTS
List of input objects sorted in such a way that objects that don't depend on anything occur before objects which
depend on them. (You could consider that to be a reverse-topological sort.)
.EXAMPLE
@JohnL4
JohnL4 / Make-MD5Hash.ps1
Last active November 16, 2015 18:12
PowerShell snipper to make an MD5 hash string from an arbitrary string
$stringToBeHashed = "[email protected]"
$md5Hash = [Security.Cryptography.MD5]::Create()
$hashBytes = $md5Hash.ComputeHash($stringToBeHashed.ToCharArray())
$hashString = ""
foreach ($b in $hashBytes) { $hashString = $hashString + $b.ToString("x2")}
$hashString
# http://www.gravatar.com/avatar/cd0858865a889264c5d383a0abca2eaf?d=identicon
@JohnL4
JohnL4 / curl.ps1
Last active November 4, 2015 20:55
In PowerShell, dump a dictionary out to the console formatted as a table of key-value rows, with automatic column width and long text wrapped w/in the column
$(curl -uri https://rubygems.org/gems/jekyll-feed).Headers | ft -auto -wrap
<#
$(cmd) is PowerShell's equivalent of bash's backtick command interpolation (`cmd`).
"curl" is a built-in alias for Invoke-WebRequest.
The result of $(cmd) is an object (PowerShell pipes objects, not text), so
".Headers" selects that object property.
The Headers property is a dictionary, so we feed that into Format-Table (built-in alias "ft"),
specifying auto-width and text-wrapping.
#>
@JohnL4
JohnL4 / local-atom-syntax-theme-customization
Created June 17, 2015 12:36
Local atom syntax theme customization
/*
* I like the Atom Light syntax theme, but the comment color is too light for me to comfortably large block comments
* (i.e., DOCUMENTATION), which, you know, some of us like to actually READ. So, this is a quick-n-dirty hack to make
* the comment color mo betta. Add this to your styles.less file (you can find it by hitting the "Open Config Folder"
* button in the Settings view.)
*/
atom-text-editor::shadow .comment {
color: #778877;
}
@JohnL4
JohnL4 / getting-stuff-into-github
Last active August 29, 2015 14:07
Getting stuff into GitHub
This assumes you've already created a github account.
So, you've created something new and wonderful on your local machine and you want to preserve it into github.
On github, create a repository (with license and readme).
On your local machine:
cd <yourWorkingDirectory> # The root of the Wonderful Thing you created
# (You might want to create a .gitignore file here, but you don't have to.)