Skip to content

Instantly share code, notes, and snippets.

require "nokogiri"
require "hpricot"
require "open-uri"
#on my macbook
#$ ruby speedtest.rb
#uri took: 4.539837
#hpricot took: 3.490182
#nokogiri took: 6.273096
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2"/>
</do>
<p><select name="name">
NSDate *date = [NSDate date];
void (^now)(void) = ^ {
    NSLog(@"The date and time is %@", date);
};
now();
sleep(5);
date = [NSDate date];
now();
@rb2k
rb2k / apple_tv_jailbreak
Created February 13, 2011 11:35
that's what it looks like from the terminal point of view
$ sudo greenpois0n.app/Contents/MacOS/greenpois0n
2011-02-13 12:22:09.632 greenpois0n[302:e07] Could not connect the action buttonPressed: to target of class NSApplication
2011-02-13 12:22:09.635 greenpois0n[302:e07] Could not connect the action buttonPressed: to target of class NSApplication
2011-02-13 12:22:09.636 greenpois0n[302:e07] Could not connect the action buttonPressed: to target of class NSApplication
2011-02-13 12:22:09.637 greenpois0n[302:e07] Could not connect the action buttonPressed: to target of class NSApplication
Initializing libpois0n
No matching processes were found
Device must be in DFU mode to continue
Device must be in DFU mode to continue
opening device 05ac:1227...
require "rubygems"
rack_app = Proc.new do |env|
[200, {"Content-Type"=>"text/html"}, env["REMOTE_ADDR"]]
end
run rack_app
class Foo
def self.doit
puts "nike"
end
def bar
Foo.doit()
end
def bar2
@rb2k
rb2k / sum_mean.rb
Created April 21, 2011 16:28
sum and mean for the Array class
class Array
def sum
inject( nil ) { |sum,x| sum ? sum+x : x }
end
def mean
sum.to_f / size.to_f
end
end
import numpy
#your regular array
myarray = [123, 221, 3, 16, 199, 0]
#convert that to 32 bit integers
tmp=numpy.array(myarray, numpy.int32)
@rb2k
rb2k / gist:1451396
Created December 9, 2011 12:47
threading problems?
*** longjmp causes uninitialized stack frame ***: ruby terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x37)[0x7f1bc849d217]
/lib/libc.so.6(+0xff1a9)[0x7f1bc849d1a9]
/lib/libc.so.6(__longjmp_chk+0x33)[0x7f1bc849d113]
/usr/lib/libcurl.so.4(+0x91e5)[0x7f1bc5f001e5]
/lib/libpthread.so.0(+0xf8f0)[0x7f1bc8ff88f0]
/lib/libpthread.so.0(pthread_cond_wait+0xcc)[0x7f1bc8ff485c]
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/libruby.so.1.9(+0x180d69)[0x7f1bc9386d69]
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/libruby.so.1.9(+0x18549b)[0x7f1bc938b49b]
*** longjmp causes uninitialized stack frame ***: ruby terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x37)[0x7fee7967e217]
/lib/libc.so.6(+0xff1a9)[0x7fee7967e1a9]
/lib/libc.so.6(__longjmp_chk+0x33)[0x7fee7967e113]
/usr/lib/libcurl.so.4(+0x91e5)[0x7fee75ae21e5]
/lib/libpthread.so.0(+0xf8f0)[0x7fee79dab8f0]
/lib/libpthread.so.0(pthread_cond_wait+0xcc)[0x7fee79da785c]
ruby(_ZN8rubinius7Channel15receive_timeoutEPNS_5StateERNS_11GCTokenImplEPNS_6ObjectEPNS_9CallFrameE+0x3f4)[0x6791e4]
ruby(_ZN8rubinius10Primitives15channel_receiveEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x100)[0x62c4f0]