Skip to content

Instantly share code, notes, and snippets.

View huoxito's full-sized avatar
🏊‍♂️

Washington L Braga Jr huoxito

🏊‍♂️
View GitHub Profile
@huoxito
huoxito / slim-redux.js
Created June 6, 2017 14:46 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
index c1562fc..f036359 100644
--- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
@@ -81,12 +81,16 @@ module ActionDispatch
return unless logger
exception = wrapper.exception
+ klass_name = wrapper.exception.class.name
+ return if ActionDispatch::ExceptionWrapper.rescue_responses[klass_name] == :not_found
@huoxito
huoxito / example.rb
Created July 4, 2016 18:24
assets:precompile on ci servers
# in config/environments/test.rb
if running_on_ci?
config.assets.compile = true
config.assets.digest = true
end
# cache these two dirs:
# - tmp/cache/assets/test/sprockets
# - public/assets
@huoxito
huoxito / trap_focus.js.coffee
Last active April 25, 2016 03:22
trap focus
# based of https://accessibility.oit.ncsu.edu/blog/2015/02/13/the-incredible-accessible-modal-window-version-3/
class FocusTrap
@init = (evt, $domNode) ->
focusableElements = 'a[href], button, input:not([disabled]), select:not([disabled]), textarea, *[contenteditable]'
if evt.which == 9
o = $domNode.find('*')
focusableItems = o.filter(focusableElements).filter(':visible')
return unless focusableItems.length
@huoxito
huoxito / custom_cookie_store.rb
Created March 3, 2016 01:09
Set CookieStore key on a request basis
@huoxito
huoxito / ar_merge_party.rb
Created May 19, 2015 02:07
spree i18n and globalize dance
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', path: '../rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
//
var items = payload.shipment.items;
var new_items = [];
for (i = 0; i < items.length; i++) {
var item = items[i];
var quantity = item.quantity;
if (item.bundled_items && item.bundled_items.length > 0) {

On current master:

$ ruby benchmarkips.rb
  0.200000   0.010000   0.210000 (  0.248978)

$ ruby benchmarkips.rb
  0.200000   0.010000   0.210000 (  0.249966)

$ ruby benchmarkips.rb
@huoxito
huoxito / add_to_cart.sql
Last active August 29, 2015 14:10
Checkout add to cart sql review
Spree::LineItem Load (0.3ms) SELECT "spree_line_items".* FROM "spree_line_items" WHERE "spree_line_items"."order_id" = $1 ORDER BY spree_line_items.created_at ASC [["order_id", 12]]
Spree::Price Load (0.2ms) SELECT "spree_prices".* FROM "spree_prices" WHERE "spree_prices"."deleted_at" IS NULL AND "spree_prices"."variant_id" = $1 [["variant_id", 1]]
(0.1ms) BEGIN
Spree::Product Load (0.3ms) SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."id" = $1 LIMIT 1 [["id", 1]]
Spree::TaxCategory Load (0.4ms) SELECT "spree_tax_categories".* FROM "spree_tax_categories" WHERE "spree_tax_categories"."deleted_at" IS NULL AND "spree_tax_categories"."id" = $1 LIMIT 1 [["id", 1]]
(0.4ms) SELECT SUM("spree_stock_items"."count_on_hand") AS sum_id FROM "spree_stock_items" INNER JOIN "spree_stock_locations" ON "spree_stock_locations"."id" = "spree_stock_items"."stock_location_id" WHERE "spree_stock_items"."deleted_at" IS NULL AND "spree_stock_items"."variant_id" = 1 AND "spree_stock_locatio
@huoxito
huoxito / add_order.rb
Created August 27, 2014 18:20
Give back service ID to Wombat
def add_order
# do stuff / add the order to shopify and get that order id
#
# e.g. order = Shopify.create_order @payload
# This will do a partial update in Wombat, only the new key
# shopify_id will be added everything else will be the same
add_object "order", { @payload[:order][:id], shopify_id: order.id }
result 200, "Order created!"
end