Skip to content

Instantly share code, notes, and snippets.

View abdollar's full-sized avatar

Abdul Chaudhry abdollar

View GitHub Profile
@abdollar
abdollar / gist:7132292
Created October 24, 2013 06:33
ObjectSpace - record rails allocations
# Load the rails application
require File.expand_path('../application', __FILE__)
require 'objspace'
require 'digest/md5'
require 'base64'
# Initialize the rails application
MyApp::Application.initialize!
objs = File.open("/tmp/objs.txt", 'w')
at_exit {
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
@abdollar
abdollar / gist:5646361
Created May 24, 2013 20:37
protect private ssh key
mv ~/.ssh/id_rsa ~/.ssh/id_rsa.old
openssl pkcs8 -topk8 -v2 des3 -in ~/.ssh/id_rsa.old -out ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
rm ~/.ssh/id_rsa.old
@abdollar
abdollar / astar.rb
Created February 25, 2013 06:11 — forked from mburst/astar.rb
require 'priority_queue'
require 'set'
class Node
def initialize(x, y)
@x = x
@y = y
@obstacle = false
@g_score = Float::INFINITY
end
@abdollar
abdollar / gist:2295194
Created April 3, 2012 20:09
wilson score confidence interval - what percentage of people took some sort of action
#pos is the number of positive ratings
#n is the total number of ratings
def score_ratings(pos, n)
#modified shamelessly from http://evanmiller.org/how-not-to-sort-by-average-rating.html
return 0 if n == 0
# require 'statistics2'
# z = Statistics2.pnormaldist(1-(1-confidence)/2)
# the z score refers to a confidence: pick 0.95 to have a 95% chance that your lower bound is correct, 0.975 to have a 97.5% chance, etc.
@abdollar
abdollar / gist:1860869
Created February 18, 2012 19:59
Debugging http with tcpflow
sudo tcpflow -c -n en1 src or dst host api.example.com
EM.run do
request = EventMachine::HttpRequest.new('http://api.example.com/')
deferrable = request.get :path => '/api/v2/chickens.json'
deferrable.callback { puts "It worked"; EM.stop }
deferrable.errback { puts "It failed"; EM.stop }
end
@abdollar
abdollar / client.rb
Created January 23, 2012 20:24 — forked from igrigorik/client.rb
chunked file stream with goliath
require 'bundler'
Bundler.require
url = 'http://0.0.0.0:9000/images/avatar.png'
EM.run do
http = EventMachine::HttpRequest.new(url).get
http.stream {|chunk| print [:chunk, chunk.size] }
http.headers {|h| p [:headers, h] }
@abdollar
abdollar / gist:1665243
Created January 23, 2012 20:01
Using upstart and foreman
create a Procfile << app: ruby script/app
rvmsudo foreman export upstart /etc/init -a app -u achaudhry
@abdollar
abdollar / gist:1665112
Created January 23, 2012 19:33
tcpdump dns queries
sudo tcpdump -vi eth0 port 53
@abdollar
abdollar / gist:1665105
Created January 23, 2012 19:32
Octal permissions
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'