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
def assign_by_weight(weights) | |
sum = weights.keys.inject(0) { |s,v| s += v } | |
#normalize random over sum | |
#parse weights into some form of mutually exclusive set | |
return result | |
end | |
foo = assign_by_weight(0.5 => :foo, 0.6 => :bar) |
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
module Rack | |
class Builder | |
def use(middleware, *args, &block) | |
middleware.instance_variable_set "@rack_builder", self | |
def middleware.rack_builder | |
@rack_builder | |
end | |
@ins << lambda { |app| middleware.new(app, *args, &block) } | |
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
unless defined?(TEST_ROOT) | |
TEST_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..')) | |
$LOAD_PATH.unshift(TEST_ROOT) | |
end | |
require 'test_helper' |
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
def funky_foo(shakalaka, &block) | |
unless some_condition | |
puts "chicken dinner" | |
return | |
end | |
# lines of code | |
# and more lines of code | |
# ... | |
# 50 lines of code |
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
module MethodVisibility | |
#mocking out super calls is tricky, so here is a hack to get around it. | |
def hide_method(method, replacement = Proc.new(){}) | |
self.send :alias_method, :old_method, method | |
self.send :define_method, method, replacement | |
begin | |
yield | |
ensure #otherwise other tests get screwed up if an assertion fails inside block | |
self.send :alias_method, method, :old_method | |
self.send :remove_method, :old_method |
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
module FlexCompiler | |
COMPILER = "/Applications/Adobe\\ Flex\\ Builder\\ 3/sdks/3.2.0/bin/mxmlc" | |
FRAMEWORK_PARAM = "-runtime-shared-library-path=/Applications/Adobe\\ Flex\\ Builder\\ 3/sdks/3.2.0/frameworks/libs/framework.swc,framework_3.2.0.3958.swz,,framework_3.2.0.3958.swf" | |
COMPONENTS_PARAM = "-runtime-shared-library-path=vendor/flex/components/bin/components.swc,components.swf" | |
DEFAULT_FLAGS = "--warnings=true --strict=true --debug=false" | |
def self.compile_swf(project) | |
puts "compiling #{project}" | |
project_path = "vendor/flex/#{project}/src/#{project}" | |
compile_cmd = "#{COMPILER} #{DEFAULT_FLAGS} #{FRAMEWORK_PARAM} #{COMPONENTS_PARAM} -file-specs #{project_path}.mxml" |
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
#!/bin/sh | |
git filter-branch -f --env-filter ' | |
ae=$GIT_AUTHOR_EMAIL | |
an=$GIT_AUTHOR_NAME | |
case $GIT_AUTHOR_NAME in | |
tconnor) | |
ae="[email protected]" | |
an="Tim Connor" | |
;; |
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
gitup() { | |
if git update-index --refresh; then | |
stashed= | |
else | |
stashed=1 | |
git stash save 'update temp' | |
fi | |
git pull --rebase; | |
if [ -n "$stashed" ]; then | |
git stash pop |
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
nesquena sent you a message. | |
-------------------- | |
Subject: Gemcutter support [timocratic/test_benchmark GH-3] | |
Now that github no longer supports gem installations, would be nice to latest version on gemcutter.org | |
View this Issue online: http://github.com/timocratic/test_benchmark/issues#issue/3 | |
-------------------- |
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 | |
#With thanks to http://tonybuser.com/post/188055319/importing-typo-to-tumblr for the initial seed | |
require "rubygems" | |
require "hpricot" | |
require "httparty" | |
class Tumblr | |
include HTTParty | |
base_uri 'www.tumblr.com' | |
default_params :generator => "Tim Connor's Tumblr Importer http://gist.github.com/218453", |