Skip to content

Instantly share code, notes, and snippets.

View agraves's full-sized avatar

Aaron Graves agraves

  • New York, NY
View GitHub Profile
@agraves
agraves / instructions
Last active August 29, 2015 14:04
Remove expired digicert certs
Instructions for clearing expired DigiCert SSL certificate on OSX
NOTICE: The following instructions "worked for me." Proceed at your own risk.
Symptoms:
* Visiting several sites, such as github, gravatar, twitter's CDN results in "invalid certificate" errors
* For example: http://i.imgur.com/8gPRfI3.png
Instructions
@agraves
agraves / gist:669c78761d5534c867ad
Last active August 29, 2015 14:04
Opened a can of whoop ass
Had a dream last night, uncle greg was being attacked by the wire fence behind gramp's
house in the dark by two fierce raccoons. Clung around his upper body, they were bitting
him repeatedly around hischest and head. Suddenly, in rushes three year old Aaron, like
little Yoda...he stealthy climbs up greg's body and sits up behind his head, reaching down,
he grabs each raccoon's head and quickly breaks their necks..the scene quickly falls away....
but you were left on the other side of the fence, I screamed, Come on, Aaron!! You can make it!!!"
You easily maneuver up the fence to the other side and I thought..."I guess a trip to the
hospital and two rabid shots are in order." Crazy dream...but I was wicked proud of you.
https://www.youtube.com/watch?v=NzcWQZ3yrNo
@agraves
agraves / group.rb
Created August 1, 2011 16:27
Rewrite has_many association on the fly
# Ever needed to dynamically rewrite the conditions on a has_many association?
# This is definitely a hack, but useful if parameterizing or adding scopes are
# not practical for whatever reason.
class Group < ActiveRecord::Base
# Any association will do
has_many :people
def filter_people(conditions)
# All calls to this method after the association is traversed and before a reload
@agraves
agraves / gotcha.rb
Created January 26, 2012 00:48
Spot the bug
class Foo
def self.foo
'foo'
end
private
def self.bar
'bar'
end
@agraves
agraves / application_controller.rb
Created January 26, 2012 07:21
Trace redirects
# Source: http://jkfill.com/2011/05/13/log-which-line-called-redirect_to/
#
# Toss this in ApplicationController and all redirects will generate a log statement
unless Rails.env.production?
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
end
@agraves
agraves / surprise.rb
Created February 7, 2012 22:48
surprise
# incorrect
describe 'foo' do
it 'should bar' do
@foo = Factory(:foo)
@foo.bar
@foo.should_receive :bar # wrong
end
end
# correct
- create_table "book_authors", :force => true do |t|
+ create_table "book_authors", :id => false, :force => true do |t|
+ t.integer "id", :null => false
@agraves
agraves / example.rb
Created April 10, 2012 03:32
Blitz.io confirmation page
# Assuming you have high-voltage installed
# routes.rb
match 'long-blitz-string' => 'pages#forty_two'
# app/controllers/pages_controller.rb
def forty_two
'42'
end
@agraves
agraves / squelch_asset_pipeline.rb
Created April 16, 2012 18:13
Squelch Asset Pipeline
# config/initializers/squelch_asset_pipeline.rb
if Rails.env.development?
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
@agraves
agraves / divio_test.py
Created April 20, 2012 21:56
optimized back-end for divio test
#!/usr/bin/python
def is_user_good_enough(username):
return False