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
require 'test/unit' | |
require 'shoulda' | |
class Test::Unit::TestCase | |
def self.context_helper(helper_arg, &block) | |
context "context helper #{helper_arg}" do | |
setup do | |
@helper_arg = helper_arg | |
end | |
merge_block(&block) if block_given? |
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://tomayko.com/writings/unicorn-is-unix | |
# simple preforking echo server in Ruby | |
require 'socket' | |
# Create a socket, bind it to localhost:4242, and start listening. | |
# Runs once in the parent; all forked children inherit the socket's | |
# file descriptor. | |
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) | |
address = Socket.pack_sockaddr_in(4242, 'localhost') | |
acceptor.bind(address) |
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
def inner(&block) | |
@inner = block if block_given? | |
@inner | |
end | |
outter = lambda do | |
name = 'outter' | |
inner do | |
puts "inner sees #{name}" | |
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
require 'net/http' | |
require 'uri' | |
require 'nokogiri' | |
class Pygrack | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
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
.bundle/environment.rb | |
bundler_gems |
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
# I got this idea from http://mihai.bazon.net/blog/redis-client-library-javascript-node | |
# The technique relies on the fact that raising an exception clears the call stack. | |
# The context is passed along with a block attached to an exception. | |
# I thought it was brilliant js hackery so I decided to try my hand at it in ruby. | |
# I've also included some other stack-dependent implementations. | |
# straight recursion, not quite a tail-call | |
# I can't go above 8.1k without stack error | |
def rsum(num) | |
if num == 0 |
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
Object.prototype.inspect = function () { | |
function pad(depth) { | |
return Array(depth).join(" "); | |
} | |
function down(attr, val, depth) { | |
var output = pad(depth) + attr + ': '; | |
output += (typeof(val) == 'object' ? "{" : val); | |
return output + "\n"; | |
} |
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
class String | |
def named_matches(rx) | |
m = rx.match(self) | |
[Hash[m.names.collect{|n| [n, m[n]]}]] | |
end | |
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
def PostsController < ActionController::Base | |
def create | |
@post = Post.new(params[:post]) | |
if @post.save | |
redirect_to posts_path | |
else | |
render :action => "new" | |
end | |
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
# This plugin will deploy your app using capistrano. | |
# If the build fails the app won't de be deployed and if it passes it will try to deploy to a list of stages you can supply. | |
# | |
# Configuration | |
# In your project's cruise_config.rb file: | |
# | |
# Pass an array of stages you want to deploy to | |
# project.cap_deployer.stages = ['integration', 'staging'] | |
# | |
# source ~/.rvm/scripts/rvm before deployment? |
OlderNewer