Skip to content

Instantly share code, notes, and snippets.

@josher19
josher19 / incrpad.py
Created October 21, 2011 22:35
python script to go from '000' to '999'
import readline, rlcompleter
readline.parse_and_bind("tab: complete")
def zeropad(n,zeros=3):
"Pad number n with zeros. Example: zeropad(7,3) == '007'"
nstr = str(n)
while len(nstr) < zeros:
nstr = "0" + nstr
return nstr
/**
* Array.prototype.map Polyfill
*/
Array.prototype.map = function(fun, thisp) {
"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
@josher19
josher19 / gist:779245
Created January 14, 2011 06:01
working-invoice.yaml
invoice: 34843
date: "2001-01-23"
billTo: &id001
given : Chris
family : Dumars
address:
lines: [ "458 Walkman Dr.", "Suite #292"]
city : Royal Oak
state : MI
postal : 48046
@josher19
josher19 / gist:749343
Created December 21, 2010 01:34
User Story Mapping
# Three levels #
Personal : Organizational
---------------------------
Goals : business objectives
Tasks : business processes
Tools/Features : employees, vendors & systems
# Business Goals #
var proplist = _.keys(_);
var undef
proplist.push(undef);
proplist.push(null);
proplist = proplist.concat(proplist);
// proplist.push(proplist);
_.isNewFunction = function (obj) { return typeof obj === 'function' }
_.isA = function isA(o,c) {return o==null ? o===c : (o.constructor===c || ( _.isFunction(c) && o instanceof c));}
@josher19
josher19 / gweather_xml.js
Created February 1, 2010 01:56
xml to javascript
// Get leaf data
// or could iterate over leaf.attributes
function show(leaf,ind) { return [leaf.tagName, leaf.getAttribute ? leaf.getAttribute("data") : leaf.textContent]; }
function grab(node,indented) {
var ind=indented||"";
return Array.prototype.slice.call(node).map( function(item) {
var others = "";
if (item.childNodes && item.childNodes.length > 0) others = grab(item.childNodes, ind + " ");
return ind + show(item).join(": ") +"\n"+ others
/** Adding underscores template to the String object */
// Source: http://github.com/documentcloud/underscore
var _ = self._ || {};
// JavaScript templating a-la ERB, pilfered from John Resig's
// "Secrets of the JavaScript Ninja", page 83.
// Single-quote fix from Rick Strahl's version.
_.template = function(str, data) {
/**
* isType return true if obj is of class klass or a superclass of klass (such as Object).
* If type is a Function, will match if obj instanceof type (includes subclasses).
* If type is a String, will match if typeof(obj) === type or obj.constructor.name === type,
* so if tom is a Horse, which is a subclass of Animal,
* then isClass(tom, "Animal") is false but isClass(tom, Animal) is true.
* @Param {obj} Object to test
* @Param {type} Function or String with name or constructor of object.
* @Return {boolean} true if obj is of given type, using typeof, instanceof, or obj.constructor.
*/
Discussion about the "truthfulness" of Objects of the Boolean class.
Given some Javascript code of:
var bool_examples = [
true == new Boolean(true),
true === new Boolean(true),
false == new Boolean(false),
false === new Boolean(false),
! 0,
// Boolean Quiz
var bool_examples = [
true == new Boolean(true),
true === new Boolean(true),
false == new Boolean(false),
false === new Boolean(false),
! 0,
! new Boolean(false),
! "",