Skip to content

Instantly share code, notes, and snippets.

View jamiehs's full-sized avatar

Jamie Hamel‑Smith jamiehs

View GitHub Profile
@jamiehs
jamiehs / pad-with-zero.js
Created April 9, 2013 20:47
Quick and dirty method for adding a leading zero to a number in JavaScript
// In this example, myNumber could be 0-99
myNumber = 7;
paddedNumber = ('0' + myNumber).slice(-2);
@jamiehs
jamiehs / navigate-slidedeck.html
Created April 10, 2013 21:41
Creating links that will allow you to navigate your SlideDeck from other parts of the page. You can use the API functions described here: http://developers.slidedeck.com/actions/
<!-- If your SlideDeck is just on the page (non-iFrame) -->
<a href="#" onclick="jQuery('.slidedeck-1644').slidedeck().next();return false;">Next</a>
<!-- If your SlideDeck is responsive (iFrame) -->
<a href="#" onclick="jQuery('div.sd2-ress-wrapper iframe').contents().find('.slidedeck-1644').slidedeck().next();return false;">Next</a>
@jamiehs
jamiehs / youtube-sizes
Created April 18, 2013 20:11
YouTube thumbnail sizes
# Large-ish (480x360) with letterboxing
http://img.youtube.com/vi/9bZkp7q19f0/0.jpg
# Tiny (120x90) letterboxed - Early in video
http://img.youtube.com/vi/9bZkp7q19f0/1.jpg
# Tiny (120x90) letterboxed - Midway through video
http://img.youtube.com/vi/9bZkp7q19f0/2.jpg
# Tiny (120x90) letterboxed - Late in video
@jamiehs
jamiehs / update_query_string.js
Created April 19, 2013 21:13
A quick function to append/update values to the query string of a URL
// http://stackoverflow.com/a/6021027
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
return uri + separator + key + "=" + value;
}
}
@jamiehs
jamiehs / gist:5489267
Created April 30, 2013 14:57
Facebook "RSS" feed URL. I'm actually not sure if this is supported.
http://www.facebook.com/feeds/page.php?format=json&id=166106021034
@jamiehs
jamiehs / git-archive.sh
Created May 10, 2013 17:58
Export (copy) to a Zip file of your Git repository without the .git tracking information
git archive --format zip --output ~/Desktop/project-name.zip master
@jamiehs
jamiehs / screenshot.js
Created June 11, 2013 14:55
Simple screenshot tool using Phantom JS http://phantomjs.org/
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
page.viewportSize = { width: 1200, height: 1200 };
page.clipRect = { top: 0, left: 0, width: 1200, height: 1200 };
page.open('http://jamie3d.com/', function () {
page.render('output.png');
phantom.exit();
});
@jamiehs
jamiehs / onDOMContentLoaded-01.js
Created June 13, 2013 17:37 — forked from firedfox/onDOMContentLoaded.js
PhantomJS DOM Loaded
const PHANTOM_FUNCTION_PREFIX = '/* PHANTOM_FUNCTION */';
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
if (msg.indexOf(PHANTOM_FUNCTION_PREFIX) === 0) {
eval('(' + msg + ')()');
} else {
console.log(msg);
}
@jamiehs
jamiehs / gist:5775701
Created June 13, 2013 17:40
Simple PhantomJS example for grabbing a HAR file
bin/phantomjs examples/netsniff.js "http://www.amazon.com" > amazon.com.har
@jamiehs
jamiehs / run_url_list.sh
Created July 2, 2013 17:47
Looping through a list of URLs in a text file and optionally stripping the schema.
#!/bin/bash
for URL in $(cut -d, -f2 < url_list.txt)
do
URL=$(sed -e 's/^http\(\|s\):\/\///g' <<< "$URL" )
echo $URL
done