Skip to content

Instantly share code, notes, and snippets.

@deepfryed
deepfryed / counter.rb
Created May 16, 2011 02:27
bean counter
#!/usr/bin/ruby
require 'bundler'
Bundler.setup(:default)
require 'yajl'
require 'beanstalk-client'
jobs = 100_000
prod = Thread.new do
@deepfryed
deepfryed / test_nokogiri_alternation.rb
Created March 12, 2011 01:50
should nokogiri css multiple selector work like xpath alternation ?
#!/usr/bin/ruby
require 'nokogiri'
require 'minitest/spec'
describe 'nokogiri css selectors' do
before do
@doc = Nokogiri::HTML %Q{
<html>
<body>
@deepfryed
deepfryed / gist:772647
Created January 10, 2011 11:10
simple swift associations benchmarks
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
@deepfryed
deepfryed / textit.rb
Created January 9, 2011 00:33
gmail cheat sheet
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
@deepfryed
deepfryed / overload.cc
Created December 29, 2010 21:10
c++ new/delete operator
$ ./overload
>> Person
>> operator new
>> Person
>> ~Person
>> operator delete
>> ~Person
@deepfryed
deepfryed / gist:735710
Created December 10, 2010 03:20
em-http fail
#!/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
@deepfryed
deepfryed / gist:728676
Created December 5, 2010 01:37
block fucking script kiddies
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
# 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
#include <ruby.h>
VALUE blocking_function(void *data) {
throw "die die die";
}
VALUE run(VALUE self) {
try {
rb_thread_blocking_region(blocking_function, 0, 0, 0);
}
#include <ruby/ruby.h>
#include <time.h>
#include <unistd.h>
#define CONST_GET(scope, constant) rb_const_get(scope, rb_intern(constant))
VALUE day_secs;
VALUE cDateTime;
VALUE fNewBang;