Skip to content

Instantly share code, notes, and snippets.

View tleen's full-sized avatar
🚀
Making things.

Tom Leen tleen

🚀
Making things.
View GitHub Profile
@tleen
tleen / gist:4742207
Created February 8, 2013 21:48
sample nginx to node
server{
listen *:8080;
server_name myproject.com;
location / {
root /usr/share/nginx/myproject/static;
try_files $uri @app;
}
@tleen
tleen / gist:5105182
Created March 7, 2013 02:45
Node: Recurse through a directory and upload files to s3, using async, knox, underscore
// recurse through tempdir and upload all files
(function uploadFile(filepath, callback){
fs.stat(filepath, function(err, stats){
if(err) return callback(err);
else{
if(stats.isDirectory()){
fs.readdir(filepath, function(err, files){
var files = _.map(files, function(file){ return path.join(filepath, file) });
async.each(files, uploadFile, callback);
});
@tleen
tleen / gist:5109955
Created March 7, 2013 17:30
Format a Javascript Date to RFC-822 datetime using moment.js
var rfc822Date = moment(yourDate).format('ddd, DD MMM YYYY HH:mm:ss ZZ')
@tleen
tleen / gist:5110817
Created March 7, 2013 19:08
Format a Javascript Date to HTML5 time element datetime using moment.js
var html5datetime = moment(yourDate).format('YYYY-MM-DDTHH:mm:ssZ')
@tleen
tleen / gist:6136736
Created August 2, 2013 01:01
Extract main portion of hostname from url in node javascript without regex
url.parse('http://some.long.hostname.here.com/andpages.html').hostname.split('.').reverse().slice(0,2).reverse().join('.');
@tleen
tleen / gist:6146417
Created August 3, 2013 13:16
Using html-minifier in node
Not totally obvious from the documentation, but to use html-minifier in node, you need to import the .minify function
! var minify = require('html-minifier');
var minify = require('html-minifier').minify,
Did not see a node usage pattern out there.
@tleen
tleen / gist:6184436
Created August 8, 2013 13:10
Narrowing a region in emacs

Handy emacs command which will limit your operations (and visibility) to a selected region. Good for regional search/replace and the like.

  1. Mark your region
  2. C-x n n / narrow-to-region
  3. Do what you are going to do
  4. C-x n w / widen
@tleen
tleen / gist:6276174
Created August 20, 2013 01:36
Using the moment.js time duration shorthand to get number of seconds from a string. Say the inputString is '3y' or '5M' or '2d', this would give you the respective time from now in seconds.
// I don't love this but its a quick/dirty create of cache duration using moment's nice date add format
// parse cache duration as [integer][unit] via http://momentjs.com/docs/#/manipulating/add/ shorthand
var durations = /^([\d]+)([\w]+)/.exec(inputString);
var invalidateSeconds = moment(0).add(durations[2],durations[1]).unix();
@tleen
tleen / gist:6299431
Created August 21, 2013 20:00
Javascript array of state names
['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']
@tleen
tleen / gist:6382987
Created August 29, 2013 20:27
Test credit card numbers (via authorize.net)
American Express Test Card 370000000000002
Discover Test Card 6011000000000012
Visa Test Card 4007000000027
Second Visa Test Card 4012888818888
JCB 3088000000000017
Diners Club/ Carte Blanche 38000000000006