Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / gist:ef3847410eefdbb535c4
Created May 13, 2014 13:24
Organize your monstrous Downloads directory into subdirectories by file CreationTime year
ls | ? {$_.GetType().ToString() -match 'FileInfo'} | % {$yr = $_.CreationTime.Year; if (-not (Test-Path $yr)){ mkdir $yr}; mv $_ $yr}
@JohnL4
JohnL4 / gist:c78c466b2ed3abf80ed2
Created August 4, 2014 00:31
Linux command line to focus an emacs window
wmctrl -a emacs
@JohnL4
JohnL4 / PowerShellRandomNumber
Created October 6, 2014 16:01
Make random numbers in PowerShell
$r = New-Object System.Random
$r.NextDouble() * 10000000000
@JohnL4
JohnL4 / gist:a1c31b8c16e366f2b8ea
Created October 9, 2014 18:48
Clean up C:\Windows\winsxs folder (which can get big)
DISM /online /Cleanup-Image /SpSuperseded
@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.)
@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 / 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 / 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
<#
.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 / 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