Skip to content

Instantly share code, notes, and snippets.

View iamjwc's full-sized avatar

Justin Camerer iamjwc

  • LimeWire, LLC
  • New York City
View GitHub Profile
import Debug.Trace
-- Problem 0
helloWorld :: [Char]
helloWorld = "Hello World"
-- Problem 1
myLast :: [a] -> a
myLast = head . reverse
@iamjwc
iamjwc / flarp.rb
Last active May 20, 2016 16:07
Flattens hashes/arrays into a single level hash with the full json key path as a top level key. Useful for finding differences between two large manifests.
# Usage:
# (irb)> { "some" => [{"keys" => "with", "some" => ["values"]}]}.flarp
# => {"some.0.keys"=>"with", "some.0.some.0"=>"values"}
class Hash
def flarp(h = {}, prefix = nil)
each do |k, v|
new_k = [prefix, k].compact.join(".")
if v.is_a?(Array) || v.is_a?(Hash)
class Hash
def flarp(h = {}, prefix = nil)
each do |k, v|
new_k = [prefix, k].compact.join(".")
if v.is_a?(Array) || v.is_a?(Hash)
v.flarp(h, new_k)
else
h[new_k] = v
end
@iamjwc
iamjwc / mysql.rb
Last active January 2, 2016 10:19
require 'formula'
class Mysql < Formula
homepage 'http://dev.mysql.com/doc/refman/5.6/en/'
url 'http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.10.tar.gz'
version '5.6.10'
sha1 'f37979eafc241a0ebeac9548cb3f4113074271b7'
bottle do
sha1 'e07b9a207364b6e020fc96f49116b58d33d0eb78' => :mountain_lion
190988
190755
190706
191474
191480
191479
191477
167433
61434
196577
class ThingRepresentation < Representable::Decorator
include Representable::JSON
property :field
end
# This works great.
ThingRepresentation.new(Thing.new).to_json # => { "field": "thing value" }
# This does not work.
@iamjwc
iamjwc / maze.go
Last active October 16, 2015 17:58
// go-race
// width: `tput cols`
// height: `tput lines`
// Our generated maze needs to be just less than 1/2 the size of our
// terminal size, so we can have room to print walls.
//
// Each cell is an integer. Each wall on the cell (N, E, S, W) are
// represented by a bit. If a wall exists only on the north side,
@iamjwc
iamjwc / file.json
Last active October 13, 2015 05:17 — forked from anonymous/file.json
{"songs": [
{
"globalId": "gold-rush",
"name": "Gold Rush",
"written-by": "Bill Monroe",
"key": "a",
"chord-progression": [
{"section-name": "A", "chords": [
{"key-as-letter": "a", "key-as-roman": "I", "duration": 3.0},
{"key-as-letter": "e", "key-as-roman": "V", "duration": 0.5}
class Parent
def self.print_name
puts self.name
end
def self.name
"Parent"
end
end
# From: http://www.quirksmode.org/js/cookies.html
window.CookieHelpers =
expiry: (days) ->
date = new Date
date.setTime(date.getTime()+(days*24*60*60*1000))
"; expires=#{date.toGMTString()}"
write: (name, value, days) ->
expires = if days then this.expiry(days) else ""
document.cookie = "#{name}=#{value}#{expires}; path=/"