Skip to content

Instantly share code, notes, and snippets.

John Hinnegan softwaregravy

Block or report user

Report or block softwaregravy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@softwaregravy
softwaregravy / delete_old_app_version.sh
Created Mar 13, 2012
Delete old beanstalk application versions
View delete_old_app_version.sh
elastic-beanstalk-describe-application-versions -a APPLICATION_NAME | sed '1,2d' | sed '/CURR_APP_VERSION/d' | cut -d '|' -f 6 | xargs -L 1 elastic-beanstalk-delete-application-version -a APPLICATION_NAME -l
@softwaregravy
softwaregravy / irb.rb
Created Mar 11, 2012
Override IRB Prompt
View irb.rb
require 'irb'
module IRB
class << self
alias :orig_init_config :init_config
def init_config(ap_path)
begin
puts "loading init config: #{Rails.env}"
# Set up the prompt to be slightly more informative
View sandbox-sample.html
<html>
<body>
<script type="text/javascript">
var lat = 40.733722;
var lon = -73.990683;
var id = "1234567890";
var api_endpoint = "api-sandbox.thinknear.com";
var link_endpoint = "m2-s.thinknear.com";
var api_key = "YOUR API KEY";
var app_id = "YOUR APP ID";
View factories.rb
Factory.define :user do |user|
user.sequence(:email) {|n| "1test#{n}@sample.com"}
user.password 'secret'
user.password_confirmation 'secret'
end
@softwaregravy
softwaregravy / business_spec.rb
Created Oct 13, 2011
Business spec refactoring
View business_spec.rb
# before
let (:user) { Factory(:user) }
# after
before :all do
@user = Factory(:user)
end
after :all do
@user.destroy
View time_period_spec.rb
# before
describe "<=>" do
it "first compares days" do
l = TimePeriod.create(:start_day => 1, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
r = TimePeriod.create(:start_day => 2, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
(l <=> r).should == -1
(r <=> l).should == 1
end
end
View day_map.rb
module DayMap
day_array = []
Date::DAYNAMES.each_with_index{|d, i| day_array << [d, i]}
reverse_day_array = []
Date::DAYNAMES.each_with_index{|d, i| reverse_day_array << [i, d]}
DAY_MAP = Hash[day_array]
REVERSE_MAP = Hash[reverse_day_array]
class << self
View gist:1210203
# What I really wanted my logic to be
def my_method(options = {})
if options.has_key?(:key) && !options[:key].nil?
if options[:key]
# do something using the option here
else
# do something else
end
end
end
@softwaregravy
softwaregravy / gist:1210199
Created Sep 11, 2011
Options of Nil and Fasle
View gist:1210199
# The way I basically always check
def my_method(options = {})
if options[:key]
# do something using the option here
end
end
View gist:1210197
# Probably the proper way to check a hash for options
def my_method(options = {})
if options.has_key?(:key) && !options[:key].nil?
# do something using the option here
end
end
You can’t perform that action at this time.