Skip to content

Instantly share code, notes, and snippets.

# fix memory caching in dev mode
# put this in config/initializers/fix_caching_in_dev.rb
# Hopefully this won't be needed for long, this fixes cache calls (due to class reloading in dev)
# http://blog.bashme.org/2008/07/25/rails-21-model-caching-issue/
if ActiveSupport::Dependencies.mechanism == :load
module ActiveSupport
module Cache
class Store
require "rubygems"
require "rbench"
def omg_slow
return 1
end
def omg_fast
1
end
require 'rubygems'
require 'tokyo_tyrant'
TYRANT = TokyoTyrant::Table.new
AMOUNT_RECORDS = 8000
$TYRANT_ID = 0
RECORD = {
"component_version" => "X",
"state" => "Analyze",
@actsasflinn
actsasflinn / TyrantRecord.rb
Created August 10, 2009 03:39
TyrantRecord, an experimental interface for modeling using Tokyo Tyrant
# Tyrannical
require 'tokyo_tyrant'
class TrueClass
def to_tokyo_tyrant;"1";end
end
class FalseClass
def to_tokyo_tyrant;"0";end
@actsasflinn
actsasflinn / gist:160348
Created August 3, 2009 03:35
experiment with Tokyo Tyrant as an ActiveRecord cache layer
require 'tokyo_tyrant'
$tyrant = TokyoTyrant::Table.new
module Cacheable
module TyrantTable
def self.included(base) #:nodoc:
super
base.class_eval %q{
cattr_accessor :cache_records
@@cache_records = false
require 'tokyo_tyrant'
t = TokyoTyrant::Table.new('127.0.0.1', 1978)
100.times do |i|
t[i] = { 'name' => "Pat #{i}", 'sex' => i % 2 > 0 ? 'male' : 'female' }
end
q = t.query
q.condition('sex', :streq, 'male')
q.limit(5)
@actsasflinn
actsasflinn / gist:116096
Created May 22, 2009 12:38
ruby-tokyotyrant takes @kamal's url shortener test
# URL shortener used to benchmark redis-rb and RubyRedis applied to ruby-tokyotyrant
# Script takes 1.2 seconds
require 'rubygems'
require 'benchmark'
require 'tokyo_tyrant'
puts Benchmark.realtime{
T=TokyoTyrant::DB.new('127.0.0.1', 45000)
def shorten(url)
#!/usr/bin/env ruby
# use this to install the same gems you have installed under one ruby in another
# run "gem list > ~/Desktop/gems.txt"
# run "ruby install_gems.rb /Users/r38y/Desktop/gems.txt"
gems = IO.readlines(ARGV.first)
gems.map! do |g|
stuff = g.split(' ')
gem_name = stuff.delete_at(0)
stuff.map{|v| v.gsub(/[\(\)\,]/, '')}.map{|v| "sudo gem install #{gem_name} -v=#{v}"}
@actsasflinn
actsasflinn / gist:87215
Created March 28, 2009 22:01
Bulk Table Operation (10k write/read) with ruby-tokyotyrant
=begin
Tokyo Tyrant Bulk Table Operations Benchmark
TokyoTyrant (C)
user system total real
bulk writing data 0.180000 0.000000 0.180000 ( 0.292081)
bulk reading data 0.120000 0.020000 0.140000 ( 0.216074)
@actsasflinn
actsasflinn / gist:83194
Created March 22, 2009 15:19
Bulk Operation (10k write/read) with ruby-tokyotyrant
=begin
Tokyo Tyrant Bulk Operations Benchmark
TokyoTyrant::RDB (Ruby) mget
user system total real
inserting data 7.770000 1.870000 9.640000 ( 12.598373)
reading data 1.540000 0.250000 1.790000 ( 2.290628)