This file contains hidden or 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
[ | |
{ "keys": ["super+backquote"], "command": "auto_complete" } | |
] |
This file contains hidden or 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
# So, I have an controller action that makes multiple calls to third-party APIs over http. | |
# I'd like to parallelize these calls via EventMachine::Synchrony::Multi, but can't figure out how to wire the controller | |
# | |
# This works fine from, say, a script on the command line, but not in a controller running on a thin server. | |
# | |
# What I was missing: a) rack/fiber_pool, b) we don't need the EM.synchrony block | |
class DemoController < ApplicationController # or a sinatra app, same result | |
# ... | |
def evented | |
multi = nil |
This file contains hidden or 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
request = require('request') | |
querystring = require('querystring') | |
module.exports = | |
help: [ | |
{ | |
command: '@agora image QUERY', | |
description: 'Fetches the first Google Image for QUERY' | |
} | |
] |
This file contains hidden or 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
$LOAD_PATH << '.' | |
$LOAD_PATH << 'lib' | |
require 'rubygems' | |
require 'bundler' | |
Bundler.setup :default, (ENV['RACK_ENV'] || 'development') | |
# your requires here... |
This file contains hidden or 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
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 |
This file contains hidden or 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
>> Array([]) | |
=> [] | |
>> Array(nil) | |
=> [] | |
>> Array([{foo: 'bar'}]) | |
=> [{:foo=>"bar"}] | |
>> Array([{foo: 'bar'}, {bar: 'baz'}]) | |
=> [{:foo=>"bar"}, {:bar=>"baz"}] | |
>> Array({foo: 'bar'}) | |
=> [[:foo, "bar"]] |
This file contains hidden or 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
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 |
This file contains hidden or 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
class Proc | |
def foobar | |
puts "...method on Proc!" | |
end | |
end | |
def block_class &block | |
block.call | |
block.foobar | |
puts block.class.inspect |
This file contains hidden or 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
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 |
This file contains hidden or 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
Mongoid::Document.send(:include, ActiveModel::SerializerSupport) | |
Mongoid::Criteria.delegate(:active_model_serializer, to: :to_a) |