Skip to content

Instantly share code, notes, and snippets.

View civersen's full-sized avatar

Chris Iversen civersen

View GitHub Profile
@civersen
civersen / String.format.js
Last active December 22, 2015 21:09
String format implementation with padding.
String.prototype.format = String.prototype.f = function () {
var s = this;
for (var i = 0; i < arguments.length; i++) {
var m = s.match("\\{(" + i + ")(:.*?)?\\}", "gm");
if (m) {
if (m[2]) {
var x = m[2].substring(1);
if (x.search("^(.)\\1+$") > -1) {
var p = arguments[parseInt(m[1], 10)].toString();
while (p.length < x.length) {
@civersen
civersen / CompressJS.js
Last active August 29, 2015 13:56
A simple node.js script that monitors changes to javascript files in my development directory tree. Once a change occurs, the script creates a minified version using the Closure compiler.
var watch = require("watch");
var cc = require("closurecompiler");
var fs = require("fs");
watch.watchTree("/Users/chris/Dropbox/Development",{"ignoreDotFiles":true},function(f,cstat,pstat){
if(typeof(f)=="string" && f.toLowerCase().indexOf(".js")>1 && f.toLowerCase().indexOf(".min.")==-1){
if(cstat.nlink===1){
var fname = f.substring(f.lastIndexOf("/")+1);
var fpath = f.substr(0,f.lastIndexOf("/"));
@civersen
civersen / 0_reuse_code.js
Created May 21, 2014 22:47
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console