Skip to content

Instantly share code, notes, and snippets.

View bcherry's full-sized avatar

Ben Cherry bcherry

View GitHub Profile
#!/bin/sh
if [ ! -n "$1" ]; then
echo "Usage: $0 'debug' | 'release'"
exit 0
fi
MODE=$1
OUT_DIR=./out-$MODE
DEBUG="false"
if [ "$MODE" == "debug" ]; then
Also not that `a + "a"` is "3a" (and "a3" the other way around)
I'm pretty certain it's because `typeof a === "object"` and `typeof "a" === "string"`.
The `+` operator calls `toPrimitive` on each operand, but since the literal strings
are already primitives, no further action is taken. It's only when they are
objects that it delegates to `[[DefaultValue]]` which ends up calling its `valueOf` method.
@bcherry
bcherry / lazyload-loadrunner.js
Created September 13, 2011 18:55
CSS plugin for loadunner (based on lazyload)
// LazyLoad, modified to be a loadrunner module
provide(function(exports) {
/*jslint browser: true, eqeqeq: true, bitwise: true, newcap: true, immed: true, regexp: false */
/**
LazyLoad makes it easy and painless to lazily load one or more external
JavaScript or CSS files on demand either during or after the rendering of a web
page.
Supported browsers include Firefox 2+, IE6+, Safari 3+ (including Mobile
@bcherry
bcherry / grep.js
Created July 6, 2011 21:47
search javascript objects by name
var grep = function(o, n) {
var s = "";
if (typeof o === "string") {
n = o;
o = window;
s = "window"
}
function actualGrep(o, n, s) {
Object.keys(o).forEach(function(k) {
@bcherry
bcherry / snowflakeadapter.js
Created October 21, 2010 00:16
adaptive function for the new string IDs for Twitter API objects (Snowflake)
// adaptive function for the new string IDs for Twitter API objects (Snowflake)
function useStringIdentifier(obj, property) {
var property_str = property + "_str";
if (!obj) {
return;
}
if (obj[property_str]) {
obj[property] = obj[property_str].toString();
delete obj[property_str];
/*
natcompare.js -- Perform 'natural order' comparisons of strings in JavaScript.
Copyright (C) 2005 by SCK-CEN (Belgian Nucleair Research Centre)
Written by Kristof Coomans <kristof[dot]coomans[at]sckcen[dot]be>
Based on the Java version by Pierre-Luc Paour, of which this is more or less a straight conversion.
Copyright (C) 2003 by Pierre-Luc Paour <[email protected]>
The Java version was based on the C version by Martin Pool.
Copyright (C) 2000 by Martin Pool <[email protected]>
class JsObject(object):
def __init__(self, *args, **kwargs):
for arg in args:
self.__dict__.update(arg)
self.__dict__.update(kwargs)
def __getitem__(self, name):
return self.__dict__.get(name, None)
var foo, bar;
foo = function () {
bar();
}
bar = function () {
foo();
}
// Simple arithemetic parser.
// Follows order of operations, only supports positive integers
// Only operators are +, -, *, and /. Does not support grouping with ()
var calc = (function () {
var calc,
sum,
negasum,
product,
dividend;
var performance = (function () {
var my = {};
// Wrap a function body in this to return a copy that instruments itself
// If you want this to be useful, you should give your profiled function a name,
// otherwise it will be identified as "", which is less than useful.
my.profile = function (func) {
return function () {
var start = new Date().getTime(),
time,