Skip to content

Instantly share code, notes, and snippets.

John Hinnegan softwaregravy

View GitHub Profile
View FACTORY_BOT REPRODUCTION_SCRIPT.rb
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "factory_bot", "~> 5.0"
gem "activerecord"
gem "sqlite3"
end
@softwaregravy
softwaregravy / main.rb
Created Mar 14, 2020 — forked from coorasse/main.rb
CanCanCan Issue
View main.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.1.0' # use correct rails version
@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
You can’t perform that action at this time.