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 'rubygems' | |
# Array.hash for objects do not produce a Fixnum hash will blow up. This issue | |
# will be fixed in a future release but I thought you might like to know in | |
# case you wanted to patch RubyGems for versions prior to the fix. | |
# | |
# (see http://redmine.ruby-lang.org/issues/show/1883) | |
# | |
# I found this error because it prevents an array of Gem::Specifications from | |
# being converted to YAML, as shown below. Note that in the example rack was |
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 'readline' | |
Signal.trap('INT', 'SIG_IGN') { puts "hello" } | |
while line = Readline.readline('--/', true) | |
exit if line == "exit" | |
puts line | |
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 'benchmark' | |
# A basic version of a dsl that registers key-value pairs onto a Class. When | |
# looking up a key-value pair, Classes that use the dsl will check the | |
# registry of each ancestor in order, as if looking up a method. | |
# | |
# Call cache_ancestors! to cache the ancestry and speedup lookup. | |
module Dsl | |
def self.extended(base) | |
base.registry ||= {} |
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 'rubygems' | |
require 'erb' | |
require 'sinatra/base' | |
# A basic RESTful Sinatra app for serving some kind of object. Uses views: | |
# | |
# views | |
# |- error.erb | |
# |- index.erb | |
# |- layout.erb |
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 'rubygems' | |
require 'redcloth' | |
module CustomHTML | |
include RedCloth::Formatters::HTML | |
def custom(opts) | |
"<em>#{opts[:text].sub("hard.", "easy!")}</em>" | |
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
// Adapted from: http://www.w3schools.com/xsl/xsl_client.asp | |
Xslt: { | |
// Transforms xml using the specified xsl and returns a document fragment. | |
// The fragment may be added to the DOM using jQuery like this: | |
// | |
// node = Xslt.transform("/example.xml", "/example.xsl"); | |
// jQuery("#node_id").replaceWith(node); | |
// | |
transform: function(xml_url, xsl_url) { |
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 prompt_test(cmd, script, prompt) | |
cmd, leader = cmd.lstrip.split(/^/, 2) | |
inputs = [] | |
expected = [leader] | |
script.lstrip.split(/^#{prompt}/).each do |lines| | |
next if lines.empty? | |
input, output = lines.split(/^/, 2) | |
inputs << input |
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
spec = eval(File.read('project.gemspec')) | |
gem "#{spec.name}", "#{spec.version}" | |
bin_path "vendor/gems/bin" | |
if ENV['BUNDLE_CC'] == "true" | |
# in the CC environment, bundles against the | |
# most recent working copies of a gemspec | |
clear_sources | |
cc_dir = ENV['CRUISE_DATA_ROOT'] || File.dirname(__FILE__) + "/../../.." |
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 'redcloth' | |
module SimpleForm | |
include RedCloth::Formatters::HTML | |
def form(opts) | |
content = opts[:text].split("<br />") | |
definition = content.shift | |
definition =~ /\A\s*(get|post)(.*?)(?:\[(.*)\])?\z/ |
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 'curb' | |
class Session | |
# The internal Curl::Easy instance | |
attr_reader :curb | |
# The last response, or nil | |
attr_reader :last | |