This file contains hidden or 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
<~/Desktop> ruby lru_benchmark.rb | |
2.250000 0.010000 2.260000 ( 2.252988) | |
<~/Desktop> ruby lru_cache_benchmark.rb # <- mine | |
2.370000 0.000000 2.370000 ( 2.376547) | |
<~/Desktop> ruby lrucache_benchmark.rb | |
3.420000 0.010000 3.430000 ( 3.435718) | |
<~/Desktop> ruby ramaze_lruhash_benchmark.rb | |
53.310000 0.040000 53.350000 ( 53.360825) |
This file contains hidden or 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 "rubygems" | |
require "lru" | |
require "benchmark" | |
cache = Cache::LRU.new(max_elements: 1_000) | |
bm = Benchmark.measure do | |
1_000_000.times do | |
cache[rand(2_000)] ||= :value | |
end |
This file contains hidden or 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 'zmq' | |
include ZMQ | |
ctx = Context.new | |
msg = "*" * 1_024 # 1KB | |
msg = msg * 1_024 # 1MB | |
Thread.new do | |
puller = ctx.socket :PULL |
This file contains hidden or 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
move in to new house: | |
- build house | |
construct house: | |
- add roof | |
- weatherproof roof | |
- add electrical wiring | |
- add plumbing |
This file contains hidden or 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
$ irb | |
[1] pry(main)> require 'rubygems' | |
=> false | |
[2] pry(main)> require 'koala' | |
=> true | |
[3] pry(main)> api = Koala::Facebook::API.new('INSERT YOUR ACCESS TOKEN HERE') | |
=> #<Koala::Facebook::API:0x10dbf34a8 | |
@access_token= | |
"INSERT YOUR ACCESS TOKEN HERE"> | |
[4] pry(main)> api.get_object('bbaldwin', :fields => 'id,languages') |
This file contains hidden or 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 "eventmachine" | |
ROFLSCALE=10 | |
ROFLQUERIES=1000 | |
class CassandraConnection | |
def initialize(id) | |
@id = id | |
end | |
def get(query) |
This file contains hidden or 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 'zmq' | |
describe 'ZMQ' do | |
let(:ctx) { ZMQ::Context.new } | |
after { ctx.destroy } | |
describe 'PUSH and PULL' do |
This file contains hidden or 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
describe CircularReferenceDetector do | |
it "should require a block upon initialization" do | |
lambda { detector = CircularReferenceDetector.new }.should raise_exception | |
end | |
describe CircularReferenceDetector, "#next_nodes" do | |
before :each do | |
@thing = Object.new |
This file contains hidden or 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
describe "CircularReferenceDetector" do | |
it "should identify circular references in linked list" do | |
class Node | |
attr_accessor :next_node | |
end | |
detector = CircularReferenceDetector.new do |node| | |
node.next_node |
This file contains hidden or 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
n --> n --> n | |
^ v | |
n <---+ |