Skip to content

Instantly share code, notes, and snippets.

Rodrigo Rosenfeld Rosas rosenfeld

Block or report user

Report or block rosenfeld

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rosenfeld
rosenfeld / config.ru
Created Jul 23, 2016
Sample simple Rack application demonstrating rack_web_console used with rack-webconsole
View config.ru
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'] == '/'
RackConsole.new(binding).call env
View cookies-serialization-bug.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
#gem 'railties', '4.2.7' # it's also present in version 4
@rosenfeld
rosenfeld / thread-pool.rb
Created Jun 7, 2016
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 = SizedQueue.new(max_threads)
max_threads.times{ @pool << 1 }
@mutex = Mutex.new
@running_threads = []
end
@rosenfeld
rosenfeld / README.txt
Last active Nov 15, 2018
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
rosenfeld / puma-app.sh
Last active Aug 29, 2015
Puma example init script. It assumes .ruby_version exist in the APP_PATH and either rbenv or rvm is used.
View puma-app.sh
#!/lib/init/init-d-script
### BEGIN INIT INFO
# Provides: my-script-name
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Run my app on Puma
### END INIT INFO
@rosenfeld
rosenfeld / application_controller.rb
Created Jul 18, 2014
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:
# https://github.com/isaacs/github/issues/21
# This is the discussion to comment on: http://blog.arkency.com/2014/07/4-ways-to-early-return-from-a-rails-controller/
class ApplicationController < ActionController::Base
# ...
around_action :catch_halt
def render(*args)
@rosenfeld
rosenfeld / README
Created Apr 3, 2014
Demonstrates how to generate refined version for Facets gem
View README
Simple script that should work if you follow the convention of declaring a single outer class per file with simple class names and structure.
Some files may not be compatible with refinements and should have some comment like "#skip-refinement-conversion" in the file header (first 10_000 chars of the file). The "class" line should also be in the header section of the file.
Files skipped will be copied "as is" to the new directory.
@rosenfeld
rosenfeld / puma.bash
Last active Aug 29, 2015
Init script for Puma with RVM
View puma.bash
#!/bin/bash
. /lib/lsb/init-functions
. ~/.rvm/scripts/rvm
# or for rbenv installed with Chef:
# . /etc/profile.d/rbenv.sh
PWD=~/ecore/src/jvm_bridge
PIDFILE=$PWD/tmp/pids/puma.pid
STATUSFILE=$PWD/tmp/pids/state.pid
PORT=4002
@rosenfeld
rosenfeld / benchmark.rb
Last active Aug 29, 2015
Concatenating first vs concatenating last performance comparison
View benchmark.rb
environment = Rails.application.assets
asset = nil
environment.send :expire_index!
FileUtils.rm_rf environment.cache.instance_variable_get :@root
puts Benchmark.measure{File.write '/tmp/application-orig.js', (asset = environment['application']).source}.total
puts(Benchmark.measure do
@rosenfeld
rosenfeld / alternatives.txt
Created Jan 24, 2014
Groovy lightweight web framework alternatives
View alternatives.txt
https://github.com/ratpack/example-ratpack-standalone-groovy-script/blob/master/ratpack.groovy
https://github.com/mbteswedenab/gretty/wiki/Getting-Started
https://github.com/webdevwilson/graffiti
You can’t perform that action at this time.