Skip to content

Instantly share code, notes, and snippets.

View rosenfeld's full-sized avatar

Rodrigo Rosenfeld Rosas rosenfeld

View GitHub Profile
@rosenfeld
rosenfeld / benchmark.rb
Last active August 29, 2015 13:56
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 / puma.bash
Last active August 29, 2015 13:57
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 / README
Created April 3, 2014 16:53
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-app.sh
Last active August 29, 2015 14:06
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 / gist:202717
Created October 6, 2009 03:04
First Ruby Challenge - Shift Subtitle
View gist:202717
require 'optparse'
optparse = OptionParser.new do |opts|
opts.banner = 'Usage: shift_subtitle.rb --operation add|sub --time ss,mmm input_file output_file'
opts.on('--operation OPERATION', /^add|sub$/, 'OPERATION must be add or sub'){|o| @operation=o}
opts.on('--time TIME_SHIFT', /^\d{2},\d{3}$/,
'TIME_SHIFT must be in format ss,mmm, where ss are the seconds and mmm are the milliseconds to shift') do |o|
@time_shift = o.sub(',', '.').to_f
end
@rosenfeld
rosenfeld / example.rb
Created June 2, 2011 20:34
Messaging API suggestion for Gitorious
View example.rb
Gitorious::Messaging.default_implementation = :in_memory
Gitorious::Messaging.start
Gitorious::Messaging.publish_to_queue('queue_name', :something => 1)
Gitorious::Messaging.publish_to_queue('queue_name', :something => 2)
messages = []
Gitorious::Messaging.subscribe_to_queue('queue_name'){|msg| puts "message: #{msg}"; messages << msg}
@rosenfeld
rosenfeld / show-terms-and-conditions.spec.coffee
Created October 6, 2011 01:44
show Terms and Conditions
View show-terms-and-conditions.spec.coffee
# spec/js/show-terms-and-conditions.spec.coffee:
require './jasmine-sinon' # wouldn't you love if vanilla JavaScript also supported 'require'?
dom = require 'jsdom'
#f = (fn) -> __dirname + '/../../web-app/js/' + fn # if you prefer to be more explicit
f = (fn) -> '../../web-app/js/' + fn
window = $ = null
@rosenfeld
rosenfeld / example.rb
Created March 8, 2012 21:19
Threads performance comparison between JRuby and MRI
View example.rb
require 'nokogiri'
require 'benchmark'
require 'thread'
require 'open-uri'
# for JRUBY: export JRUBY_OPTS="--1.9 -J-Xmx2048m"
# JRuby 1.6.7 doesn't support File.write yet in 1.9 mode. Just doing some cache here - not important
File.open('test.html', 'w'){|f| f.write(open('http://www.sec.gov/Archives/edgar/data/1129623/000095012310064472/d73737ddefm14a.htm').read) } unless File.exists?('test.html')
content = File.read('test.html')
@rosenfeld
rosenfeld / ctags
Created March 21, 2012 00:18
Grails ctags/Vim support (~/.ctags)
View ctags
--langdef=groovy
--langmap=groovy:.groovy
--regex-groovy=/^[ \t]*[(private|public|protected) ( \t)]*def[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f,function,functions/
--regex-groovy=/^[ \t]*private def[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/v,private,private variables/
--regex-groovy=/^[ \t]*public def[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/u,public,public variables/
--regex-groovy=/^[ \t]*[abstract ( \t)]*[(private|public) ( \t)]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class,classes/
--regex-groovy=/^[ \t]*[abstract ( \t)]*[(private|public) ( \t)]*enum[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class,classes/
@rosenfeld
rosenfeld / conway.rb
Created May 2, 2012 20:49
Conway's Game of Life in Ruby
View conway.rb
class Life
attr_reader :live_cells
def initialize(live_cells)
@live_cells = live_cells
end
alias :to_a :live_cells
def next_generation