Skip to content

Instantly share code, notes, and snippets.

@pithyless
pithyless / group_of_thingies.rb
Created February 8, 2012 08:40 — forked from Peeja/group_of_thingies.rb
Test a block in Ruby
class GroupOfThingies
attr_accessor :thingies
# Use like this:
#
# group_of_thingies = GroupOfThingies.new
# group_of_thingies.each do |thing|
# puts "Check out this awesome thing: #{thing}!"
# end
#
@pithyless
pithyless / ken-burns.css
Created February 18, 2012 22:56 — forked from thierryk/ken-burns.css
Ken Burns effect (styling images with panning and zooming effects)
/**
* See: http://www.css-101.org/articles/ken-burns_effect/css-transition.php
*/
/**
* Styling the container (the wrapper)
*
* position is used to make this box a containing block (it becomes a reference for its absolutely positioned children). overflow will hide part of the images moving outside of the box.
*/
@pithyless
pithyless / either.rb
Created March 27, 2012 14:44
Chaining Either for Ruby
# A chainable Either monad for Ruby
#
# Examples
#
# Either.right('s') >> proc { |s| Either.right(s + '-1') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left=nil, @right="s-1-2">
#
# Either.right('s') >> proc { |s| Either.left('error!') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left='error!', @right=nil>
#
@pithyless
pithyless / gazebo.rb
Created April 1, 2012 16:04
DCI via SimpleDelegator and a hint of metaprogramming
get '/give/me/gazebo/not/gazelle/:min_size' do
pricing = PriceCalculator.new
ParamsExtractor.new(pricing).parse(params)
GazelleFinder.new(pricing).find_all_gazelles
GazelleFilter.new(pricing).remove_sick_gazelles # pricing has access to #gazelles
GazeboBuilder.new(pricing).calculate_size_of_gazebo
GazeboPricer.new(pricing).calculate_final_price # pricing no longer has #gazelles
@pithyless
pithyless / custom_assertions.rb
Created July 23, 2012 12:33
minitest samples
# https://gist.github.com/2032303
module MiniTest::Assertions
def assert_palindrome(string)
assert string == string.reverse, "Expected #{string} to read the same way backwards and forwards"
end
def assert_default(hash, default_value)
assert default_value == hash.default, "Expected #{default_value} to be default value for hash but was #{hash.default.inspect}"
end
@pithyless
pithyless / gist:3386424
Created August 18, 2012 12:08
Convert FLAC to ALAC/AAC on a Mac
Step 1: install flac via Homebrew
brew install flac
Step 2: decode FLAC to AIFF
cd path/to/directory/with/files/to/convert
for i in *.flac; do
flac -d --force-aiff-format "$i"
done
@pithyless
pithyless / gist:3428884
Created August 22, 2012 20:06
OSX Mountain Lion - Install Notes
# Don't write to Disk on Sleep
sudo pmset -a hibernatemode 0
# Install Developer Tools (no XCode)
# https://developer.apple.com/downloads/index.action#
# Install DropBox
# Install 1Password
# Install Homebrew
@pithyless
pithyless / char_converter.rb
Created September 5, 2012 16:00
Rails middleware to encode characters and avoid exploding controllers
# config/initializers/char_converter.rb
require 'uri'
module Support
class CharConverter
SANITIZE_ENV_KEYS = [
"HTTP_COOKIE", # bad cookie encodings kill rack: https://github.com/rack/rack/issues/225
"HTTP_REFERER",
"PATH_INFO",
@pithyless
pithyless / Gemfile
Created November 12, 2012 14:52
Configuration required to setup newrelic-moped
group :production, :acceptance do
gem 'rpm_contrib'
gem 'newrelic-moped' # https://github.com/joinwire/newrelic-moped
gem 'newrelic_rpm'
end
@pithyless
pithyless / equalable.rb
Created April 12, 2013 18:56
Equalable ruby mixin.
module Equalable
def ==(o)
o.class == self.class && o.equality_state == equality_state
end
alias_method :eql?, :==
def hash
equality_state.hash
end
end