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
#!/bin/bash | |
# accepts as many version strings as you like | |
# returns them in order, one per line, highest first | |
function vseq() | |
{ | |
# collect arbitrary number of args | |
while [ -n "$1" ]; do | |
args="$args$1," | |
shift |
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://andora.us/blog/2011/03/03/choosing-foreground-using-luminosity-contrast-ratio/ | |
# color contrast ratio ranges from 1 (least) to 21 (most, white/black) | |
class Color | |
attr_reader :r, :g, :b | |
def initialize(hex) | |
raise 'Invalid hex code' unless hex =~ /[0-9a-f]{6}/i | |
hexes = hex.scan /.{2}/ | |
@r,@g,@b = hexes.map { |h| h.hex.to_i } | |
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
alert(window.location.pathname); |
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
function ajax(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4) { | |
callback(xhr.responseText); | |
} | |
} | |
xhr.open('GET', url, true); | |
xhr.send(); | |
} |
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
@gists = YAML::load Net::HTTP.get(URI.parse(GIST_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
# very basic test_helper.rb addition to work with devise | |
def login_as(user) | |
if user.is_a?(Symbol) | |
user = Factory(user) | |
user.save | |
end | |
@request.session[:user] = user | |
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
# useful for organizing unobtrusive javascript per template | |
# assumes layout has yield :javascripts | |
# need to figure out how to invoke from the template without explicitly having to call it | |
def javascript_template_include_tag | |
javascript_path = "views/#{@template.template.path_without_format_and_extension}.js" | |
if File.exist?(File.join(RAILS_ROOT, 'public', 'javascripts', javascript_path)) | |
content_for :javascripts do | |
javascript_include_tag javascript_path | |
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 disable_rubygems; nil; end | |
def source(s); $src = s unless s[/gemcutter/] end | |
def gem(n, v) | |
if Hash === v | |
$stderr.puts "ignoring git gem #{n}" | |
return | |
end | |
puts "#{n} --version '#{v}' #{$src ? " -s#{$src}": ""}" | |
end | |
load ARGV[0] || "Gemfile" |
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
# on Ruby 1.9.1... | |
# gem install test-unit -v 1.2.3 | |
# gem install autotest redgreen autotest-fsevent autotest-rails ZenTest autotest-growl | |
require 'redgreen' | |
Autotest.send(:alias_method, :real_ruby, :ruby) | |
Autotest.send(:define_method, :ruby) do |*args| | |
real_ruby + %[ -rrubygems -e "require 'redgreen'" ] | |
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
PATH=$PATH:/opt/local/bin | |
export PATH | |
alias be='mate -w ~/.bash_profile;source ~/.bash_profile' | |
# alias ss='script/server' | |
# alias sc='script/console' | |
alias rdm='rake db:migrate' | |
alias glg='gem list |grep' | |
alias rrg='rake routes |grep' |
OlderNewer