Skip to content

Instantly share code, notes, and snippets.

View wnuqui's full-sized avatar

Wilfrido Nuqui Jr. wnuqui

  • Mandaluyong, Philippines
View GitHub Profile
require "amqp"
EventMachine.run do
connection = AMQP.connect
channel = AMQP::Channel.new(connection)
replies_queue = channel.queue("", :exclusive => true, :auto_delete => true)
replies_queue.subscribe do |metadata, payload|
puts "[response] Response for #{metadata.correlation_id}: #{payload.inspect}"
end
@wnuqui
wnuqui / gist:4653064
Last active December 11, 2015 20:09
3 bare bone rails applications using 3 jruby application servers (all running in heroku cedar)
# 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 0.0.0.0 -p $PORT --max-threads=8
@wnuqui
wnuqui / gist:3038693
Created July 3, 2012 09:17
switch zone
def Time.using_zone_of(zone)
Time.zone = zone
yield
Time.zone = 'UTC'
end
Time.using_zone_of("Hawaii") do
puts Time.zone.now
end
@wnuqui
wnuqui / gist:3038677
Created July 3, 2012 09:13
in the zone
# default zone
Time.zone # => (GMT+00:00) UTC
# then we can assign zone like use "Hawaii"
Time.zone = "Hawaii" # => "Hawaii"
# then do local using zone
local = Time.zone.local(2012, 8, 1, 15, 30, 45) # => Wed, 01 Aug 2012 15:30:45 HST -10:00
# then save this local to a column and save
STDOUT << URI.escape(create(model.to_sym, options).to_json)
@wnuqui
wnuqui / gist:2822263
Created May 29, 2012 03:05
a friendly Ruby Object!
class Foo
def to_s
"I am friendly. You can debug here thru formatted string."
end
end
foo = Foo.new # "I am friendly. You can debug here thru formatted string."
foo # "I am friendly. You can debug here thru formatted string."
# alternatively
@wnuqui
wnuqui / gist:2767143
Created May 22, 2012 06:45
module inside a class! what do you think?
class Foo
module Bar
def self.test
puts "Test!"
end
end
end
# Bar namespaced to Foo for the "test" util method!
# what do you think?
@wnuqui
wnuqui / gist:2717341
Created May 17, 2012 08:15
ruby's "system" call suddenly contradicts what I saw running the "rake tasks" in shell
# 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
wnuqui / gist:2717282
Created May 17, 2012 07:59
where ruby's str#gsub can really prove that assumptions can really go wrong (any light?)
# 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: http://pastie.org/3924412
@wnuqui
wnuqui / gist:2715883
Created May 17, 2012 02:58
prompt in rake task definition
# _thanks_ to where I saw this
task :prompt do
STDOUT.puts "Prompt? "
prompt = STDIN.gets.chomp
STDOUT.puts "Cool! Prompt is #{prompt}."
end