Skip to content

Instantly share code, notes, and snippets.

$ ruby test.rb
Run options: --seed 42213
# Running:
running setup
925762681343
running setup
691270111299
.running setup
session = {}
# see https://github.com/mperham/dalli
def common_cache
@common_cache ||= Dalli::Client.new('localhost:11211', { :namespace => "all_apps", :compress => true })
end
def session.[] (arg)
if arg.to_s == 'access_token'
@access_token ||= common_cache.get("sessions/#{self[:user_id]}")
class Signup
include Virtus
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
attr_reader :user
attr_reader :company
class Proxy
def initialize(object)
@object = object
end
def method_missing method, *args, &block
if @object.respond_to? method
@object.send(method, *args, &block).to_s
else
@bbozo
bbozo / .rvmrc
Created November 20, 2014 07:24
.rvmrc for 2+ ruby versions
#!/bin/bash
function rvmrc-production {
export WTGW_ENV_CHOICE='production' # for use in database.yml for example
rvm use jruby-1.7.12 --create
export JRUBY_OPTS=--2.0
}
function rvmrc-development {
export WTGW_ENV_CHOICE='development' # for use in database.yml for example
require 'celluloid/io'
require 'http'
class Client
include Celluloid::IO
def transmit
HTTP.get('http://127.0.0.1:1337', socket_class: Celluloid::IO::TCPSocket)
end
end
/home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:177:in `read': U+0416 from UTF-8 to ASCII-8BIT (Encoding::UndefinedConversionError)
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:177:in `load_rb'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:166:in `load_file'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:15:in `block in load_translations'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:15:in `each'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/base.rb:15:in `load_translations'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/simple.rb:57:in `init_translations'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0.6.9/lib/i18n/backend/simple.rb:71:in `lookup'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p484/gems/i18n-0
@bbozo
bbozo / production.log
Last active January 4, 2016 05:29
Dalli, possible issue with multitenant apps: Cannot share client between multiple processes
Connecting to database specified by database.yml
Cache write: test
Dalli::Server#connect 127.0.0.1:11211
Cache read: test
.... removed a bunch of boot-up ActiveRecord spam ...
Cache read: http://domain_a.somewhere.com/?
127.0.0.1:11211 failed (count: 0) RuntimeError: Cannot share client between multiple processes
Cache read: http://domain_b.somewhere.com/?
@bbozo
bbozo / getter_benchmark.rb
Last active January 3, 2016 13:19
getter_benchmark.rb
class Foo1
FOO = 3
end
class Foo2
def self.foo
3
end
end
@bbozo
bbozo / gist:8315184
Created January 8, 2014 11:06
stack trace for rails/issues/7725
RuntimeError (can't modify frozen String):
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:51:in `force_encoding'
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:51:in `encode_params'
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:63:in `block in encode_params'
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:56:in `each'
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:56:in `encode_params'
actionpack (3.2.16) lib/action_dispatch/http/parameters.rb:12:in `parameters'
actionpack (3.2.16) lib/action_dispatch/http/filter_parameters.rb:31:in `filtered_parameters'
actionpack (3.2.16) lib/action_controller/metal/instrumentation.rb:21:in `process_action'
actionpack (3.2.16) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'