Skip to content

Instantly share code, notes, and snippets.

@mrjabba
mrjabba / 127fib.rb
Created November 30, 2013 16:44
127 Parallel Fib from Ruby Tapas
require 'thread'
require "benchmark"
module FibSolver
def self.fib(scheduler_queue, my_queue)
loop do
scheduler_queue << [:ready, my_queue]
message, *args = my_queue.pop
case message
when :fib
@mrjabba
mrjabba / gist:6159864
Created August 5, 2013 21:41
rvm install of ruby 2.0.0
Saving wrappers to '/Users/khutson/.rvm/wrappers/ruby-2.0.0-p247'........
ruby-2.0.0-p247 - #importing default gemsets, this may take time...............................
/Users/khutson/.rvm/scripts/functions/support: line 291: 89701 Segmentation fault: 11 "$ruby_path" -rrbconfig -e '\
File.open("'"$config_path"'","w") { |file|
RbConfig::CONFIG.sort.each{|key,value|
file.write("#{key.gsub(/\.|-/,"_")}=\"#{value.gsub("$","\\$")}\"\n")
}
}
' > /dev/null 2>&1
@mrjabba
mrjabba / caller.txt
Created January 24, 2013 21:41
Ruby kernel#caller
Kernel has a great method you can call. "caller".
Returns an array of the stack that called you.
So if you want to just see your immediate caller,
you can do puts "who called me caller=#{caller.first}"
and it will print the immediate caller.
If your method is being called from multiple clients this seems useful in debugging..
@mrjabba
mrjabba / scan_jars.bash
Created December 6, 2012 19:31
jar scanning
NOTE how to to look for stuff inside a directory of jar files from the command line
for i in *.jar; do jar -tvf "$i" | grep com.foo; done

Under jruby 1.6.7:

want_spring=1 rspec spec/models/ums_user_spec.rb

  • 20 seconds until we start doing maven
  • 45 seconds until we start running tests
  • Time 8.11 seconds. Total time 53 seconds

rspec spec (skips spring test above)

  • 23 seconds until we start doing maven
  • 31 seconds until we start running tests
  • Time 15.4 seconds. Total time 51 seconds
@mrjabba
mrjabba / Sweet n Spicy pulled pork.md
Created October 6, 2012 01:23
Sweet n Spicy pulled pork

Sweet n Spicy pulled pork

We had some extra pork loin, cooked in a crock pot, then pulled.

I created this sauce that I let some of it simmer in. Delicious.

  • 1 stick celery, sliced
  • 1 carrot, sliced
  • one half scallion, sliced
  • one quarter white onion, sliced
@mrjabba
mrjabba / amqp_tester.rb
Created July 27, 2012 21:51
simplest possible thing..works..pub and sub together
def do_it
#simplest possible thing..works..pub and sub together..
puts "do it.."
EventMachine.run do
connection = AMQP.connect('amqp://guest:guest@localhost:5672')
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
opts = {:durable => true, :ack => true}
ex_name = "my.exchange.name"
q_name = "myqueue"
@mrjabba
mrjabba / consumer.rb
Created July 20, 2012 17:08
rabbit consumer testing
class BaseMessageHandler
def initialize(opts = {})
@connection_string = opts[:rabbit_mq_host]
raise ConfigurationError.new('rabbit_mq_host is not specified') unless @connection_string
end
def fetch_channel
AMQP.start(@connection_string) do |connection, open_ok|
AMQP::Channel.new(connection) do |channel|
yield channel
@mrjabba
mrjabba / newScheduledThreadPool_jruby.rb
Created July 11, 2012 20:33
how to schedule a newScheduledThreadPool in jruby
require 'java'
java_import 'java.util.concurrent.Executors'
java_import 'java.util.concurrent.TimeUnit'
class SomeClass
include java.lang.Runnable
def run
puts "imma lil jruby runner"
end
end
@mrjabba
mrjabba / rack_simple.rb
Created May 12, 2012 17:14
Creating the simplest possible server in ruby using rack
my_rack_proc = lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello. The time is #{Time.now}"]] }
puts my_rack_proc.call({})
require 'rack'
Rack::Handler::WEBrick.run(my_rack_proc, :Port => 3000)