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 RedisLock | |
class << self | |
def with_lock(name, wait: false) | |
key = "LOCK:#{name}" | |
until fetch_lock(key) | |
if wait | |
sleep(1) | |
else | |
return | |
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
class CaptureThings | |
attr_reader :things | |
def initialize(&block) | |
@things = [] | |
instance_eval(&block) | |
end | |
def method_missing(thing) | |
@things << thing.to_s | |
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
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) |
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 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 |
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 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 |
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
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 |
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
https://plus.google.com/events/cqkjpnv749irie3s862vtvnvkik?authkey=COeQg_2V36Wi-QE |
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
while :; do clear; git add -A; git commit -m "update"; git push origin master; sleep 2; done |
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
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" |
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
# 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))} |
NewerOlder