Skip to content

Instantly share code, notes, and snippets.

@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: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,
-# 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"
<!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>
html, body {
background-color: #4B7399;
font-family: Verdana, Helvetica, Arial;
font-size: 14px;
}
a img {
border: none;
}
@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])
@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: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:3291918
Created August 8, 2012 03:54
Fun with barometer
#!/usr/bin/env ruby
# load our gem
require 'barometer'
if ARGV.size == 0
puts "Usage: get_temp.rb PLACE_NAME"
exit 0
end
# make request
@gkop
gkop / joseph.rb
Created September 7, 2012 00:53
Scrape and parse Joseph the Starwatcher, featuring Wombat
# encoding: utf-8
require 'wombat'
SIGNS = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra",
"Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
data = Wombat.crawl do
base_url "http://www.taosnet.com"
path "/starwatcher/rdoscrpt.html"