Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
seanlilmateus / async_await.rb
Last active December 27, 2020 08:34
whenever Rubymotion returns a symbol of the def-expr, async and await like c# will be possible
module AsyncAwait
class Task < NSOperation
def self.new(&block)
alloc.initWithBlock(block)
end
def initWithBlock(block)
init.tap do
@hiattp
hiattp / sidekiq.config
Last active March 6, 2020 09:14
Sidekiq Config for Elastic Beanstalk
# 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
@tanraya
tanraya / gist:7438337
Created November 12, 2013 20:44
Carrierwave auto orient image explained
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
@bf4
bf4 / rails32_http_patch_support.rb
Last active June 4, 2018 09:04
HTTP PATCH support in Rails 3.2
# 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?
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) => {
@seanlilmateus
seanlilmateus / values_for_keys_with_dictionary.rb
Last active May 12, 2018 21:43
Using Cocoa’s KVC to assign JSON keys and values to Rubymotion models <Objects>
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
@henrik
henrik / config--initializers--rails4_to_rails3_downgradability.rb
Created June 18, 2015 09:55
Fix "NoMethodError: undefined method `sweep'" error when downgrading from Rails 4 to Rails 3.
# 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'])
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@grosser
grosser / resque_web.rb
Created September 13, 2011 15:08 — forked from skippy/resque_web.rb
Mountable resque-web for rails 3+ apps
# 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]
@ruckus
ruckus / AppController.php
Created October 25, 2012 04:51
CakePHP Request logging ala Rails
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