Skip to content

Instantly share code, notes, and snippets.

View rosenfeld's full-sized avatar

Rodrigo Rosenfeld Rosas rosenfeld

View GitHub Profile
rosenfeld / application_controller.rb
Created July 18, 2014 11:47
Supporting automatic return from render/redirect/head in Rails
View application_controller.rb
# Please don't comment in this gist since I'm not notified by any comments here:
# This is the discussion to comment on:
class ApplicationController < ActionController::Base
# ...
around_action :catch_halt
def render(*args)
rosenfeld / thread-pool.rb
Created June 7, 2016 12:49
Simple thread pool implementation in Ruby
View thread-pool.rb
require 'thread' # for Mutex: Ruby doesn't provide out of the box thread-safe arrays
class ThreadPool
def initialize(max_threads = 10)
@pool =
max_threads.times{ @pool << 1 }
@mutex =
@running_threads = []
rosenfeld / client.rb
Created April 4, 2012 20:40
Demonstrate how to use Drb to integrate to Java through Ruby and JRuby
View client.rb
# ruby client.rb SheetName > output.xls
require 'drb/drb'
service = DRbObject.new_with_uri(SERVER_URI)
puts service.get_excel_output('sheet_name' => ARGV.first || 'Test')
rosenfeld / README.txt
Last active November 15, 2018 09:48
Sprite generator to replace compass (only Ruby and ImageMagick are required)
View README.txt
This was created to replace compass in a Rails project.
The generator supports multiple themes and the sprite dimensions are available in a dimensions.sass file as variables.
There are no other dependencies than Ruby and ImageMagick binaries (or compatible commands with convert and identify).
The image name contains an MD5 hash of all images content and is stored directly into public/assets
so that the resulting CSS doesn't depend on sprockets.
It took about 0.2s to generate two theme sprites for me with about 30 images each.
rosenfeld / pagination.sql
Created September 28, 2012 18:18
Pagination example with PostgreSQL
View pagination.sql
select username, count(*) over() from user order by username limit 5 offset 0;
rosenfeld /
Created August 7, 2012 19:06
Parse query params in CoffeeScript
# for simple use case - doesn't take into account multiple occurrences
parseParams = (search =>
d = (str)-> decodeURIComponent str.replace /\+/g, ' '
query = search.substring 1
regex = /(.*?)=([^\&]*)&?/g
params = {}
params[d(m[1])] = d(m[2]) while m = regex.exec query
rosenfeld / .ctags
Last active January 12, 2018 00:50
CoffeeScript support for exuberant-ctags
View .ctags
--regex-CoffeeScript=/(^|=[ \t])*class ([A-Za-z.]+)( extends [A-Za-z.]+)?$/\2/c,class/
--regex-CoffeeScript=/^[ \t]*@?([A-Za-z.]+):.*[-=]>.*$/\1/f,function/
--regex-CoffeeScript=/^[ \t]*([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\1/f,function/
--regex-CoffeeScript=/^[ \t]*([A-Za-z.]+)[ \t]+=[^-=>\n]*$/\1/v,variable/
rosenfeld /
Created July 23, 2016 13:44
Sample simple Rack application demonstrating rack_web_console used with rack-webconsole
require 'rack_web_console'
require 'rack-webconsole'
Rack::Webconsole.inject_jquery = true
#Rack::Webconsole.key_code = '39'
use Rack::Webconsole
run ->(env) {
return [404, {}, []] unless env['PATH_INFO'] == '/' env
View cookies-serialization-bug.rb
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
gemfile(true) do
source ''
#gem 'railties', '4.2.7' # it's also present in version 4
rosenfeld / chef-gitorious-etc-solo.rb
Created February 28, 2011 12:29
Chef configuration files for Gitorious
View chef-gitorious-etc-solo.rb
file_cache_path "/root/chef-solo"
cookbook_path "/root/chef-solo/cookbooks"
json_attribs "/root/chef-solo/node.json"