Skip to content

Instantly share code, notes, and snippets.

View scottwater's full-sized avatar

Scott Watermasysk scottwater

View GitHub Profile
@scottwater
scottwater / ab_helper.rb
Created May 9, 2013 10:42
Quick and dirty A/B testing Rails views
module ABHelper
def choose_test(name, default_option, *options)
key = "#{name}_ab"
unless current_test = (params[key] || session[key] || cookies[key])
current_test = options[rand(options.count)]
end
current_test = default_option unless options.include?(current_test)
session[key] = cookies.permanent[key] = current_test
end
@scottwater
scottwater / nodoublesubmit.coffee
Created September 12, 2012 16:06
Stop Double Submits and then re-enable the button (when validation fails/etc)
$ = jQuery
$.fn.extend
nodoublesubmit: (options) ->
settings =
delay: 2000
debug: false
settings = $.extend settings, options
@scottwater
scottwater / gist:3638694
Created September 5, 2012 15:42
Quick heroku
function hs(){
heroku "$@" --remote staging
}
function hp(){
heroku "$@" --remote production
}
window.location = 'http://www.google.com';
@scottwater
scottwater / deprecated.rb
Created April 5, 2012 20:29
Is this the best pattern for deprecating a method paramater?
module FullContact
class Client
module Person
# Returns extended information for a given person (email, phone, twitter or facebook)
#
def person(options={})
if options.is_a?(String)
warn "[DEPRECATION] supplying an email address directly is deprecated. Please use {email: #{options}} instead."
options = {:email => options}
end
@scottwater
scottwater / body.htm
Created April 2, 2012 17:55
KickoffLabs SlideShow
<div id="gallery">
<img src="http://static.kickofflabs.com.s3.amazonaws.com/jo/harvest.png" alt="" data-caption="#caption_1" />
<img src="http://static.kickofflabs.com.s3.amazonaws.com/jo/stayconnected.png" alt="" data-caption="#caption_2" />
<span id="caption_1" class="orbit-caption">Create a beautiful looking site... </span>
<span id="caption_2" class="orbit-caption">Caption 2</span>
</div>
@scottwater
scottwater / email_queue.rb
Created February 17, 2012 17:47
EmailQueue for Sidekiq
class EmailQueue
include Sidekiq::Worker
def perform(options)
mailer = options['mailer'].constantize
method = options['method']
args = options['args']
mailer.send(method, *args).deliver
end
jQuery ->
$("form").submit (e) ->
e.preventDefault()
email = $("#email").val()
return if email.length == 0
$.ajax
url: "https://api.kickofflabs.com/v1/1905/subscribe",
data: "email=#{email}",
dataType: 'jsonp',
jsonp: 'jsonp',
@scottwater
scottwater / api.coffee
Created January 18, 2012 02:21
Sample Coffee
jQuery ->
$("form").submit (e) ->
e.preventDefault()
email = $("#email").val()
return if email.length == 0
$.ajax
url: "https://api.kickofflabs.com/v1/1905/subscribe",
data: "email=#{email}",
dataType: 'jsonp',
jsonp: 'jsonp',
@scottwater
scottwater / topsy.json
Created January 11, 2012 19:08
topsy example (bug?)
{"request":{"parameters":{"window":"h3","q":"kickofflabs"}
,"response_type":"json","resource":"search","url":"http://otter.topsy.com/search.json?q=kickofflabs&window=h3"}
,"response":{"window":"h3","page":1,"total":4,"perpage":10,"last_offset":4,"hidden":0,"list":[{"trackback_permalink":"","trackback_author_url":"http://twitter.com/russellbuckley","content":"MWC Unofficial Fringe Festival 2012 - Coming Soon! http://t.co/aR2LwZon","trackback_date":1326306392,"topsy_author_img":"http://a2.twimg.com/profile_images/1335736386/Twitter_normal.jpg","hits":1,"topsy_trackback_url":"http://topsy.com/trackback?url=http%3A%2F%2Fmobile-world-congress-fringe-festival.kickofflabs.com%2F%3Fs%3D3G79&utm_source=otter","firstpost_date":1326306392,"url":"http://mobile-world-congress-fringe-festival.kickofflabs.com/?s=3G79","trackback_author_nick":"russellbuckley","highlight":"MWC Unofficial Fringe Festival 2012 - Coming Soon! http://t.co/aR2LwZon ","topsy_author_url":"http://topsy.com/twitter/russellbuckley?utm_source=otter"