Skip to content

Instantly share code, notes, and snippets.

@gkop
gkop / gist:3079365
Created July 9, 2012 22:12
NPR mp3 url decoder
NPR = {};
NPR.base64 = {};
// Code below belongs to NPR
NPR.base64.PADCHAR = '=';
NPR.base64.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
NPR.base64.makeDOMException = function () {
var e, tmp;
try {
@gkop
gkop / gist:3056743
Created July 5, 2012 21:57
Open page in browser when cuke fails
# in features/support/env.rb
After do |scenario|
# if scenario failed, open page in browser
if ENV["SAVE_AND_OPEN_PAGE"] == "true" && scenario.failed?
save_and_open_page
end
end
@gkop
gkop / gist:2920731
Created June 12, 2012 23:09
Drag thing in to other thing capybara step
## in features/support/selectors.rb
when /^the (?<type>\w+){1} "(?<name>[^"]*){1}"$/
[:xpath, "//li[contains(@class, '#{$~[:type]}') and contains(., '#{$~[:name]}')]"]
## in features/step_definitions/drag_things_steps.rb
def find_by_selector(thing)
selector = selector_for(thing)
find(selector[0], selector[1])
html, body {
background-color: #4B7399;
font-family: Verdana, Helvetica, Arial;
font-size: 14px;
}
a img {
border: none;
}
<!DOCTYPE html>
<html>
<head>
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
<%= yield(:head) %>
</head>
<body>
-# adapted from https://github.com/ryanb/nifty-generators/blob/master/lib/generators/nifty/layout/templates/layout.html.haml
!!!
%html
%head
%title
= content_for?(:title) ? yield(:title) : "Untitled"
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
= stylesheet_link_tag "nifty"
@gkop
gkop / gist:2340796
Created April 9, 2012 01:58
Regexes to upgrade to new FactoryGirl syntax
# NOTE if you want to do this outside a git repo, find . -type f can by substituted for git grep -l 'Factory'
# fix Factory.create and Factory()
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory(\.create)?\((\:)?(\w+)(, )?/FactoryGirl\.create\($2$3$4/g'
# fix Factory.build
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory\.build\((\:)?(\w+)(, )?/FactoryGirl\.build\($1$2$3/g'
# fix Factory.define
# NOTE after running this, at the very least you still have to wrap your definitions sets with a FactoryGirl.define do end block,
@gkop
gkop / auto_strip_text_attributes.rb
Created March 20, 2012 22:42 — forked from rahearn/auto_strip_text_attributes.rb
Adding functionality to every model in a system
# This file is in lib
module AutoStripTextAttributes
extend ActiveSupport::Concern
included do
text_columns = columns.collect do |c|
c.name.to_sym if c.type == :string || c.type == :text
end.compact
@gkop
gkop / gist:1531106
Created December 29, 2011 01:55
parallel_tests without ActiveRecord
namespace :db do
desc "Stub out to use with parallel_tests gem without ActiveRecord"
task :abort_if_pending_migrations do
end
end
@gkop
gkop / gist:1424593
Created December 2, 2011 19:49
convoluted alternative to which which
# bash lies
$ time --version
--version: command not found
real 0m0.127s
user 0m0.120s
sys 0m0.020s
$ /usr/bin/time --version