This file contains 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
# What is existence? | |
class Be | |
def initialize | |
end | |
def matches?(actual) | |
defined? actual | |
end | |
This file contains 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
dbrady@robomonkey:~/lmp/market (sprint)$ ruby -e 'require "rubygems"; require "trollop"; puts Trollop.class' | |
Module | |
dbrady@robomonkey:~/lmp/market (sprint)$ ruby -e 'require "rubygems"; require "nokogiri"; puts Nokogiri.class' | |
Module | |
dbrady@robomonkey:~/lmp/market (sprint)$ cd | |
dbrady@robomonkey:~ $ ruby -e 'require "rubygems"; require "trollop"; puts Trollop.class' | |
Module | |
dbrady@robomonkey:~ $ ruby -e 'require "rubygems"; require "nokogiri"; puts Nokogiri.class' | |
./nokogiri.rb:4: uninitialized constant Nokogiri (NameError) | |
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' |
This file contains 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
require 'rubygems' | |
require 'nokogiri' | |
doc = Nokogiri::HTML.parse(<<-eohtml) | |
<table> | |
<tr><td>9</td><td>MRobinson</td></tr> | |
<tr><td>10</td><td>RGoldblatt</td></tr> | |
<tr><td>11</td><td>JBrancato</td></tr> | |
<tr><td>XX</td><td><table><tr><td>Poo</td></tr></table></td></tr> | |
</table> |
This file contains 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 String | |
>> alias :/ :split | |
>> end | |
=> nil | |
>> "foo"/// | |
=> ["f", "o", "o"] |
This file contains 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
$ cat bin/localhost | |
#!/bin/sh | |
open http://localhost/$* |
This file contains 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
# This takes about 2s for a 53Mb file. | |
bytes = audio_file.read_into(audio_buffer) | |
# This takes less than a second, BUT the data is interleaved | |
# (left, right, left, right, left, right, etc) | |
self.audio_data = audio_buffer.unpack('s*') | |
# Less than a second. | |
self.left_channel = NArray.float(2, audio_data.size) | |
self.right_channel = NArray.float(2, audio_data.size) |
This file contains 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
describe "Server" do | |
describe "methods" do | |
let(:put) { "put foobar beans 5\nhowdy" } | |
it "should be valid for a valid put method" do | |
# before all | |
@pid = spawn("bin/server") | |
# before each | |
@sock = TCPSocket.new "127.0.0.1", 3000 |
This file contains 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
# One pattern I use so much I need to make an editor macro for it: | |
class Foo | |
attr_accessor :x, :y, :z, :w | |
# --> macro on above line should produce: | |
def initialize(x, y, z, w) | |
@x, @y, @z, @w = x, y, z, w | |
end | |
# --> end macro |
This file contains 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
# Coders from from C often like this style: | |
log status == OK ? "OK" : "PROBLEM" | |
log "All done." | |
# But since if returns a value in ruby, you can spell it out: | |
log if status == OK | |
"OK" | |
else | |
"PROBLEM" | |
end |
This file contains 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
// Consider the humble object: | |
var dave = { | |
name: "Dave", | |
age: 39, | |
color: "green" | |
}; | |
// If I add to this and forget to add another trailing comma, it's a | |
// syntax error: | |
var dave = { |
OlderNewer