Skip to content

Instantly share code, notes, and snippets.

View commuterjoy's full-sized avatar

Matt Chadburn commuterjoy

View GitHub Profile
@commuterjoy
commuterjoy / gist:1170957
Created August 25, 2011 15:39
Qunit + Sinon
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>QUnit/Sinon.JS</title>
<link rel="stylesheet" href="vendor/qunit/qunit.css" type="text/css" media="screen">
</head>
<body>
<h1 id="qunit-header">QUnit/Sinon.JS Test</h1>
<h2 id="qunit-banner"></h2>
@commuterjoy
commuterjoy / gist:1209805
Created September 11, 2011 16:47
Rewrite the link of an RSS feed to that of the first anchor in the description
include('Zend/Feed/Rss.php');
include('Zend/Dom/Query.php');
$feed = new Zend_Feed_Rss('http://example.com/rss');
foreach ($feed as $item) {
# where feed contains an <a href="" />, use that as the RSS <link> value
$dom = new Zend_Dom_Query(html_entity_decode($item->description()));
$anchor = $dom->query('a');
@commuterjoy
commuterjoy / gist:1247421
Created September 28, 2011 09:03
polyfill the String.trim function for old Safari's etc.
if ("undefined" === typeof String.trim) {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
}
@commuterjoy
commuterjoy / gist:1251870
Created September 29, 2011 20:40
n-way comparison of string parts using Array.every
/**
* Splits a string on a given separator and compares each part
* @returns {Boolean} True is all parts are equal, false if not
*/
String.prototype.equate = function (separator) {
return this.split(separator).every(function(element, index, array){
return (element === array[0]);
});
}
@commuterjoy
commuterjoy / gist:1284070
Created October 13, 2011 12:02
swap a port number when a cucumber scenario is tagged with varnish
# Cucumber has a nice feature where it can wrap code _around_ a
# scenario. In my case I have a Varnish cache running on port 6081
# and an plain apache on port 80 and various tests that rely
# on both services. So this way I can temporarily monkey patch the
# Capybara host if I tag any feature with '@varnish' and have the
# http traffic hit the cache.
Around('@varnish') do |scenario, block|
default_host = Capybara.default_host
Capybara.default_host = Capybara.default_host.gsub(/(:\d+)$/, ':6081')
@commuterjoy
commuterjoy / gist:1307626
Created October 23, 2011 17:40
Converting Gherkin to JSON in Ruby
# This took me an hour or so to figure out as the documentation is a bit
# sparse, but the gherkin gem ships with a json formatter
require 'rubygems'
require 'gherkin'
require 'gherkin/formatter/json_formatter'
require 'gherkin/parser/parser'
require 'json'
@commuterjoy
commuterjoy / gist:1331565
Created November 1, 2011 19:08
yum list installed 1/11/2011
Installed Packages
GConf2.x86_64 2.14.0-9.el5 installed
GraphicsMagick.x86_64 1.3.12-2.bbc installed
MAKEDEV.x86_64 3.23-1.2 installed
NetworkManager.x86_64 1:0.7.0-13.el5 installed
NetworkManager-glib.x86_64 1:0.7.0-13.el5 installed
ORBit2.x86_64 2.14.3-5.el5 installed
SysVinit.x86_64 2.86-17.el5 installed
acl.x86_64 2.2.39-6.el5 installed
acpid.x86_64 1.0.4-9.el5_4.2 installed
@commuterjoy
commuterjoy / gist:1347412
Created November 8, 2011 10:12
Dropbox
# Add this to /etc/profile and source it, then you can type `drop [file|folder]` to transfer
# files to some remote host, or 'drops' to list all drops, or 'undrop [file]
export DROPHOST=example.com
export DROPUSER=username
export DROPPATH=/home/path/to/folder
export DROPWEBROOT=/drop
# drop a file or folder & copy the resulting url to your clipboard
function drop() {
@commuterjoy
commuterjoy / foo.xml
Created November 17, 2011 14:22
xsltproc foo.xsl foo.xml
<ol>
<li>
<a href="http://news.bbc.co.uk/democracylive/hi/northern_ireland/newsid_9583000/9583548.stm?t=86s">00:01:28</a>you find out who the <strong>some term</strong> the US and the</li>
</ol>
@commuterjoy
commuterjoy / gist:1382238
Created November 21, 2011 10:23
Wally Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)