Skip to content

Instantly share code, notes, and snippets.

View zerowidth's full-sized avatar

Nathan Witmer zerowidth

View GitHub Profile
@zerowidth
zerowidth / bash_profile.sh
Created January 3, 2013 16:21
custom test runners with bash / fuubar / test/unit. hacks heaped upon hacks for a particular dev environment.
# http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time
function timer() {
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local stime=$1
etime=$(date '+%s')
if [[ -z "$stime" ]]; then stime=$etime; fi
@zerowidth
zerowidth / mountain_lion.md
Created July 27, 2012 19:43
Mountain Lion and You
  • stay calm
  • do not approach, and give it a way to escape
  • do not run, as it may encourage it to chase you
  • do not crouch or bend over, as you may look more like a 4-legged prey animal
  • do all you can to appear larger. raise your arms and open your jacket.

Installing

  • install Mountain Lion
  • Upgrade XCode
@zerowidth
zerowidth / a.rb
Created July 19, 2012 14:00
child socket port re-binding test
# only way to get the child process to re-bind is to set SO_REUSEPORT on both
# the parent socket and the child socket before binding.
require "socket"
puts "in parent"
server = TCPServer.new("127.0.0.1", 4000)
server.setsockopt(:SOCKET, :REUSEPORT, true)
puts server.inspect
(defn depth-of [line]
(count ((re-find #"^([\s-]*)" line) 1)))
(defn list-depth [line]
(count ((re-find #"^(\s*)" line) 1)))
(declare parse-list)
(defn parse-hash [lines]
(when-let [line (first lines)]
(let [depth (depth-of line)
children (take-while #(> (depth-of %) depth) (rest lines))
@zerowidth
zerowidth / music.rb
Created May 7, 2012 21:37
A functional, lazily-evaluated solution to https://github.com/KeeperPat/music-yaml-parsing for a "coding challenged" competition
Proc.module_eval { def method_missing(m,*a); call(m.to_s,*a); end }
Array.module_eval { def rest; self[1..-1]; end }
Object.module_eval { def let; yield self; end }
Music = Module.new do
def self.load(filename)
depth = ->(l) { %r(^([\s-]*)\w).match(l)[1].length }
ldepth = ->(l) { %r(^(\s*)\S).match(l)[1].length }
nonzero = ->(n) { n > 0 }
empty = ->(c) { c.empty? }
@zerowidth
zerowidth / gist:2430323
Created April 20, 2012 17:06 — forked from marcel/gist:2100703
giftube – Generates an animated gif from a YouTube url.
#!/usr/bin/env ruby
# giftube – Generates an animated gif from a YouTube url.
#
# Usage:
#
# giftube [youtube url] [minute:second] [duration]
#
# ex.
#
@zerowidth
zerowidth / rage.coffee
Created March 24, 2012 22:06
jointhecolorwar rage face
# npm install socket.io-client canvas
io = require "socket.io-client"
util = require "util"
fs = require "fs"
Canvas = require "canvas"
EventEmitter = require("events").EventEmitter
class Pixels extends EventEmitter
constructor: ->
@zerowidth
zerowidth / cleanup.sh
Created February 28, 2012 22:26
git cleanup script
#!/bin/bash
# inspired by https://gist.github.com/1564252
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
CYAN=$(tput setaf 6)
RESET=$(tput sgr 0)
function header() {
@zerowidth
zerowidth / ar_pg_defaults.gemspec
Created October 4, 2011 16:11
Let postgres insert default values for columns with default values that AR 3.1 doesn't understand
Gem::Specification.new do |s|
s.name = "ar_pg_defaults"
s.version = "0.0.1"
s.platform = Gem::Platform::RUBY
s.author = "Nathan Witmer"
s.email = "nwitmer@gmail.com"
s.homepage = "https://gist.github.com/1262051"
s.summary = "Help AR let postgres do its thing"
s.description = "Let postgres insert default values for columns with default values that AR 3.1 doesn't understand"
# simple guardfile for vital testing workshop.
#
# $ gem install guard guard-rspec growl_notify
#
# put your code in lib/thing.rb
# and the specs in spec/thing_spec.rb
#
# then
#
# $ guard