Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Iversen civersen

  • Melbourne
View GitHub Profile
@civersen
civersen / 0_reuse_code.js
Created May 21, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@civersen
civersen / CompressJS.js
Last active Aug 29, 2015
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.
View CompressJS.js
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 / String.format.js
Last active Dec 22, 2015
String format implementation with padding.
View String.format.js
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) {
You can’t perform that action at this time.