Skip to content

Instantly share code, notes, and snippets.

@kavanagh
kavanagh / AppendStylesheet.js
Created April 16, 2012 15:24
Append CSS Stylesheet to the head using jQuery
$.appendStylesheet = function appendStylesheet(url, callback) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = url;
link.rel = "stylesheet";
link.type = "text/css";
if (callback && $.isFunction(callback)) {
@kavanagh
kavanagh / namespace.js
Created June 2, 2012 11:00
Simple namespace function
(function(global){
global.namespace = function namespace(name, context) {
var names = name.split('.'), name;
context = context || global;
while (name = names.shift()) {
context = context[name] = context[name] || new function(){};
}
return context;
};
@kavanagh
kavanagh / json-spider.js
Created October 2, 2012 01:19
A very simple node script to spider JSON web services.
var request = require( 'request' ),
fs = require( 'fs' ),
util = require( 'util' );
var todo = process.argv.splice( 2 ),
processor = {
'/rest/path/foo/bar': {
'response.result.cid': function( str ) {
@kavanagh
kavanagh / nodejs.sh
Created October 31, 2012 18:55 — forked from crcastle/nodejs.sh
Node.js tartup script for AWS EC2 Linux box
#!/bin/bash
# nodejs - Startup script for node.js server
# chkconfig: 35 85 15
# description: node is an event-based web server.
# processname: node
# server: /path/to/your/node/file.js
# pidfile: /var/run/nodejs.pid
#
@kavanagh
kavanagh / wrap-paragraphs.js
Created April 24, 2013 15:14
Wrap an array of strings with p tags
var paragraphs = ['paragraph 1', 'paragraph 1'];
var html = '<p>' + paragraphs.join('</p><p>') + '</p>';
@kavanagh
kavanagh / example.js
Created May 14, 2013 08:41
Very simple topic subscription.
var a = topic();
a.add(function(){
console.log('a', arguments);
});
a.fire('message for a'); // should be "a", ["message for a"]
// named topic
var b = topic('b');
@kavanagh
kavanagh / job.sh
Created June 20, 2013 16:43
function to quickly make an interactive job
# 's' below refers to symlinked sublime
# all refers to 'testem' remove this if you dont need it
function job() {
if [[ -z "$1" ]]; then
echo "You must specify a project name!"
return;
fi
mkdir $1 && cd $1 && yo ig-job && s . && s ./app/scripts/main.js && s ./app/scripts/config.js && \
osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "cd '$PWD' && testem" in selected tab of the front window' && \
grunt server;
@kavanagh
kavanagh / split-paragraphs.js
Created June 24, 2013 12:18
Split a string into paragraphs
var body = '<p>' + (row.body || '').split(/[\r\n\t]+/gm).join('</p><p>') + '</p>';
@kavanagh
kavanagh / map.geojson
Created August 28, 2013 16:32
via:geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kavanagh
kavanagh / map.geojson
Created August 28, 2013 16:35
via:geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.