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
module AsyncAwait | |
class Task < NSOperation | |
def self.new(&block) | |
alloc.initWithBlock(block) | |
end | |
def initWithBlock(block) | |
init.tap do |
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
# Sidekiq interaction and startup script | |
files: | |
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh": | |
mode: "000755" | |
content: | | |
#!/bin/bash | |
. /opt/elasticbeanstalk/hooks/common.sh | |
. /opt/elasticbeanstalk/support/envvars |
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
module CarrierWave | |
module MiniMagick | |
# Rotates the image based on the EXIF Orientation | |
# According to http://jpegclub.org/exif_orientation.html | |
def auto_orient | |
manipulate! do |image| | |
case image['EXIF:Orientation'].to_i | |
when 2 | |
image.flop | |
when 3 |
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
# Rails 3.2 support for HTTP PATCH. | |
fail "Remove this patch" if Rails::VERSION::MAJOR > 3 | |
# see http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/ | |
# https://github.com/rails/rails/pull/505 | |
# Be very conservative not to monkey-patch any methods until | |
# the relevant files are loaded. | |
ActiveSupport.on_load(:action_controller) do | |
ActionDispatch::Request.instance_eval do | |
# Is this a PATCH request? |
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
let people = [ | |
{ name: 'Bob', age: 28, child: { name: 'Sally', age: 8, grade: 3 } }, | |
{ name: 'Sara', age: 46, child: { name: 'Lois', age: 14, grade: 9 } }, | |
{ name: 'Ann', age: 27, child: { name: 'George', age: 9, grade: 4 } }, | |
{ name: 'Dave', age: 52, child: { name: 'Hale', age: 17, grade: 11 } }, | |
]; | |
const add1 = (x) => x + 1; | |
const toFieldApplyFunc = (field, fn) => { | |
return (obj) => { |
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 User | |
MAPPING_KEYS = Hash[ 'user_name', :name, 'total_video_count', :videosCount] | |
attr_accessor *MAPPING_KEYS.values, :age | |
def initialize(args={}) | |
if args.is_a?(Hash) | |
dictionary = Hash[ args.map { |k, v| [MAPPING_KEYS.fetch(k, k) , v] } ] | |
setValuesForKeysWithDictionary(dictionary) | |
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
# Without this fix, downgrading from Rails 4 to Rails 3 causes session cookies to blow up. | |
# | |
# The way the flash is stored in the session changed in a backwards-incompatible way. | |
if Rails::VERSION::MAJOR == 3 | |
module ActionDispatch | |
class Flash | |
def call(env) | |
if (session = env['rack.session']) && (flash = session['flash']) |
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
Model.new.foo |
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
# https://gist.github.com/1214052 | |
require 'sinatra/base' | |
class ResqueWeb < Sinatra::Base | |
require 'resque/server' | |
use Rack::ShowExceptions | |
if CFG[:user].present? and CFG[:password].present? | |
Resque::Server.use Rack::Auth::Basic do |user, password| | |
user == CFG[:user] && password == CFG[:password] |
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 AppController extends Controller { | |
function beforeFilter() { | |
$this->capture_request_head_for_log(); | |
} | |
/* | |
Log some basic basic details of the HTTP Request: | |
Started GET "/users/lost" for 127.0.0.1 at 2012-10-24 19:18:25 -0700 |