Skip to content

Instantly share code, notes, and snippets.

View kenton's full-sized avatar

Kenton Newby kenton

View GitHub Profile
@kenton
kenton / spec_helper.rb
Created April 8, 2014 14:35
Automate migrations in specs
# in spec_helper.rb or wherever your testing framework has initialization code
if ActiveRecord::Migrator.needs_migration?
ActiveRecord::Migrator.migrate(File.join(Rails.root, 'db/migrate'))
end
@kenton
kenton / product.rb
Last active August 29, 2015 14:02
problem with solr joins
# Notes:
# a product has_many variants
# conf is just a configuration object that holds a bunch of stuff. in this case, we're interested in the values
# for option_facets, which are the values we want to be able to facet on.
searchable do
if conf.option_facets.present?
conf.option_facets.each do |option_facet|
join(option_facet, :type => :integer, :join_string => "from=product_id to=id")
@kenton
kenton / gist:7dd74a377e5448c1e904
Created June 30, 2014 17:34
git precommit hook
#!/usr/bin/env ruby
# exit 0 means "all good"
todo = `git diff --staged | ack KGNTODO`
open_page = `git diff --staged | ack save_and_open_page`
pry = `git diff --staged | ack 'binding.pry'`
remote_pry = `git diff --staged | ack 'binding.remote_pry'`
if todo.empty? and pry.empty? and remote_pry.empty? and open_page.empty?
Sass::SyntaxError at /app/sign-up/testurl ========================================= > Mixin sd-rhythm-padding is missing argument $padding. (in /Users/kentonnewby/dev/lampo/smartdollar/app/assets/stylesheets/application.css.scss:38) app/views/layouts/application.html.erb, line 14 ----------------------------------------------- ``` ruby 9 <%= csrf_meta_tags %> 10 <%= yield(:meta) if content_for?(:meta) %> 11 12 13 > 14 <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 15 <%= render "layouts/shared/typekit" %> 16 <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 17 <%= yield(:head_assets) if content_for?(:head_assets) %> 18 <%= analytics_loader(:adobe_dtm) %> 19 ``` App backtrace ------------- - app/views/layouts/application.html.erb:14:in `_app_views_layouts_application_html_erb___3178877113320295523_2280383700' - app/views/layouts/onboarding.html.erb:11:in `_app_views_layouts_onboarding_html_erb__4167278517789202693_2278189940' - spec/features/c
@kenton
kenton / Budget Form Downloaded
Created February 25, 2015 22:16
Quickstart Budget Saved
{
"id"=>"4c7e3e16-217e-423e-859b-ecd225a7254a",
"properties"=>{"filename"=>"quick_start_budget.pdf"},
"visit_id"=>"7492226c-8821-4c68-8cb4-c246904c840d",
"visitor_id"=>"745f62c8-6378-44f9-aef2-eb666dddf93b",
"user_id"=>"AXIDKN1ABC1AB0AB",
"time"=>"2015-02-25T08:34:36.279-06:00",
"event"=>"smartdollar.engagement.budget_form.downloaded",
"request"=>{"uuid"=>"d633d1ba-9dd3-4ea2-b31c-1ecea2b8bffd", "remote_ip"=>"127.0.0.1",
"session_id"=>"1a11ab111dba20a1119999da84999abc"},
@kenton
kenton / pre-commit.rb
Last active August 29, 2015 14:27
git pre-commit hook to check for problem files before commiting
#!/usr/bin/env ruby
problems = []
checks = {
#'_spec\.rb$' => ['focus:[:space:]*true'],
'\.rb$' => [
'binding.pry',
'debugger',
'if true',
@kenton
kenton / gist:1597674
Created January 12, 2012 00:22
Shell command to copy all gemsets from one ruby version to another
# you'll need to adjust the names of the source and destination ruby versions
# you may also need to adjust the number of fields that are cut (the -f 7 flag in the cut command) if the output of "rvm gemset list" changes at some point down the road
rvm gemset list | sed 's/^[[:space:]]*//' | cut -d ' ' -f 7 | while read gemset; do rvm gemset copy 1.9.2@$gemset 1.9.3@$gemset; done
(@ondemand)(1m|feature/ondemand-geogrid!?) ~limos $ git pull origin feature/ondemand-geogrid
From ldc.beanstalkapp.com:/ldc-git
* branch feature/ondemand-geogrid -> FETCH_HEAD
Auto-merging lib/ondemand/pricing/geographic_shapes/disambiguation.rb
Auto-merging lib/ondemand/pricing/TESTING.txt
Merge made by the 'recursive' strategy.
app/models/geographic_shape.rb | 3 ++-
lib/ondemand/pricing/TESTING.txt | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/ondemand/pricing/geographic_generator/market_geometries.rb | 9 +++++++-
lib/ondemand/pricing/geographic_shapes/database_installer.rb | 6 ++++-
>> dropoff_coords = "37.3716, -121.921"
=> "37.3716, -121.921"
>> pickup_coords = "37.3741595214844, -121.925221923828"
=> "37.3741595214844, -121.925221923828"
>> quote = Ondemand::Pricing::Ride::QuoteRide.new_from_rate_card(:dropoff_latlng => dropoff_coords, :pickup_latlng => pickup_coords)
{"rows":[{"elements":[{"status":"ZERO_RESULTS"}]}],"destination_addresses":["37.368,-42.2769"],"status":"OK","origin_addresses":["37.3769933814132,-42.2951683058561"]}
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
from /Users/kentonnewby/dev/limos/lib/ondemand/pricing/routes/google_distance_matrix_api/request.rb:94:in `perform'
>> pickup_coords = "37.7296575656584,-122.45277792457"
>> dropoff_coords = "37.7835680142054,-122.469833645424"
=> "37.7835680142054,-122.469833645424"
>> quote = Ondemand::Pricing::Ride::QuoteRide.new_from_rate_card(:dropoff_latlng => dropoff_coords, :pickup_latlng => pickup_coords)
#<Ondemand::Pricing::Formula:0x10a3088c8
@kind=:quote,
@market_rate=#<BigDecimal:10a2fd7e8,'0.2E2',9(27)>,
@minimum_price=#<BigDecimal:10a2fd928,'0.15E2',9(27)>,
@pricing_tiers=nil,
@ride=