This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STDOUT << URI.escape(create(model.to_sym, options).to_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _thanks_ to where I saw this | |
task :prompt do | |
STDOUT.puts "Prompt? " | |
prompt = STDIN.gets.chomp | |
STDOUT.puts "Cool! Prompt is #{prompt}." | |
end |
NewerOlder