Skip to content

Instantly share code, notes, and snippets.

@isaiah
isaiah / Gemfile
Last active August 29, 2015 14:06
Bootsrap haml navbar & fixed footer layout
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
@isaiah
isaiah / non-streaming-headers
Last active August 29, 2015 14:04
Rails live streaming sample
$ 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
@isaiah
isaiah / player
Created June 3, 2013 17:33
An audio player in golang.
package main
import (
"bytes"
"code.google.com/p/portaudio-go/portaudio"
"encoding/binary"
"fmt"
"io"
"log"
"os"
@isaiah
isaiah / gist:5539458
Created May 8, 2013 09:51
Ruby dynamic calls benchmark
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" } }
@isaiah
isaiah / How to write JRuby native extension.md
Last active October 13, 2015 02:27
How to write jruby extension

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:

@isaiah
isaiah / gist:240846
Created November 23, 2009 02:17
ankoder full attributes jobs
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}-"
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}-"