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 () { | |
Backbone.syncWithoutUpload = Backbone.sync | |
Backbone.syncWithUpload = function(method, model, options) { | |
// Create iframe | |
var iframe_id = 'file_upload_iframe_' + Date.now() | |
, iframe = jQuery('<iframe id="' + iframe_id + '" name="' + iframe_id + '" ></iframe>').hide() | |
// Create an hidden form | |
var authToken = jQuery('meta[name=csrf-token]').attr('content') | |
, authParam = jQuery('meta[name=csrf-param]').attr('content') |
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
#!/usr/bin/env ruby -rubygems | |
@api_token = api_token | |
@project_id = integer_value_or_permalink | |
@paths = [ array_of_file_path ] | |
require 'faraday' # >= 0.8 | |
require 'faraday_middleware' | |
@conn = Faraday.new(:url => 'https://beta.teambox.com/') do |builder| |
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
# Ported from https://github.com/jzaefferer/jquery-validation/blob/master/jquery.validate.js | |
creditcard = (value)-> | |
# accept only spaces, digits and dashes | |
return unless /[^0-9 \-]+/.test(value) | |
nCheck = nDigit = 0 | |
bEven = false | |
checkDigit = (n) -> |
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
queue_name = 'queue:queue_name' | |
len = Resque.redis.llen(queue_name) | |
deletion = Resque.redis.lrange(queue_name,0, len).select do |entry| | |
JSON.parse(entry)['args'][0] == "some_criterial" rescue nil | |
end | |
deletion.each do |entry| | |
puts entry | |
puts Resque.redis.lrem queue_name, -1, entry |
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
#!/usr/bin/env ruby -rubygems | |
reject_keys = %w(PATH STACK URL APP_NAME LOG_LEVEL) | |
reject_keys += %w(RACK_ENV RAILS_ENV NODE_ENV) | |
reject_keys += %w(COMMIT_HASH CONSOLE_AUTH LANG LAST_GIT_BY) | |
reject_keys += %w(REDISTOGO NEW_RELIC DATABASE MONGOHQ MEMCACHE SENDGRID) | |
reject_keys += (ENV['REJECT_ENV_KEYS'].nil? ? [] : ENV['REJECT_ENV_KEYS'].split(',')) | |
keys_regexp = %r/#{reject_keys.join('|')}/i | |
configuration = `heroku config`.split("\n").inject({}) do |hash, line| |
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
require 'delegate' | |
class Klass < DelegateClass(String) | |
# ... | |
end | |
class Klass < DelegateClass(String) | |
# Re-open the class | |
end | |
# => TypeError: superclass mismatch for class Klass |
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
class Foo | |
def self.define_attribute(name) | |
class_eval %{ | |
def #{name}(*args) | |
attribute(#{name.inspect}, *args) | |
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
# USAGE: | |
# rate_limiter = RateLimiter.new('throttle_key', limit: 5, ttl: 1.hour) | |
# rate_limiter.throttled { not_too_often } | |
# | |
class RateLimiter | |
attr_reader :topic, :limit, :ttl, :cache | |
def initialize(topic:, limit:, ttl:, cache: default_cache) | |
@topic, @limit, @ttl, @cache = topic, limit, ttl, cache | |
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
class HashObject | |
def []=(method_name, implementation) | |
define_singleton_method(method_name, &implementation) | |
end | |
def [](method_name) | |
if method(method_name).arity == 0 | |
method(method_name).call | |
else | |
method(method_name).curry |
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
class ItemUpdater | |
class AgedBrie < ItemUpdater | |
def value_change | |
-super | |
end | |
end | |
class BackstagePass < ItemUpdater | |
def value_change | |
case sell_in |