Skip to content

Instantly share code, notes, and snippets.

View heapwolf's full-sized avatar
🕷️
Vault of the Black Spiders

heapwolf heapwolf

🕷️
Vault of the Black Spiders
View GitHub Profile
function queryString2JSON() {
var query = {}
unescape(window.location.search).replace(/[^&\?]+/g, function(a, b) {
var c = a.split("=");
query[c[0]] = c[1];
});
return query;
}
$(".content").weld(
{
some : "data",
user : "tmpvar"
},
{
map : function(key, value) {
$(this).attr("foo", value); // key is null if it is an array.
},
method : "append" // defines what action the insert method should do.
/*! Cross-browser-compatible setZeroTimeout
*
* I took the original setZeroTimeout and made it cross-browser-compatible, using setTimeout(fn, 0) as a fallback in case postMessage is not supported.
* Mathias Bynens <http://mathiasbynens.be/>
* See <http://mathiasbynens.be/notes/settimeout-onload>
*
* Copyright statement below:
*
* See <http://dbaron.org/log/20100309-faster-timeouts>
* By L. David Baron <dbaron@dbaron.org>, 2010-03-07, 2010-03-09
@heapwolf
heapwolf / director usage
Created November 29, 2011 21:34 — forked from anonymous/director usage
figuring out how to use director (flatiron js)
var routes = {
'/track' : {
on: function() {
alert('a');
},
'/:id' : {
on: function(id){
alert('b');
}
}
@heapwolf
heapwolf / abs.js
Created January 2, 2012 04:21
Math.abs() performance
var test = require('testling');
test('Math.abs performance', function (t) {
var t0 = new Date;
for (var i = 0; i < 100 * 1000; i++) Math.abs(i - 50 * 1000)
t.log(new Date - t0);
t.end();
});
@heapwolf
heapwolf / jsonparse.js
Created February 13, 2012 23:27 — forked from creationix/jsonparse.js
Sax-only version of jsonparse
// Named constants with unique integer values
var C = {};
// Tokenizer States
var START = C.START = 0x11;
var TRUE1 = C.TRUE1 = 0x21;
var TRUE2 = C.TRUE2 = 0x22;
var TRUE3 = C.TRUE3 = 0x23;
var FALSE1 = C.FALSE1 = 0x31;
var FALSE2 = C.FALSE2 = 0x32;
var FALSE3 = C.FALSE3 = 0x33;
var util = require('util'),
Stream = require('stream');
var FastJSONStream = exports.FastJSONStream = function (options) {
this.bufferSize = options.bufferSize;
this._buffer = new Buffer(this.bufferSize);
};
util.inherits(FastJSONStream, Stream);
FastJSONStream.prototype.write = function (chunk) {
@heapwolf
heapwolf / gist:1856712
Created February 18, 2012 01:17
Plates
data = [ { _id: 'first',
name: 'My first post',
title: 'first',
content: 'This is my first post',
ctime: 1329501275682,
mtime: 1329501275682,
resource: 'Post',
_rev: '1-c045632b8020ed83d84210f2bfe8eac5' },
{ _id: 'second',
name: 'My second post',
@heapwolf
heapwolf / gist:3086430
Created July 10, 2012 21:47 — forked from rmurphey/gist:3086328
What's wrong with Netmag's "Optimize your JavaScript" post

What's wrong with Netmag's "Optimize your JavaScript" post

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some people who actually know what they're talking about (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Things that are just plain wrong

  • Calling array.push() five times in a row will never be a "performance improvement." The author has clearly co
@heapwolf
heapwolf / install-nodejs.sh
Created August 8, 2012 18:43 — forked from TooTallNate/install-nodejs.sh
Simple Node.js installation script using the precompiled binary tarballs
#!/bin/sh
VERSION=0.8.6
PLATFORM=darwin
ARCH=x64
PREFIX="$HOME/node-v$VERSION-$PLATFORM-$ARCH"
mkdir -p "$PREFIX" && \
curl http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz \
| tar xzvf - --strip-components=1 -C "$PREFIX"