Skip to content

Instantly share code, notes, and snippets.

View anildigital's full-sized avatar
:octocat:

Anil Wadghule anildigital

:octocat:
View GitHub Profile
@anildigital
anildigital / nuke.rb
Created February 6, 2011 17:06 — forked from radar/nuke.rb
require 'rubygems'
require 'mechanize'
require 'httparty'
# Ugly code, for an ugly hack.
# Hey, if Lighthouse didn't suck then none of this would happen.
# It's been lotsa fun coding it though, so I suppose I should be thankful for the "opportunity"
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
THIS DOCUMENT MOVED TO http://chneukirchen.github.com/rps/
AND http://github.com/chneukirchen/rps
= Ruby Packaging Standard
The aim of this document is two-fold. First, to specify a common
structure of how a Ruby package distributed as source (that is, but
not limited to, development directories, version-controlled
repositories, .tar.gz, Gems, ...) should conform to.

If one was inclined to use the acts_as_yaffle pattern, they would probably use the second one, rather than the heavily cargo-culted first one.

module Matz
def self.included(*)
puts <<-MATZ
Simplicity is NOT a Goal
------------------------
Things too simple are difficult
Things too complex are difficult
@anildigital
anildigital / memrate.rb
Created May 22, 2010 20:02 — forked from defunkt/memrate.rb
Awesome option parsing.
#!/usr/bin/env ruby
## Usage: memrate.rb [-l <lib>] [-i <num>] [-t <threshold>] [-k <size>] [<host>]
## Measure memcached server read time.
##
## Options
## -l, --library=<lib> Memcached client library to use. memcache-client by
## default. memcached also supported.
## -i, --iterations=<num> Number of times to read the value. If not set, read
## until interrupted.
## -t, --threshold=<time> Report iterations that take longer than <time>
@anildigital
anildigital / gist:410309
Created May 22, 2010 19:41 — forked from defunkt/gist:206253
Awesome unicorn config.
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
$ cat script/test.rb
require File.expand_path('../../config/environment.rb', __FILE__)
5000.times{ print 'a' }
$ RAILS_ENV=production strace -e trace=write ruby script/test.rb > /dev/null
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 904) = 904
# this:
builder = Rack::Builder.new do
use Rack::ContentLength
use Rack::ETag
run app
end
app = builder.to_app
# is the same as:
require 'rubygems'
require 'ruby-prof'
RubyProf.measure_mode = RubyProf::PROCESS_TIME
RubyProf.start
require 'config/environment'
results = RubyProf.stop
File.open "loading-graph.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)