Skip to content

Instantly share code, notes, and snippets.

View fred's full-sized avatar

Frederico Araujo fred

  • Thailand
View GitHub Profile
@rossdakin
rossdakin / attributes_default.rb
Last active August 29, 2015 14:10
Chef cookbook for creating NAT boxes (intended for use with AWS OpsWorks) – does not do any health checks, HA, nor automatic route table (re)configuration.
# my_nat_cookbook/attributes/default.rb
# specify your CIDR in custom JSON somewhere: { "my_nat_cookbook": { "source_cidr": "10.1.0.0/16" } }
default[:deliv_nat][:source_cidr] = '0.0.0.0/0'
default[:deliv_nat][:aws_region] = node[:opsworks][:instance][:region]
default[:deliv_nat][:ec2_instance_id] = node[:opsworks][:instance][:aws_instance_id]
@dblock
dblock / mongoid_criteria.rb
Created May 24, 2012 19:38
Mongoid::Criteria each_by iterator
module Mongoid
class Criteria
def each_by(by, &block)
idx = 0
total = 0
set_limit = options[:limit]
while ((results = ordered_clone.limit(by).skip(idx)) && results.any?)
results.each do |result|
return self if set_limit and set_limit >= total
@pithyless
pithyless / char_converter.rb
Created September 5, 2012 16:00
Rails middleware to encode characters and avoid exploding controllers
# config/initializers/char_converter.rb
require 'uri'
module Support
class CharConverter
SANITIZE_ENV_KEYS = [
"HTTP_COOKIE", # bad cookie encodings kill rack: https://github.com/rack/rack/issues/225
"HTTP_REFERER",
"PATH_INFO",
@fred
fred / clockwork_celluloid.rb
Created June 28, 2013 17:16
Running clockwork inside a Sidekiq Thread using Celluloid
###
### Rails.root/lib/scheduler.rb
###
require 'celluloid/autostart'
module AwesomeRailsApp
class ClockworkScheduler
include Celluloid
include Clockwork
def run
@vigo
vigo / bunde_complete.sh
Last active July 20, 2016 02:32
Bash completion for bundle
_bundler_complete()
{
if [[ ! `which bundle` ]]; then
return
fi
local cur prev commands
commands="help install update package exec config check list show outdated console open viz init gem platform"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
@vjfrancois
vjfrancois / clockwork.cap
Last active August 6, 2016 15:29 — forked from rogercampos/clockwork.rb
Clockwork and delayed_job tasks file for capistrano 3
namespace :workers do
namespace :clockwork do
desc "Stop clockwork"
task :stop do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} stop"
end
end
<?php
// how to run:
// php download_disputes.php
// Works on Mac OS X
// It will generate (and overwrite) a csv file with name disputes.csv
// Update your valid Live Secret Key, this is only a test key:
$skey = 'skey_';
// Output file name
<?php
// how to run:
// php download_refunds.php
// Works on Mac OS X
// It will generate (and overwrite) a csv file with name refunds.csv
// Update your valid Live Secret Key, this is only a test key:
$skey = 'skey_';
// Output file name
@hyoshida
hyoshida / install-patched-ruby-1.8.7-p375.sh
Last active August 3, 2017 04:05
patch for ruby-build error
# patch for make ruby error
# % rbenv install 1.8.7-p375
# ...
# ossl_pkey_ec.c:815: error: ‘EC_GROUP_new_curve_GF2m’ undeclared (first use in this function)
# ossl_pkey_ec.c:815: error: (Each undeclared identifier is reported only once
# ossl_pkey_ec.c:815: error: for each function it appears in.)
# make[1]: *** [ossl_pkey_ec.o] error 1
# ...
#
# refs: http://forums.cpanel.net/f5/case-84173-error-installing-ruby-377831.html
@skamithi
skamithi / application_controller.rb
Created April 25, 2012 14:53
Adding Opensearch to my Rails 3.2 app
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def opensearch
response.headers['Content-Type'] = 'application/opensearchdescription+xml; charset=utf-8'
end