Skip to content

Instantly share code, notes, and snippets.

@donpdonp
donpdonp / gist:959999
Created May 6, 2011 23:26
begin/rescue
## before
def some_method
Tweet.all.each do |tweet|
tweet.parse
end
end
## after
def some_method
Tweet.all.each do |tweet|
23 May 20:45:42 - Client 7560046834405512 connected
connect!
registered 7560046834405512
23 May 20:45:43 - xhr-multipart message handler error - TypeError: Object #<Object> has no method 'receiveMessage'
at Object.<anonymous> (/home/donp/src/javascript/nowslider/server.js:21:16)
@donpdonp
donpdonp / gist:1085169
Created July 15, 2011 17:55
floating point crazyness
$ irb
irb(main):001:0> RUBY_VERSION
=> "1.9.2"
irb(main):002:0> 1.8 + 0.1
=> 1.9000000000000001
irb(main):003:0> 1.8 + 0.1 == 1.9
=> false
irb(main):004:0>
## Ruby 1.8 wont even let you know whats going on!
@donpdonp
donpdonp / gist:1128599
Created August 5, 2011 21:47
Rubinius and Rails SafeBuffer
Cannot modify SafeBuffer in place
activesupport (3.0.9) lib/active_support/core_ext/string/output_safety.rb:119:in `rstrip!'
kernel/common/string.rb:1495:in `rstrip'
activesupport (3.0.9) lib/active_support/core_ext/string/output_safety.rb:115:in `rstrip'
string.rb
def rstrip
str = dup
1495: str.rstrip! || str
@donpdonp
donpdonp / gist:1129851
Created August 6, 2011 22:55
match and UTF-8
ruby-1.9.2-p290 :008 > line="Welcome to leguin.freenode.net in Ume\xE5, Sweden, EU!"
=> "Welcome to leguin.freenode.net in Ume\xE5, Sweden, EU!"
ruby-1.9.2-p290 :011 > line.encoding
=> #<Encoding:UTF-8>
ruby-1.9.2-p290 :010 > /^$/.match("abc")
=> nil
ruby-1.9.2-p290 :009 > /^$/.match(line)
Last login: Tue Aug 16 15:00:35 PDT 2011 from 192.168.0.7 on pts/1
Welcome to sirius.donpark.org. Sirius is a dual-core atom d510.
|
\ _ /
-= (_) =-
/ \ _\/_
| //o\ _\/_
_ ___ __ _ __ __ _ _ _ _ _ __ __ _ | __/o\\ _
=-=-_=-=-_=-=_=-_=_=-_=-_-_=_=-= _=_=-=_,-'|"'""-|-,_
=- _=-=-_=- _=-= _--_ =-= -_=-=_-=_,-" |
require 'net/http'
res = Net::HTTP.start("twitter.com", 443, {:use_ssl => true}) {|http|
http.get("/")
}
puts res.body[0,100]
puts res.inspect
require 'net/http'
require 'net/https'
http = Net::HTTP.new('twitter.com',443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
#specifying the cert location works with ruby1.8
http.ca_file = '/etc/ssl/certs/ca-certificates.crt'
res = http.get("/")
@donpdonp
donpdonp / gist:1155415
Created August 18, 2011 22:23
rc-svcdir
$ mount
rootfs on / type rootfs (rw)
/dev/root on / type ext4 (rw,noatime,user_xattr,acl,barrier=1,data=ordered,discard)
devtmpfs on /dev type devtmpfs (rw,relatime,size=1017228k,nr_inodes=254307,mode=755)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
rc-svcdir on /lib64/rc/init.d type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1024k,mode=755)
...
$ ls /lib64/rc/init.d/daemons/
nginx/ php-fpm/ sshd/ udev/
## mongrel config
web_app_proxy = Proxy(addr='127.0.0.1', port=1500)
routes = {
'/': web_app_proxy,
}
$ sudo tcpflow -c -i lo port 1500
tcpflow[7196]: listening on lo
127.000.000.001.55068-127.000.000.001.01500: GET / HTTP/1.1
Host: donpark.org