Skip to content

Instantly share code, notes, and snippets.

Matt Wilson hypomodern

Block or report user

Report or block hypomodern

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:dbcc330f9fde05237fcc
{
init: function(elevators, floors) {
elevators.forEach(function(elevator) {
elevator.floorIsDestination = function(floorNum) {
return elevator.destinationQueue.indexOf(floorNum) != -1;
}
elevator.on("floor_button_pressed", function(floorNum) {
if (!elevator.floorIsDestination(floorNum)) {
elevator.goToFloor(floorNum);
View keybase.md

Keybase proof

I hereby claim:

  • I am hypomodern on github.
  • I am hypomodern (https://keybase.io/hypomodern) on keybase.
  • I have a public key whose fingerprint is 546D D3C6 B046 667D 241C 89DF EBF8 C277 6FF1 854B

To claim this, I am signing this object:

View build_frontend.sh
#!/bin/bash
set -exo pipefail
BUILD_ENV=$1
if [ `uname` == 'Darwin' ]; then
OSX=1
JSCOMPRESSOR="yuicompressor --type js"
else
OSX=
@hypomodern
hypomodern / ams_with_mongoid.rb
Created Jan 21, 2013
Want to use ActiveModel::Serializers with Mongoid-backed models? Here's the initializer you're looking for:
View ams_with_mongoid.rb
Mongoid::Document.send(:include, ActiveModel::SerializerSupport)
Mongoid::Criteria.delegate(:active_model_serializer, to: :to_a)
@hypomodern
hypomodern / randomizer.rb
Created Jun 19, 2012
MongoMapper::Randomizer plugin
View randomizer.rb
module MongoMapper
# From https://gist.github.com/901929
module Randomizer
extend ActiveSupport::Concern
included do
key :randomizer, Integer
before_create Proc.new { |doc| doc.randomizer = self.class.count }
end
@hypomodern
hypomodern / blocks_are_procs.rb
Created May 24, 2012
Blocks become of class Proc in a useful context ;)
View blocks_are_procs.rb
class Proc
def foobar
puts "...method on Proc!"
end
end
def block_class &block
block.call
block.foobar
puts block.class.inspect
@hypomodern
hypomodern / hash_ext.rb
Created May 22, 2012
Ruby Hash#fetch_path
View hash_ext.rb
class Hash
def fetch_path(path, default = nil)
pieces = path.split('.', 2)
value = self[pieces[0]]
return value if value && !pieces[1]
return default if !value.respond_to?(:fetch_path) || !value
value.fetch_path(pieces[1], default)
end
end
@hypomodern
hypomodern / gist:2316750
Created Apr 6, 2012 — forked from cadwallion/gist:2316695
Array() shenanigans...
View gist:2316750
>> Array([])
=> []
>> Array(nil)
=> []
>> Array([{foo: 'bar'}])
=> [{:foo=>"bar"}]
>> Array([{foo: 'bar'}, {bar: 'baz'}])
=> [{:foo=>"bar"}, {:bar=>"baz"}]
>> Array({foo: 'bar'})
=> [[:foo, "bar"]]
@hypomodern
hypomodern / gist:2279482
Created Apr 1, 2012
What I'm currently doing to test behavior when an external service fails
View gist:2279482
client.stub!(:connection).and_return(
Faraday.new do |builder|
builder.adapter :test do |stub|
stub.get('laikal1.card') {[ 500, {}, 'Oh Noes! I blew it up!' ]}
end
end
)
VCR.turned_off do
response = client.fetch
response.status.should == 500
@hypomodern
hypomodern / config.ru
Created Feb 20, 2012
HOWTO: Bundler.setup in a sinatra app
View config.ru
$LOAD_PATH << '.'
$LOAD_PATH << 'lib'
require 'rubygems'
require 'bundler'
Bundler.setup :default, (ENV['RACK_ENV'] || 'development')
# your requires here...
You can’t perform that action at this time.