Skip to content

Instantly share code, notes, and snippets.

@devpuppy
devpuppy / luminosity_constrast_ratio.rb
Created March 25, 2015 21:26
Calculate the Luminosity Contrast Ratio between two colors for readability
# 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
@gcatlin
gcatlin / gist:1847248
Created February 16, 2012 19:43
Install specific version of Homebrew formula
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#