Skip to content

Instantly share code, notes, and snippets.

I got the horses in the back

Jamie Gaskins jgaskins

I got the horses in the back
Block or report user

Report or block jgaskins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jgaskins / call_metrics.rb
Last active Mar 24, 2019
Trace metrics for methods defined in Ruby code
View call_metrics.rb
require 'pp'
require 'set'
module CountThings
COUNTS = { |h, k| h[k] = { |h, k| h[k] = 0 } }
TIMINGS = { |h, k| h[k] = { |h, k| h[k] = [] } }
TRACED_METHODS = { |h, k| h[k] = }
jgaskins / hooks.rb
Last active Feb 16, 2019
Hooks implementation for Clearwater
View hooks.rb
module Hooks
def self.component *attrs, &render do
attr_reader *attrs
define_method :initialize do |**props|
attrs.each { |attr| `self[#{attr}] = #{props[attr]}` }
jgaskins / sort-videos.js
Created Dec 11, 2018
Sort Confreaks event videos by number of views
View sort-videos.js
.sort((a, b) => (
a.querySelector('.video-views strong').innerText|0) >= (b.querySelector('.video-views strong').textContent|0)
? -1
: 1
).map(v => v.querySelector('.video-title').innerText + ' by ' + v.querySelector('.video-presenters').innerText)
jgaskins /
Created Nov 6, 2018
Optimizing UUID generation from strings in Crystal
require "uuid"
require "benchmark"
struct UUID
def self.optimized(value : String, variant = nil, version = nil)
bytes = uninitialized UInt8[16]
case value.size
when 36 # Hyphenated
{8, 13, 18, 23}.each do |offset|
jgaskins / benchmark_if_vs_exception.rb
Created Oct 21, 2018
Benchmarking conditionals vs exceptions
View benchmark_if_vs_exception.rb
require 'benchmark/ips'
def expensive_operation duration=0.001
sleep duration
Benchmark.ips do |x| 'simple if' do
if false
jgaskins /
Created Oct 17, 2018
Forking HTTP server
class PrintPid
include HTTP::Handler
def call(context)
workers = do |i|
process = fork do
server =[
jgaskins / benchmark.rb
Created Sep 5, 2018
Benchmark callable vs proc as event handlers
View benchmark.rb
class EventHandler
def call event
class Eventable
def initialize
@events = { |h, k| h[k] = [] }
jgaskins / worker.rb
Created Sep 4, 2018
Distribute a large Sidekiq job across many smaller ones
View worker.rb
class ProcessThings
include Sidekiq::Worker
def perform(ids: Thing.ids)
class Individual
include Sidekiq::Worker
jgaskins / render_promise.rb
Created Jun 28, 2018
Rendering a promise with Clearwater
View render_promise.rb
require 'clearwater/black_box_node'
require 'clearwater/component'
require 'clearwater/application'
class RenderPromise
include Clearwater::BlackBoxNode
DEFAULT = proc { Clearwater::Component.span }
Wrapper =
jgaskins / app.rb
Last active May 3, 2019
API app with Roda
View app.rb
require 'authentication'
class MyApp < Roda
include Authentication
plugin :json
route do |r|
r.on('docs') { Docs }
You can’t perform that action at this time.