Skip to content

Instantly share code, notes, and snippets.

View kenton's full-sized avatar

Kenton Newby kenton

View GitHub Profile
@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 / 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"},
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 / 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?
@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 / 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

For RS-2265, a ReturnAuth should allow selection of a warehouse, defaulting to SF

My intended workflow would have been something like this:

  • add a warehouse_id column to ReturnAuthorizations
  • include spec for validations that a ReturnAuth marked as "accepted" has to have a warehouse_id present
  • ReturnAuthorization#process_return calls ReturnAuthorization#return_inventory_units
  • ReturnAuthorization#return_inventory_units calls InventoryUnit#return! on each of the ReturnAuth's inventory_units
  • InventoryUnit#return! is a state transition that has a callback function, InventoryUnit#restock_variants
  • InventoryUnit#restock_variants increments the variant count to restock that item
  • This should also be where the warehouse is set for that variant, but you need to be able to pass in the warehouse object to the #return! method used for the state transition. This can be done with a block, but requries reimplementing the state machine found in Spree::InventoryUnit in the spree/trr-deploy branch.
<div class="box" data-hook="admin_users_index_search">
<h3>Search</h3>
<form accept-charset="UTF-8" action="/admin/users" class="spree/user_search" id="spree/user_search" method="get">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&#x2713;" />
</div>
<p>
Email<br><input id="q_email_cont" name="q[email_cont]" size="18" type="text" />
</p>
<div data-hook="admin_users_index_search_buttons">
# getting this json format in the response
[{"product":{"id":160,"name":"3.1 Phillip Lim Dress"}},{"product":{"id":161,"name":"3.1 Phillip Lim Skirt"}},{"product":{"id":178,"name":"3.1 Phillip Lim Dress"}},{"product":{"id":175,"name":"3.1 Phillip Lim Dress"}},{"product":{"id":156,"name":"3.1 Phillip Lim Wool Dress"}},{"product":{"id":158,"name":"3.1 Phillip Lim Plaid Skirt"}},{"product":{"id":159,"name":"3.1 Phillip Lim Silk Pants"}},{"product":{"id":162,"name":"3.1 Phillip Lim Woven Blazer"}},{"product":{"id":163,"name":"3.1 Phillip Lim Strapless Dress"}},{"product":{"id":164,"name":"3.1 Phillip Lim Tiered Skirt"}},{"product":{"id":166,"name":"3.1 Phillip Lim Shift Dress"}},{"product":{"id":167,"name":"3.1 Phillip Lim Beaded Tee"}},{"product":{"id":168,"name":"3.1 Phillip Lim Silk Dress"}},{"product":{"id":171,"name":"3.1 Phillip Lim Shearling Jacket"}},{"product":{"id":172,"name":"3.1 Phillip Lim Printed Sweater"}}]
# need this format in the response
[{"id":156,"name":"3.1 Phillip Lim Wool Dress"},{"id":15
Spree::Sunspot::Setup.configure do
searchable auto_index: true,
auto_remove: true,
include: [:variants],
if: ->(prod) { prod.in_active_flash_sale_now? } do
text :name, boost: 2.0
text :description, boost: 1.2