Isaiah Peng isaiah

View player
1 2 3 4 5 6 7 8 9 10
package main
 
import (
"bytes"
"code.google.com/p/portaudio-go/portaudio"
"encoding/binary"
"fmt"
"io"
"log"
"os"
View gist:5539458
1 2 3 4 5 6 7 8 9 10
n = 100000
 
# taken from [here](http://blog.lojic.com/2008/12/22/ruby-dynamic-method-invocation-performance/),
# but the original one use the same string all the time, which doesn't reflect real world situation
 
bm(12) {|x|
x.report("orig") { n.times { test = "stormy weather"; test.length } }
x.report("call") { n.times { test = "stormy weather"; m = test.method(:length); m.call } }
x.report("send") { n.times { test = "stormy weather"; test.send(:length) } }
x.report("eval") { n.times { test = "stormy weather"; eval "test.length" } }
View jruby_ext_how_to.md

Problem

Sometimes you found that jruby always complain about cannot find class you defined in your precious java class, that jruby failed to load the Service that defines all the classes in ruby space.

How it work

Let's talk about the way jruby load native extension, take puma as an example, Assume you have 'puma/http11.jar' in your load path, with:

View gist:240846
1 2 3 4 5 6 7 8 9 10
require "rubygems"
require "hmac-sha1"
require "base64"
 
ankoder_access_key = ANKODER_ACCESS_KEY
private_key = ANKODER_PRIVATE_KEY
ankoder_date = Time.now.strftime("%a, %d %b %Y %X GMT")
ankoder_action = "POST"
ankoder_path = "/download"
string = "-#{ankoder_date}-#{ankoder_action}-#{ankoder_path}-"
View gist:199468
1 2 3 4 5 6 7 8 9
require "rubygems"
require "hmac-sha1"
require "base64"
ankoder_access_key = ANKODER_ACCESS_KEY
private_key = ANKODER_PRIVATE_KEY
ankoder_date = Time.now.strftime("%a, %d %b %Y %X GMT")
ankoder_action = "GET"
ankoder_path = "/video.xml"
string = "-#{ankoder_date}-#{ankoder_action}-#{ankoder_path}-"
Something went wrong with that request. Please try again.