Skip to content

Instantly share code, notes, and snippets.

View mcotton's full-sized avatar

Mark Cotton mcotton

View GitHub Profile
utils.each = function(arr, cb) {
for (var i = 0, len = arr.length; i < len; ++i) {
cb.length > 1 ?
cb(i, arr[i]) :
cb(arr[i])
}
}
@mcotton
mcotton / gist:969679
Created May 12, 2011 23:33
everyone's new favorite javascript pattern
(function(window,document,undefined) {
})(this,this.document);
@mcotton
mcotton / slugify
Created July 10, 2011 05:14
JavaScript slugify
function slugify(text) {
text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
text = text.replace(/-/gi, "_");
text = text.replace(/\s/gi, "-");
return text;
}
@mcotton
mcotton / about.md
Created August 10, 2011 03:08 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@mcotton
mcotton / routes.js
Created October 15, 2011 04:57 — forked from tj/routes.js
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@mcotton
mcotton / bookmarklet.js
Created November 2, 2011 00:11
auto-login bookmarklet
// Saved URL should look like this:
// javascript:<function>
// replace <function> with the following text
(function(){
// Grab the username and password input fields
user = document.getElementById('txtUserName');
pass = document.getElementById('txtPassword');
// Grab the submit button, oddly named 'punch'
@mcotton
mcotton / gist:1595385
Created January 11, 2012 16:10
Make a simple python webserver in local directory
alias web = 'python -m SimpleHTTPServer'
@mcotton
mcotton / gist:2631131
Created May 7, 2012 22:43
Forward ssh ports for couchdb

This is handy for seeing the couchdb futon interface without making it publicly available. It still will only accept connections from localhost.

Syntax:
ssh -L <local port>:porxy:<remote port> <user>@<remote host>

Example for CouchDB:

ssh -L 5984:localhost:5984 [email protected]

@mcotton
mcotton / gist:2885834
Created June 7, 2012 01:00
Using crypto in Node.js
var crypto = require('crypto')
, text = 'I love cupcakes'
, salt = 'abcdeg'
, hash
hash = crypto.createHmac('sha1', salt).update(text).digest('hex')
@mcotton
mcotton / gist:3165763
Created July 23, 2012 19:46
Setting Django on OSX
> sudo curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
> sudo pip install Django
> git clone <project>
> cd <project>
> cp local_settings_test.py local_settings.py
> export DJANGO_SETTINGS_MODULE=qliqserver.settings
> mkdir logs
> pip install south
> pip install django-piston
>