Skip to content

Instantly share code, notes, and snippets.

@mzabriskie
mzabriskie / getElementLegacy.js
Last active August 29, 2015 13:56
Legacy get element code circa 2001
function getElement(id) {
var el = null;
if (document.getElementById) {
el = document.getElementById(id);
}
else if (document.all) {
el = document.all[id];
}
else if (document.layers) {
el = document.layers[id];
@mzabriskie
mzabriskie / README.md
Last active October 17, 2025 04:27
Check git status of multiple repos

If you're like me you have a dir like ~/Workspace/Github where all your git repos live. I often find myself making a change in a repo, getting side tracked and ending up in another repo, or off doing something else all together. After a while I end up with several repos with modifications. This script helps me pick up where I left off by checking the status of all my repos, instead of having to check each one individually.

Usage:

git-status [directory]

This will run git status on each repo under the directory specified. If called with no directory provided it will default to the current directory.

function duration(timeInMillis) {
var intervals = {
'h': 3600000,
'm': 60000,
's': 1000,
'ms': 1
},
sb = '';
for (var k in intervals) {
/**
* Creates an array containing a range of values.
*
* <p>
* Examples:
*
* <code>
* // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
* Array.range(1, 10);
*
@mzabriskie
mzabriskie / random-token.js
Created September 9, 2013 22:39
Base 36 random token
Math.floor(Math.random() * Math.pow(2, 64)).toString(36);
@mzabriskie
mzabriskie / EvalCssText.js
Created April 3, 2013 20:11
Evaluate CSS text to add it to the page.
// Evaluate CSS text
// Can be used to add CSS to the page from XHR response, or localStorage, etc.
function evalCssText(text) {
// When Base64 encoding the data URI CSS urls, such as background images will not load if they aren't fully qualified URLs
// NOTE: Change this to whatever matches your path. All my images are loaded from a /static directory.
text = text.replace(/\/static\//gim, window.location.protocol + '//' + window.location.host + '/static/');
var href = 'data:text/css;base64,' + Base64.encode(text);
var node = new Element('link');
node.set('type', 'text/css');
@mzabriskie
mzabriskie / Base64.js
Created April 3, 2013 20:02
Base64 encode/decode for JavaScript
// http://www.webtoolkit.info/javascript-base64.html
(function () {
var KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
// private method for UTF-8 encoding
function _utf8_encode(string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {