Skip to content

Instantly share code, notes, and snippets.

View jacobo's full-sized avatar

Jacob Burkhart jacobo

  • HOVER
  • San Francisco, CA
View GitHub Profile
@jacobo
jacobo / opencv.rb
Created December 16, 2018 22:29 — forked from acmarques/opencv.rb
class Opencv < Formula
desc "Open source computer vision library"
homepage "http://opencv.org/"
url "https://github.com/opencv/opencv/archive/2.4.13.2.tar.gz"
sha256 "4b00c110e6c54943cbbb7cf0d35c5bc148133ab2095ee4aaa0ac0a4f67c58080"
revision 2
bottle do
sha256 "db402b1fbfc0ae68dd024fc78f63ad4232a64300a8c40b32cb39668d1c8637b2" => :high_sierra
sha256 "53cfcc3c43d671f32a7723e369c3501d65218f4084d9d2fa633671cf14c8381b" => :sierra
def json_pretty(obj)
str = StringIO.new
Pry::ColorPrinter.pp(JSON.parse(obj.to_json), str, (`tput cols` || "200").strip.to_i)
str.rewind
puts str.read.gsub("=>", ": ")
end
def pretty(obj)
str = StringIO.new
Pry::ColorPrinter.pp(JSON.parse(obj.to_json), str, (`tput cols` || "200").strip.to_i)
@jacobo
jacobo / gist:46cf340e5c6ec86eb61535976a2cde5d
Created June 28, 2019 18:58
benchmark a series of method calls
class CaptureThings
attr_reader :things
def initialize(&block)
@things = []
instance_eval(&block)
end
def method_missing(thing)
@things << thing.to_s
end
end
class RedisLock
class << self
def with_lock(name, wait: false)
key = "LOCK:#{name}"
until fetch_lock(key)
if wait
sleep(1)
else
return
end