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
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 / 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=/"
<div style="overflow:hidden; height: 100px">
<span id="1" style="height:50px;" />
<span id="2" style="height:50px;" />
<span id="3" style="height:50px;" />
</div>
#!/usr/bin/env bash
IP=`ifconfig | grep "inet " | grep -v "inet 127.0.0.1" | cut -f 2 -d " "`
PORT=$1
if [ -z "$1" ]
then
PORT=8000
fi
# Copy ip and port to pasteboard
@iamjwc
iamjwc / pipe.rb
Created May 11, 2011 20:36
pipe.rb
class Pipe
DestinyNotYetChosenException = Class.new(Exception)
CannotWriteToReaderException = Class.new(Exception)
CannotReadFromWriterException = Class.new(Exception)
def initialize
@readpipe, @writepipe = IO.pipe
end
[~/programming/sinatra]$ irb
ruby-1.8.7-p330 :001 > class Array; def save_map(&blk); self.instance_variable_set(:@map_blk, blk) end; def call_saved_map; self.map(&self.instance_variable_get(:@map_blk)) end end
=> nil
ruby-1.8.7-p330 :002 > a = [1,2,3]
=> [1, 2, 3]
ruby-1.8.7-p330 :003 > a.save_map {|i| i * 2 }
=> #<Proc:0x00000001003463a8@(irb):3>
ruby-1.8.7-p330 :004 > a
=> [1, 2, 3]
ruby-1.8.7-p330 :005 > a.call_saved_map
@iamjwc
iamjwc / before_action.rb
Created April 26, 2011 14:53
before_action.rb
module Sinatra::BeforeAction
def before_action(&blk)
before {
# Find all the routes for the given request method
routes = self.class.routes[request.request_method]
# Find the route that matches the pattern/conditions of the
# request and steal the params.
routes.select do |pattern, keys, conditions, block|