Skip to content

Instantly share code, notes, and snippets.

@sbeam
sbeam / -
Created October 3, 2014 12:24
--- 123d2pKhY1JNsNsc0bzw4L_37.vcl 2014-10-03 08:22:28.000000000 -0400
+++ 123d2pKhY1JNsNsc0bzw4L_38.vcl 2014-10-03 08:22:03.000000000 -0400
@@ -421,14 +421,21 @@
# Header rewrite Whitelist Querystring : 10
- set req.url = regsuball(req.url, "(?:(?<=[?&])(?!_escaped_fragment_|brand|branch|type|min_msrp|max_msrp|_type|keywords|page|per_page|tags|name|order_by|adid|return_url|event|classifications|zip|website_ids)[^&]+?)(?:&|$)", "");
+ set req.url = regsuball(req.url, "(^|[\\?&]+)([^&\\/=]+(?:(&|$))|(?!_escaped_fragment_|brand|branch|type|min_msrp|max_msrp|_type|keywords|page|per_page|tags|name|order_by|adid|return_url|event|classifications|zip|website_ids\\b)[^&\\/=]+=[^&]+)", "&");
# this tests a critical regex used in the 'Whitelist Query Params' config in
# Fastly, to transform request URLs into a normalized version that strips
# 'traffic partner' tracking params and other noise, but leaves any valid keys
# that match the params we actually use. A lot hinges on the proper operation
# of this regex to keep hit ratio high but leave needed params intact.
#
# This version leaves trailing ? and &, which is unavoidable now but are pulled
# out by a simple second sweep.
#
# http://regex101.com/r/oJ2gI6/10
@sbeam
sbeam / gist:7e0dd95453d1e54398b7
Last active August 29, 2015 14:06
wrapping snazziness
class Foo
def self.with_enthusiasm
boring_old_methods = instance_methods(false)
yield
snazzy_new_methods = instance_methods(false) - boring_old_methods
snazzy_new_methods.each do |method|
method_without_chains = "#{method.to_s}_with_reset".to_sym
alias_method method_without_chains, method
define_method method do |*args|
@sbeam
sbeam / variant_decorator.rb
Created October 16, 2012 17:48
Spree::Variant.find_by_options
Spree::Variant.class_eval do
# find variants matching the given map of option_type.id's to option_value.id's
# and optionally limited to one product
# Spree::Variant.find_by_options {'4'=>'14','1'=>'3',2=>6, 3=>10}, product
def self.find_by_options opts={}, product=nil
sovv = Arel::Table.new :spree_option_values_variants
sot = Spree::OptionType.arel_table
sov = Spree::OptionValue.arel_table
@sbeam
sbeam / gist:3849340
Created October 7, 2012 19:39
capybara helper for select2-ajax elements
# select2_ajax helper to make capybara work with ajax-enabled Select2 elements
# assumes 'placeholder' option is used in Select2 (if it is using ajax, it should be)
#
# usage:
#
# it "should have a select2 field for searching by team name" do
# @team = Factory :team
# select2_ajax @team.name, :from => "Select a Team", :minlength => 4
# click_button "Join"
# page.should have_content "You are now on '#{@team.name}'."
@sbeam
sbeam / thin.sh
Created August 24, 2012 19:08
/etc/init.d/thin - replacement that runs bundle exec thin within each site
#!/bin/bash
### BEGIN INIT INFO
# Provides: thin
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: thin initscript
# Description: thin
### END INIT INFO
@sbeam
sbeam / deploy.rb
Created August 23, 2012 18:55
Ruby version management on Debian
require "bundler/capistrano" # runs bundle:install on remote for us
# give cap the correct path to our custom installed rubies
default_environment['PATH'] = "/usr/local/ruby/bin:/usr/bin:/bin"
# ... rest of normal cap config
@sbeam
sbeam / randpw.pl
Created March 15, 2012 02:03
password/passphrase hybrid generator
#!/usr/bin/perl -w
# Usage: randpw.pl <len>
# optional <len> truncate to so many chars
# using my copy of /usr/dict/words, n = 53970, so with default settings, r=2 and
# ((n+1)! / (r * (n-1)!) = 1456407435 (because its a duplicative combination at this stage)
# so there are
# (1456407435 * 1000 * 68)^3 = 9.7134 x 10^41
# possible passwords here,
/home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:506:in `rename': Not a directory - /home/sbeam/public_html/alpinehausct/tmp/cache/00020120110-11026-hr2o4s-0 or /home/sbeam/public_html/alpinehausct/tmp/cache/001/000/ (Errno::ENOTDIR)
from /home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:506:in `mv'
from /home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:1402:in `fu_each_src_dest'
from /home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:1418:in `fu_each_src_dest0'
from /home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:1400:in `fu_each_src_dest'
from /home/sbeam/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/fileutils.rb:495:in `mv'
from /home/sbeam/.rvm/gems/ruby-1.8.7-p352@alpinehaus/gems/activesupport-3.1.3/lib/active_support/core_ext/file/atomic.rb:35:in `atomic_write'
from /home/sbeam/.rvm/gems/ruby-1.8.7-p352@alpinehaus/gems/activesupport-3.1.3/lib/active_support/cache/file_store.rb:102:in `write_entry'
from /home/sbeam/.rvm/
@sbeam
sbeam / gist:1571992
Created January 6, 2012 19:22
Y U NO WORK CONTROLLER SPEC
class SubscriptionsController < ApplicationController
def create
@subscription = Subscription.new params[:subscription]
@subscription.save
respond_to do |wants|
wants.js
wants.html
end