This file contains 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
module ObjectSpace | |
def self.profile(&blk) | |
require 'objspace' | |
enable_gc = GC.disable | |
ObjectSpace.trace_object_allocations(&blk) | |
objs = Hash.new(0) | |
ObjectSpace.each_object { |o| | |
if (file = ObjectSpace.allocation_sourcefile(o)) && (line = ObjectSpace.allocation_sourceline(o)) | |
objs["#{file}:#{line}:#{o.class.name}"] += 1 |
This file contains 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
heroku addons:add pgbackups --remote staging | |
heroku addons:add pgbackups --remote production | |
heroku pgbackups:capture --remote production | |
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging |
This file contains 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
>> load './RUNME-demo_of_async_fibers.rb' | |
/Users/flip/ics/backend/son_of_a_batch/RUNME-demo_of_async_fibers.rb:4: warning: already initialized constant FIBER_IDXS | |
814e5e90 0 f_0 beg main top level | |
814e5e90 1 f_0 beg em setup this block sets up the eventmachine execution, but no execution-order shenanigans yet | |
814e5e90 2 f_0 beg fiber stp the end-the-reactor block won't be called for 1.5s, so we get here immediately. | |
814e5e90 3 f_0 end fiber stp nothing from inside the Fiber.new{} block has run yet. | |
814e5e90 4 f_0 end fiber stp kick off the fiber... | |
80d829a0 5 f_1 beg fiber when my_fiber.resume is called, this runs. Now in a new fiber | |
80d829a0 6 f_1 beg get_result get_result is called from within fiber_1 | |
80d829a0 7 f_1 setup callback set up some code to run 1.5s from now |
This file contains 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
class QueryTracer < ActiveSupport::LogSubscriber | |
ACCEPT = %r{^(app|config|lib)}.freeze | |
FRAMES = 5 | |
THRESHOLD = 300 # In ms | |
def sql(event) | |
return unless event.duration > THRESHOLD | |
callers = Rails. | |
backtrace_cleaner. |
This file contains 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
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) | |
Benchmark.bm(10) do |x| | |
x.report do | |
100.times do | |
100.times { fork {} } | |
Process.waitall | |
end | |
end | |
end |
This file contains 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
#!/usr/bin/env ruby | |
# Usage: gemspec [-s] GEMNAME | |
# | |
# Prints a basic gemspec for GEMNAME based on your git-config info. | |
# If -s is passed, saves it as a GEMNAME.gemspec in the current | |
# directory. Otherwise prints to standard output. | |
# | |
# Once you check this gemspec into your project, releasing a new gem | |
# is dead simple: | |
# |