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
# Add pessmistic locking support. Make sure you're inside a transaction. | |
# resource = MyResource.get(24) | |
# resource.lock! # write lock (FOR UPDATE) | |
# | |
# TODO: | |
# resource = MyResource.get_with_lock!(:write, 24) | |
# resource = MyResource.get_with_lock!(:read, 24) | |
# MyResource.all(:lock => :write) | |
module DataMapper |
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
for ip in `sudo cat /var/log/auth.log | grep "invalid user .* from" | sed 's/^.*invalid user \([0-9a-zA-Z_\-]\+\) from \([0-9.]\+\).*$/\1\t\2/' | cut -f2 | sort -u`; do echo iptables -A INPUT -s $ip/32 -p tcp -j REJECT; done | xargs sudo |
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
#!/usr/bin/env ruby1.9.1 | |
require 'em-http' | |
EM.run do | |
url = "http://www.scribd.com:80/doc/45016088/He-Spake-and-It-Was-Done" | |
http = EM::HttpRequest.new(url).get timeout: 10 | |
http.callback { puts "done"; EM.stop }; | |
http.errback {|res| puts "error\n"; p res.response_header; EM.stop } | |
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
$ ./overload | |
>> Person | |
>> operator new | |
>> Person | |
>> ~Person | |
>> operator delete | |
>> ~Person |
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
Key | Action | |
------------------------------+-------------------------------------------- | |
c | Compose | |
/ | Search | |
k | Move to newer conversation | |
j | Move to older conversation | |
n | Next message | |
p | Previous message | |
o or <Enter> | Open | |
u | Return to conversation list |
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
bharanee@tardis $ ./simple.rb -s swift -s dm -r 1000 | |
-- driver: sqlite3 rows: 1000 runs: 5 -- | |
benchmark sys user total real rss | |
swift #create 0.060000 0.370000 0.430000 0.431087 18.81m | |
swift #select 0.000000 0.020000 0.020000 0.027583 3.56m | |
swift #update 0.070000 1.760000 1.830000 1.836255 77.74m | |
dm #create 0.120000 1.640000 1.760000 1.799292 119.61m | |
dm #select 0.050000 0.760000 0.810000 0.812489 49.06m |
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
#!/usr/bin/ruby | |
require 'nokogiri' | |
require 'minitest/spec' | |
describe 'nokogiri css selectors' do | |
before do | |
@doc = Nokogiri::HTML %Q{ | |
<html> | |
<body> |
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
#!/usr/bin/ruby | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'yajl' | |
require 'beanstalk-client' | |
jobs = 100_000 | |
prod = Thread.new do |
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
HTTP/1.0 200 OK | |
x-amz-id-2: s95X6KRMXeT/gMbMOWU4WFYZMHPZzk/xxY1FDy2aqwb2hiX7rOWdEhcCWTXB4Lek | |
x-amz-request-id: B7D8B74B02C1D18E | |
Date: Wed, 06 Jul 2011 07:37:44 GMT | |
Last-Modified: Sat, 19 Jun 2010 09:28:48 GMT | |
ETag: "27b5075801658b818f55d521c37a5f4c" | |
Accept-Ranges: bytes | |
Content-Type: jpg | |
Content-Length: 3013 | |
Server: AmazonS3 |
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
# encoding: utf-8 | |
require 'rubygems' | |
require 'benchmark/ips' | |
require 'set' | |
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set | |
def original value | |
if value.is_a?(String) && value.empty? |