View gist:806d4cc48b644ee941ef
1 2 3 4 5 6 7 8 9 10
def method_calls(detailed: false, thread: nil)
[].tap do |log|
ident = -1
trace = TracePoint.new(:call, :return, :c_call, :c_return) do |tp|
break if thread and thread != Thread.current
 
case tp.event
when :call, :c_call
if tp.event == :call or detailed
ident += 1
View reduce_allocations_rails_32.rb
1 2 3 4 5 6 7 8 9 10
# rails 3.X patch to remove extra allocations on field access
module ActiveRecord::AttributeMethods::Read::ClassMethods
def internal_attribute_access_code(attr_name, cast_code)
access_code = "(v=@attributes[attr_name]) && #{cast_code}"
 
unless attr_name == primary_key
access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
end
 
if cache_attribute?(attr_name)
View gist:8f0a7d83509c80b53c45
1 2 3 4 5 6 7 8 9 10
def track_sql(&block)
timing = Hash.new 0
track = ->(_,start,finish,_,data) do
Thread.exclusive do
timing[data[:name]] += (finish - start)
end
end
 
ActiveSupport::Notifications.subscribed(track, 'sql.active_record', &block)
timing
View sidekiq_bench.rb
1 2 3 4 5 6 7 8 9 10
require 'benchmark'
require 'sidekiq/limit_fetch'
require 'sidekiq/cli'
 
total = ARGV.shift || 50
concurrency = ARGV.shift || 1
limit = ARGV.shift
 
total = total.to_i
limit &&= limit.to_i
View .editrc
1 2
bind "\e[A" ed-search-prev-history
bind "\e[B" ed-search-next-history
View repro.rb
1 2 3 4 5 6 7 8 9 10
$:.unshift '.'
 
require 'rake'
load 'Rakefile'
load 'rakelib/kernel.rake'
require 'lib/mri_bridge.rb'
require 'lib/melbourne.rb'
require 'lib/compiler'
 
File.to_ast 'kernel/bootstrap/basicobject.rb'
View cassandra-schema_dsl.gemspec
1 2 3 4 5 6 7 8 9 10
Gem::Specification.new do |s|
s.name = 'cassandra-schema_dsl'
s.version = '0.1'
s.author = 'brainopia'
s.summary = 'Cassandra schema dsl'
s.files = ['cassandra-schema_dsl.rb']
s.require_path = '.'
s.add_dependency 'cassandra'
View octokit_mirror.rb
1 2 3 4 5 6 7 8 9 10
class Octokit::Mirror
attr_reader :remaining, :reserved
def initialize(options={})
@client = Octokit::Client.new options
@remaining = Atomic.new Float::INFINITY
@reserved = Atomic.new 0
@monitor = Atomic.new 0
end
View task.rb
1 2 3 4 5 6 7 8 9 10
require 'delegate'
 
class Task
extend Forwardable
def_delegators 'self.class', :collection, :indication
 
class << self
def queues
[OrgRepos, Members, Orgs, Projects, Users, Stars, Contributions]
end
View gist:3910381
1 2 3 4 5 6 7 8 9
require 'eventmachine'
 
class Request < EM::P::HeaderAndContentProtocol
CRLF = "\r\n"
 
def receive_request(headers, body)
receive_full_request headers.join(CRLF) << CRLF*2 << body
end
end
Something went wrong with that request. Please try again.