Skip to content

Instantly share code, notes, and snippets.

View danivovich's full-sized avatar

Dan Ivovich danivovich

View GitHub Profile
@danivovich
danivovich / main.rb
Created October 11, 2011 19:10
Pivotal feature points by label
require 'pivotal-tracker'
TOKEN = 'API_TOKEN'
PROJECT_NUM = -1
def estimate_to_hours(estimate)
2 ** estimate
end
PivotalTracker::Client.token = TOKEN
@danivovich
danivovich / mdfind_test_log.sh
Created January 18, 2012 19:54
mdfind test.log files in homedir
ls -lh `mdfind -onlyin $HOME -name test.log`
@danivovich
danivovich / rspec_shallow_dup_spec.rb
Created January 25, 2012 01:04
Shallow copy issue with rspec metadata
describe 'outer', :one => { :two => 2 } do
context 'inner1' do
before do
example.metadata[:one][:three] = 3
end
it 'should have 3' do
example.metadata[:one][:three].should == 3
end
end
@danivovich
danivovich / deploy_count.rb
Created March 1, 2012 02:42
Count deploys from airbrake
require 'nokogiri'
require 'open-uri'
auth_token = 'AUTH_TOKEN'
site = 'https://ACCOUNT_NAME.airbrake.io/projects/PROJECT_NUMBER'
counts = {
:staging => 0,
:production => 0
}
@danivovich
danivovich / factory_girl_step_helpers.rb
Created March 22, 2012 01:39
Factory Girl steps for Turnip
module FactoryGirlStepHelpers
def convert_human_hash_to_attribute_hash(human_hash, associations = [])
HumanHashToAttributeHash.new(human_hash, associations).attributes
end
class HumanHashToAttributeHash
attr_reader :associations
def initialize(human_hash, associations)
@human_hash = human_hash
@danivovich
danivovich / render_the_page_steps.rb
Created June 14, 2012 17:51
Capybara Webkit save and open page but with render
Then /^render the page$/ do
if Capybara.current_driver == Capybara.javascript_driver
file_name = "capybara-webkit-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.png"
name = File.join(*[Capybara.save_and_open_page_path, file_name].compact)
page.driver.render name
begin
require "launchy" # could raise LoadError
raise LoadError unless Launchy::Version::MAJOR >= 2
Launchy.open(name)
rescue LoadError
@danivovich
danivovich / static_assets.rake
Last active December 11, 2015 17:49
replace links to assets in static error pages with links to hashed asset pipeline assets
namespace :assets do
desc 'Update the URIs for assets used in the static pages (e.g. 500.html)'
task :update_static_pages => :environment do
manifest_path = Rails.root.join('public', 'assets', 'manifest.yml')
unless File.exists?(manifest_path.to_s)
raise "Must run assets:precompile first"
end
manifest = YAML.load(manifest_path.read)
%w[404 422 500 504 browser].each do |static_page|
path = Rails.root.join('public', "#{static_page}.html")
@danivovich
danivovich / gunicorn.conf.py
Created March 12, 2013 00:23
Graceful restarts with code reloading on Capistrano style deployed Python applications
import os
import signal
bind = "127.0.0.1:8888"
errorlog = "%s/log/gunicorn.log" % (os.getcwd())
workers = 4
keepalive = 5
preload_app = True
def on_starting(server):
@danivovich
danivovich / ladders.go
Created September 10, 2013 20:43
Chutes and Ladders in Go
package main
import (
"fmt"
"math/rand"
"os"
"text/tabwriter"
"time"
)
@danivovich
danivovich / deps.rb
Created February 13, 2015 17:37
ruby-build deps for chef
%w(autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev).each do |pkg|
package pkg
end