This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190988 | |
190755 | |
190706 | |
191474 | |
191480 | |
191479 | |
191477 | |
167433 | |
61434 | |
196577 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent | |
def self.print_name | |
puts self.name | |
end | |
def self.name | |
"Parent" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pipe | |
DestinyNotYetChosenException = Class.new(Exception) | |
CannotWriteToReaderException = Class.new(Exception) | |
CannotReadFromWriterException = Class.new(Exception) | |
def initialize | |
@readpipe, @writepipe = IO.pipe | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[~/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |