Skip to content

Instantly share code, notes, and snippets.

@pstephens
pstephens / GetNode.ps1
Last active December 28, 2015 06:59
Node.js bootstrapper in PowerShell.
$nodeUrl = "http://nodejs.org/dist/v0.10.22/x64/node-v0.10.22-x64.msi"
$nodeSha = "c3c169304c6371ee7bd119151bcbced61a322394"
function DownloadIt($url, $path)
{
Start-BitsTransfer -Source $url -Destination $path
}
function TestHash($path, $sha)
{
@pstephens
pstephens / dir.js
Last active January 4, 2016 07:59
Recursively get a list of files given a starting path.
var _ = require('underscore');
var fs = require('fs');
var path = require('path');
var Q = require('Q');
function processFileAsync(context)
{
return Q.ninvoke(fs, "stat", context.path)
.then(function(stat) {
@pstephens
pstephens / console-logs.txt
Last active January 4, 2016 09:19
Can't create a new virtual machine in VMWare Fusion 6.0.2.
1/24/14 11:13:17.808 AM VMware Fusion[939]: -[NSViewController loadView] loaded the "plVMDKOpenHelper" nib but no view was set.
1/24/14 11:13:17.809 AM VMware Fusion[939]: (
0 CoreFoundation 0x00007fff87d9741c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8775de75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff87d972cc +[NSException raise:format:] + 204
3 AppKit 0x00007fff88169507 -[NSViewController loadView] + 361
4 VMware Fusion 0x00000001079ca47f VMware Fusion + 152703
5 VMware Fusion 0x0000000107a5e0e7 VMware Fusion + 757991
6 VMware Fusion 0x0000000107a5dfe1 VMware Fusion + 757729
7 VMware Fusion 0x0000000107c0c2dc _ZN3cui19VMConfigTransaction3SetINS_16VMConfigPolicies16PolicyProtectionEEEvRNS_19TransactionPropertyIT_S0_EERKS5_ + 286956
JSON:
[
{
international_date: false,
is_coed: false,
team_name: "foo bar"
},
{
international_date: false,
is_coed: false,
@pstephens
pstephens / Program.fs
Created August 17, 2014 15:25
Fun with F# and bulk copy
// Fun with F# and bulk copy
open System.Configuration
open System.Data
open System.Data.SqlClient
let getOpenConnection () =
let cn = new SqlConnection(ConfigurationManager.ConnectionStrings.["TdsScratch"].ConnectionString)
cn.Open ()
cn
@pstephens
pstephens / sort.erl
Created October 9, 2014 01:24
Naive qsort in Erlang.
-module(sort).
-export([qsort/1]).
%%% A slightly naive implementation. But at least it does partial TCO.
partition(_, [], Smaller, Equal, Larger) -> {Smaller, Equal, Larger};
partition(Pivot, [H|T], Smaller, Equal, Larger) when H < Pivot -> partition(Pivot, T, [H|Smaller], Equal, Larger);
partition(Pivot, [H|T], Smaller, Equal, Larger) when H =:= Pivot -> partition(Pivot, T, Smaller, [H|Equal], Larger);
partition(Pivot, [H|T], Smaller, Equal, Larger) when H > Pivot -> partition(Pivot, T, Smaller, Equal, [H|Larger]).
@pstephens
pstephens / gist:71ec249757941f9c01ca
Created October 21, 2014 01:55
Problem running Optimus on Windows
PS C:\src> lein ring server
Exception in thread "main" java.lang.Exception: Unsupported OS/archetype: Windows 8.1 amd64, compiling:(v8/core.clj:34:2
6)
at clojure.lang.Compiler.load(Compiler.java:7142)
at clojure.lang.RT.loadResourceScript(RT.java:370)
at clojure.lang.RT.loadResourceScript(RT.java:361)
at clojure.lang.RT.load(RT.java:440)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
@pstephens
pstephens / coder.clj
Last active August 29, 2015 14:19
Alphabet Cipher solution
;; Solution to https://github.com/gigasquid/wonderland-clojure-katas/tree/master/alphabet-cipher
(ns alphabet-cipher.coder)
(defn crypt [op keyword message]
(letfn [
(tochar [idx] (char (+ idx (int \a))))
(toidx [ch] (- (int ch) (int \a)))
(encode [keychar msgchar] (tochar (mod (op (toidx msgchar) (toidx keychar)) 26)))]
(->> message
(map encode (cycle keyword))
@pstephens
pstephens / bootstrap.ps1
Last active August 29, 2015 14:26
Proposed bootstrap script for ClojureScript (rough draft)
$ErrorActionPreference = "Stop"
$root = Resolve-Path "$PSScriptRoot\.."
$shell = New-Object -com shell.application
# Read white listed dependency version info from the /bin/sh script and store in variables
Get-Content $root\script\bootstrap |
Where-Object { $_ -match '^\s*(\w+)\s*=\s*\"([^\"]*)\"\s*$' } |
Where-Object { $matches[1] -in "CLOJURE_RELEASE", "CLOSURE_RELEASE",
"DJSON_RELEASE", "GCLOSURE_LIB_RELEASE", "RHINO_RELEASE", "TREADER_RELEASE" } |
Foreach-Object { New-Variable $matches[1] $matches[2] -Scope private }
@pstephens
pstephens / serve.cljs
Created November 15, 2015 04:25
Simple node.js style 'hello world' web server in ClojureScript
(ns biblecli.commands.serve
(:require
[cljs.nodejs :as nodejs]
[clojure.string :as string]
[goog.object]))
(def node-http (nodejs/require "http"))
(defn process-request [req res]
(goog.object/set res "statusCode" 200)