This file contains hidden or 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
# Global GOTO table. | |
$LABELS = Hash.new | |
def label(name) | |
$LABELS[name] = callcc {|cc| cc } | |
end | |
def goto(name) | |
$LABELS[name].call | |
end |
This file contains hidden or 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
#!/usr/bin/env ruby | |
comp_line = ENV["COMP_LINE"] | |
exit -1 if comp_line.nil? | |
COMMANDS = %w(server generate destroy plugin benchmarker profiler | |
console dbconsole application runner) | |
parts = comp_line.scan(/\w+/) | |
exit 0 unless parts.size == 2 |
This file contains hidden or 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
using System; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Diagnostics; | |
/// <summary> | |
/// A simple attribute that times controller actions, returning the measured time | |
/// in the HTTP header "X-Duration". | |
/// </summary> |
This file contains hidden or 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
# compl1.rb - Redis autocomplete example | |
# download female-names.txt from http://antirez.com/misc/female-names.txt | |
require 'rubygems' | |
require 'redis' | |
r = Redis.new | |
# Create the completion sorted set | |
if !r.exists(:compl) |
This file contains hidden or 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
# compl1.rb - Redis autocomplete example | |
# download female-names.txt from http://antirez.com/misc/female-names.txt | |
require 'rubygems' | |
require 'redis' | |
r = Redis.new | |
# Create the completion sorted set | |
if !r.exists(:compl) |
This file contains hidden or 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
INPUT=input.markdown | |
OUTPUT=output.html | |
XSLT=cat - | |
$(OUTPUT): $(INPUT) | |
markdown $(INPUT) | $(XSLT) > $(OUTPUT) |
This file contains hidden or 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 'rubygems' | |
require 'backports' # aliases Proc#=== to Proc#call | |
rs = (0..10000).to_a.sample(30) | |
rs.each do |r| | |
case r | |
when lambda { |n| n.zero? } then puts "#{r} is zero" | |
when lambda { |n| (n % 5).zero? } then puts "#{r} is fiven" | |
when lambda { |n| (n % 4).zero? } then puts "#{r} is fourven" |
This file contains hidden or 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
# | |
# A benchmark testing the performance of three methods of delegation: | |
# | |
# - Manually defining delegation methods | |
# - Metaprogramming using __send__ | |
# - Metaprogramming without using __send__ | |
# | |
# Note that the manual way of doing it is much faster if the arity of the | |
# target method is known. However, this benchmark is only meant to test | |
# the issue of __send__, and so we define the delegation methods with |
This file contains hidden or 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 Middleware | |
# Processes a request before it reaches the application. | |
# | |
# The middleware can change the flow of the request/response chain by: | |
# - Raising an exception, which will halt the process | |
# - Returning an instance of Response, which will go through the middleware layer | |
# | |
# Returning any other value will not do anything. | |
def process_request(request) | |
# ... |
This file contains hidden or 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 Issue < ActiveRecord::Base | |
# This is a very simplifed version of the old method. | |
def merge_issues(sources, options = {}) | |
target = self | |
comment = options[:comment] | |
transaction do | |
sources.each do |source| | |
source.merge_into(target, :comment => comment) | |
end |