Skip to content

Instantly share code, notes, and snippets.


Wilfrido Nuqui Jr. wnuqui

View GitHub Profile
View request_response_client.rb
require "amqp" do
connection = AMQP.connect
channel =
replies_queue = channel.queue("", :exclusive => true, :auto_delete => true)
replies_queue.subscribe do |metadata, payload|
puts "[response] Response for #{metadata.correlation_id}: #{payload.inspect}"
wnuqui / gist:4653064
Last active Dec 11, 2015
3 bare bone rails applications using 3 jruby application servers (all running in heroku cedar)
View gist:4653064
# JAVA_OPTS and Procfiles
JAVA_OPTS: -Djruby.memory.max=384m -Xmx384m -Xms256m -Xss512k -XX:+UseCompressedOops -XX:+PrintGCDetails
# puma backed app's Procfile
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
# torquebox-lite backed app's Procfile
web: bin/torquebox-lite -b -p $PORT --max-threads=8
View gist:3038693
def Time.using_zone_of(zone) = zone
yield = 'UTC'
Time.using_zone_of("Hawaii") do
View gist:3038677
# default zone # => (GMT+00:00) UTC
# then we can assign zone like use "Hawaii" = "Hawaii" # => "Hawaii"
# then do local using zone
local =, 8, 1, 15, 30, 45) # => Wed, 01 Aug 2012 15:30:45 HST -10:00
# then save this local to a column and save
View gist:2960811
STDOUT << URI.escape(create(model.to_sym, options).to_json)
wnuqui / gist:2822263
Created May 29, 2012
a friendly Ruby Object!
View gist:2822263
class Foo
def to_s
"I am friendly. You can debug here thru formatted string."
foo = # "I am friendly. You can debug here thru formatted string."
foo # "I am friendly. You can debug here thru formatted string."
# alternatively
wnuqui / gist:2767143
Created May 22, 2012
module inside a class! what do you think?
View gist:2767143
class Foo
module Bar
def self.test
puts "Test!"
# Bar namespaced to Foo for the "test" util method!
# what do you think?
wnuqui / gist:2717341
Created May 17, 2012
ruby's "system" call suddenly contradicts what I saw running the "rake tasks" in shell
View gist:2717341
# try running a rake task like
RAILS_ENV=test ANOTHER=imaginary rake foo:bar
# and run
rake foo:bar RAILS_ENV=test ANOTHER=imaginary
# both run right?
# now do this
ruby -e "system 'rake foo:bar RAILS_ENV=test ANOTHER=imaginary'"
wnuqui / gist:2717282
Created May 17, 2012
where ruby's str#gsub can really prove that assumptions can really go wrong (any light?)
View gist:2717282
# ruby is 1.9.2p290
"Foo\n".gsub('\n', '') # => "Foo\n"
"Foo\n".gsub("\n", '') # => "Foo"
"Foo\n".gsub("\n", '') # => "Foo"
"Foo\n".gsub('\n', '') # => "Foo\n"
'Foo\n'.gsub("\n", '') # => "Foo\\n"
'Foo\n'.gsub('\n', '') # => "Foo"
# pastie here:
wnuqui / gist:2715883
Created May 17, 2012
prompt in rake task definition
View gist:2715883
# _thanks_ to where I saw this
task :prompt do
STDOUT.puts "Prompt? "
prompt = STDIN.gets.chomp
STDOUT.puts "Cool! Prompt is #{prompt}."
You can’t perform that action at this time.