Skip to content

Instantly share code, notes, and snippets.

module Rack
class MemoryBloat
def initialize(app, logger)
@app = app
@logger = logger
end
def call(env)
memory_usage_before = memory_usage
result = @app.call(env)
require 'rubygems'
require 'haml'
require 'effigy'
require 'effigy/core_ext/hash'
template = Haml::Engine.new(%{%html
%head
%title
%body
%h1
module SeleniumHelpers
# Execute JavaScript in the context of your Selenium window
def run_javascript(javascript)
driver.get_eval <<-JS
(function() {
with(this) {
#{javascript}
}
}).call(selenium.browserbot.getCurrentWindow());
JS
@stonegao
stonegao / url_dsl.rb
Created December 28, 2009 07:26 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
drew.send(:battle_cry)
# => Drew says zing!!!
# Factory girl, relaxed.
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
function merge(target, source) {
/* Merges two (or more) objects,
giving the last one precedence */
if ( typeof target !== 'object' ) {
target = {};
}
for (var property in source) {
#! ruby19
ADDR = %r{[-.\w]+@[-.\w]+}
email = DATA.read.freeze
# 1. Java style
subst = {}
puts email.gsub(ADDR) {|match|
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;
This example shows how to setup an environment running Rails 3 beta under 1.9.1 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell))
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.1
# Switch to 1.9.1
∴ rvm 1.9.1