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
class RedisLock
class << self
def with_lock(name, wait: false)
key = "LOCK:#{name}"
until fetch_lock(key)
if wait
sleep(1)
else
return
end
@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
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 / 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
module WithControllerHelper
class TestCase < ActionController::TestCase
def initialize(controller_class)
super("WithControllerHelper")
setup_controller_request_and_response
@routes = Rails.application.routes
@controller = controller_class.new
end
end
gist_it = Proc.new do |content|
post_body = {
description: "gist",
public: false,
files: { :file1 => {content: content}}
}
resp = RestClient.post "https://api.github.com/gists", post_body.to_json, {content_type: :json, accept: :json}
JSON.parse(resp.body)["files"]["file1"]["raw_url"]
end
https://plus.google.com/events/cqkjpnv749irie3s862vtvnvkik?authkey=COeQg_2V36Wi-QE
while :; do clear; git add -A; git commit -m "update"; git push origin master; sleep 2; done
require 'flickraw'
FlickRaw.api_key= "SECRET"
FlickRaw.shared_secret="SECRET"
def reauth
token = flickr.get_request_token
auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'write')
puts auth_url
verify = gets #"123-123-123"
# Put this anywhere in your specfile:
class ReloadHax
def self.setup(*files_to_reload, &go_block)
@files_to_reload, @go_block = files_to_reload, go_block
end
def self.go
ApplicationController.asset_host = "http://billing.localdev.engineyard.com:3000"
ActionView::Resolver.caching = false
@files_to_reload.each{|x| load(File.join(Rails.root,x))}