View keyword_param.rb
1 2 3 4 5 6 7 8 9 10
class Base
def xtest(foo:, bar:, **extra)
puts "base: #{foo}, #{bar}"
end
end
 
class Artzt < Base
def xtest(foo:, bar:, blah:)
super
puts "child: #{foo}, #{bar} #{blah}"
View vimperator
1 2 3 4 5 6 7 8 9 10
unmap h
unmap l
map h previousTab
map l nextTab
map u restoreTab
map d removeTab
map b Vomnibar.activateTabSelection
map t Vomnibar.activateInNewTab
 
map <c-o> goBack
View lazy.rb
1 2 3 4 5 6 7 8 9 10
class Enumerator
class Lazy
def initialize(coll)
 
@lazy = Yid.new do |yielder|
if block_given?
coll.each do |x|
yield yielder, x
end
else
View fib.rb
1 2 3 4 5 6 7 8 9 10
class Fib
def self.fib
a, b = [0, 1]
s = 1..Float::INFINITY
Enumerator::Lazy.new(s.lazy) do |yielder, val|
a, b = b, a + b
yielder << a
end
end
end
View Gemfile
1 2 3 4 5 6 7 8 9 10
source 'https://rubygems.org'
 
gem 'react-rails', '~> 1.0.0.pre', github: 'reactjs/react-rails'
 
gem 'haml-rails'
gem 'bootstrap-sass'
 
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0.beta1'
# Use postgresql as the database for Active Record
View non-streaming-headers
1 2 3 4 5 6 7 8 9 10
$ curl localhost:8080 -I
 
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "0f8cca87cff164a57033f54d75dc1288"
Cache-Control: max-age=0, private, must-revalidate
X-Runtime: 0.017000
Server: Jubilee(2.1.0)
Transfer-Encoding: chunked
Date: Thu, 24 Jul 2014 14:38:03 GMT
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 How to write JRuby native extension.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}-"
Something went wrong with that request. Please try again.