Skip to content

Instantly share code, notes, and snippets.

View chinshr's full-sized avatar

Juergen Fesslmeier chinshr

  • Palo Alto, California
View GitHub Profile
@chinshr
chinshr / human-bugs
Created December 17, 2014 06:09
Human bugs
ambiguity effect
anchoring
availablitlty heuristics
backfire effect
bandwagon effect
barnum effect
Base rate neglect or base rate fallacy
belief bias
bias blind spot
choice-supportive bias
@chinshr
chinshr / gist:b475b0b8398ca2d9f5a2
Last active August 29, 2015 14:11
Orderer collection variants
Spree::Variant.class_eval do
scope :with_distinct_images, -> {
variant_assets_sql = "SELECT MD5(GROUP_CONCAT(`spree_assets`.`image_type`, `spree_assets`.`attachment_file_name`)) FROM `spree_assets`
WHERE `spree_assets`.`type` IN ('Spree::Image') AND `spree_assets`.`viewable_id` = `spree_variants`.`id` AND `spree_assets`.`viewable_type` = 'Spree::Variant'
ORDER BY `spree_assets`.`image_type` ASC, `spree_assets`.`attachment_file_name` ASC"
variant_product_assets_sql = "SELECT MD5(GROUP_CONCAT(`spree_assets`.`image_type`, `spree_assets`.`attachment_file_name`)) FROM `spree_assets`
INNER JOIN `spree_products` ON `spree_products`.`deleted_at` IS NULL
INNER JOIN `spree_variants` `variants_including_masters_spree_products_join` ON `variants_including_masters_spree_products_join`.`product_id` = `spree_products`.`id` AND `variants_including_masters_spree_products_join`.`is_master` = 1 AND `variants_including_masters_spree_products_join`.`deleted_at` IS NULL
WHERE `spree_products
@chinshr
chinshr / Variant includes
Created December 19, 2014 00:05
Variant includes
def variant_includes
[:default_price, :product, collections: [:images, :collection_series], :images, :product => [:master => :images]]
end
@chinshr
chinshr / Scaling Rails
Created January 6, 2015 22:25
Some low and higher hanging fruits to scale Rails apps
<!DOCTYPE html>
<html>
<head>
<title>Scaling Rails</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
@chinshr
chinshr / gist:80127d40ff3205dd784c
Created January 20, 2015 00:51
Current Vendor
class ApplicationController < ...
#...
protected
# session[:current_vendor_id]
def current_vendor
@current_vendor ||= vendor_from_session unless @current_vendor == false
@chinshr
chinshr / gist:38f525b3101af3174f71
Created March 26, 2015 21:40
FedEx Larkspur Dr., Healsburgh, CA", address validation error
POST https://gateway.fedex.com:443/xml/
> <AddressValidationRequest xmlns="http://fedex.com/ws/addressvalidation/v2">
<WebAuthenticationDetail>
<UserCredential>
<Key>wdnHHEULCYFPnEwq</Key>
<Password>KJgbpvpE6W5aroRiAXCAEJO0b</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>632499744</AccountNumber>
@chinshr
chinshr / codeclimate.yml
Created November 9, 2015 19:11
Codecomplexity CC yaml
languages:
Ruby: true
exclude_paths:
- "app/models/video_migration.rb" # is what was intended to be ignored with the previous lib/*_migration.rb ?
- "app/smart/**/*.rb"
- "app/utviz/**/*.rb"
- "config/application.rb" #this didnt seem to be ignored by the following line.
- "config/**/*"
@chinshr
chinshr / codeclimate-complexity-33.rb
Created November 9, 2015 18:50
Codeclimate complexity 33
def perform
Rails.logger.info "AudioExtractor: creating Elastic Transcoder Job for #{ingest.video.handle}"
client.create_job({
pipeline_id: PIPELINE_ID,
input: {
key: "#{ingest.video.handle}.mp4"
},
output: {
key: "#{ingest.video.handle}.mp3",
@chinshr
chinshr / rack_timer.rb
Last active December 15, 2015 19:49
Rack Timer is Rails instrumentation middleware that logs long running middleware, Heroku, request_id, and is adding NewRelic instrumentation to each installed middleware.
# From https://github.com/lukeludwig/rack_timer
# mentioned at http://pulse.sportngin.com/news_article/show/137153
#
# Environment configuration, e.g. heroku.yml:
#
# RACK_TIMER = true | false # instrument middleware?
# RACK_TIMER_LOG = true | false # enable logging for each middleware
# RACK_TIMER_LOG_THRESHOLD = 100 # threshold in ms when logs are written
# RACK_TIMER_NEWRELIC_INSTRUMENTATION = true | false # enable Newrelic instrumentation
#
@chinshr
chinshr / ruby-with-blocks.rb
Last active December 16, 2015 04:09
Adding with() blocks so we avoid the ugliness of assigning values in the if comparisons in Ruby.
# ==with
#
# We have been struggling with the absence of @with@ blocks
# in Ruby for a long time. We had something similar in
# Object Pascal.
#
# Let me explain what it does:
#
# with Invoice.find_by_id(params[:id]) do |invoice|
# puts invoice.total