Skip to content

Instantly share code, notes, and snippets.

@jbodah
jbodah / autoyard.rb
Created September 21, 2018 21:57
autoyard spike
require 'spy'
require 'spy/util'
TypeAnalysis = Module.new
TypeAnalysis.extend(Spy::API)
singleton_spy = TypeAnalysis.on_object(NegativeKeywordSelectorTrie)
singleton_spy = Spy::Util::TypeAnalysis.new(singleton_spy).decorate
class_spy = TypeAnalysis.on_class(NegativeKeywordSelectorTrie)
class_spy = Spy::Util::TypeAnalysis.new(class_spy).decorate
@jbodah
jbodah / arel_patch.rb
Created September 19, 2018 15:27
adding Arel-supported alias_column support to Rails
require 'arel/attributes/attribute'
module ColumnAlias
module ArelAttributePatch
def name
return super unless relation.engine.respond_to?(:column_aliases)
name_given = super
relation.engine.column_aliases[name_given] || name_given
end
end
@jbodah
jbodah / disk_bottleneck.sh
Created June 4, 2018 15:32
how to check for a disk bottleneck
iostat -xmt 2
# Example output:
06/04/2018 03:29:38 PM
avg-cpu: %user %nice %system %iowait %steal %idle
11.14 0.00 0.75 1.00 0.13 86.98
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 65.00 18.00 1450.50 0.21 23.29 32.79 6.17 4.20 0.08 11.40
@jbodah
jbodah / page_fault
Created June 1, 2018 20:08
check the number of page faults
ps -eo min_flt,maj_flt,cmd | grep mongod.conf | grep -v grep
@jbodah
jbodah / audio-edge-test.html
Created January 20, 2018 18:53
detecting audio edges for auto-trimming using the web audio api
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>audio edge test</title>
</head>
<body>
</body>
<script>
var audioCtx = new AudioContext();
@jbodah
jbodah / multiplex.rb
Created March 16, 2017 19:18
io multiplexing
module TermTerm
def self.start!(command)
master, slave = PTY.open
comand = "script --return -c '#{command}' /dev/null"
i,_,e,t = Open3.popen3(command, out: slave)
multi = TermTerm::Multiplexer.new
multi.forward($stdin, i)
multi.forward(master, $stdout)
multi.forward(e, $stderr)
multi.run!
@jbodah
jbodah / gist:797da4104cfe6c4eb560ad5371b131a2
Created February 22, 2017 19:26
which proc listening on port?
lsof -i :3081
@jbodah
jbodah / pre-push
Last active July 18, 2016 16:20
pre-push2
##
# Run syntax checks before pushing
#
# Installation:
# 1. Copy this gist to .git/hooks/pre-push
# 2. chmod +x .git/hooks/pre-push
#
# NOTE: you can also just call `rubocop --auto-correct` if you would rather
#! /usr/bin/env sh
@jbodah
jbodah / say_hipchat.rb
Created May 6, 2016 18:09
say_hipchat
#! /usr/bin/env ruby
require 'yaml'
require 'hipchat'
def config
@config ||= YAML.load_file(File.expand_path File.join(__FILE__, '../.env.yml'))
end
def hipchat
@jbodah
jbodah / simple_callbacks.rb
Created March 17, 2016 17:41
simple callbacks mixin
# To use, simply define @__callbacks as a hash where the keys are events
# and the values respond to #call (e.g. lambdas, procs, methods)
#
# This implementation assumes you only have one callback per event, but
# you could use an array instead if you wanted
module SimpleCallbacks
def run_callback(type, *args)
@__callbacks[type].call(*args) if @__callbacks.has_key?(type)
end
end