Skip to content

Instantly share code, notes, and snippets.

View knzconnor's full-sized avatar

Kenzi Connor knzconnor

View GitHub Profile
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)
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
unless defined?(TEST_ROOT)
TEST_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..'))
$LOAD_PATH.unshift(TEST_ROOT)
end
require 'test_helper'
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
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
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"
#!/bin/sh
git filter-branch -f --env-filter '
ae=$GIT_AUTHOR_EMAIL
an=$GIT_AUTHOR_NAME
case $GIT_AUTHOR_NAME in
tconnor)
ae="tim.connor@yieldbuild.com"
an="Tim Connor"
;;
@knzconnor
knzconnor / gitup.sh
Created October 9, 2009 00:39
Does a git pull, even with uncommitted changes
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
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
--------------------
#!/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",