Skip to content

Instantly share code, notes, and snippets.

View rosenfeld's full-sized avatar

Rodrigo Rosenfeld Rosas rosenfeld

View GitHub Profile
@rosenfeld
rosenfeld / gist:202717
Created October 6, 2009 03:04
First Ruby Challenge - Shift Subtitle
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 / chef-gitorious-etc-solo.rb
Created February 28, 2011 12:29
Chef configuration files for Gitorious
file_cache_path "/root/chef-solo"
cookbook_path "/root/chef-solo/cookbooks"
json_attribs "/root/chef-solo/node.json"
@rosenfeld
rosenfeld / example.rb
Created June 2, 2011 20:34
Messaging API suggestion for Gitorious
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
# 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
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)
--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 / client.rb
Created April 4, 2012 20:40
Demonstrate how to use Drb to integrate to Java through Ruby and JRuby
# ruby client.rb SheetName > output.xls
require 'drb/drb'
SERVER_URI="druby://localhost:8787"
DRb.start_service
service = DRbObject.new_with_uri(SERVER_URI)
puts service.get_excel_output('sheet_name' => ARGV.first || 'Test')
@rosenfeld
rosenfeld / .ctags
Last active January 12, 2018 00:50
CoffeeScript support for exuberant-ctags
--langdef=CoffeeScript
--langmap=CoffeeScript:.coffee
--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
rosenfeld / conway.rb
Created May 2, 2012 20:49
Conway's Game of Life in Ruby
class Life
attr_reader :live_cells
def initialize(live_cells)
@live_cells = live_cells
end
alias :to_a :live_cells
def next_generation
@rosenfeld
rosenfeld / fake_server.js.coffee
Created June 3, 2012 22:24
oojs sample generated files
# =require fake_ajax_server
createProducts = -> [
{id: 1, name: 'One'}
{id: 2, name: 'Two'}
]
extendClass 'specs.ShoppingCartSpec', ->
createFakeServer: ->
@fakeServer = new FakeAjaxServer (url, settings)->