Skip to content

Instantly share code, notes, and snippets.

Christopher Jeffrey (JJ) chjj

Block or report user

Report or block chjj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View lite.txt
[obj] [structure] [property] [value]
test_article none title A Test Article
test_article none content Hello world!
test_article tags 0 misc
test_article tags 1 etc
test_article comments.0 poster_name AvgJoe
test_article comments.0 content This article is amazing
test_article comments.1 poster_name SuperNerd
test_article comments.1 content No it's not!
another_article none title Another Article
@chjj
chjj / loop-bench.js
Created May 1, 2011
loop benchmarks
View loop-bench.js
var a = [];
for (var i = 0; i < 100000; i++) a.push('a');
var o = {};
for (var i = 0; i < 100000; i++) o['key_' + i] = 'a';
(function() {
var s = Date.now();
var i = a.length;
while (i--) {
View joinvconcat.js
(function() {
var start = Date.now();
var i = 1000000;
while (i--) {
var str = '';
str += 'a';
str += 'a';
str += 'a';
str += 'a';
str += 'a';
View calleebench.js
var times = 15000;
(function() {
var i = 0, start = Date.now();
(function() {
if (++i < times) arguments.callee.call();
})();
console.log('callee', Date.now() - start);
})();
View simple_request.js
var http = require('http')
, parse = require('url').parse
, StringDecoder = require('string_decoder').StringDecoder;
var LIMIT = 10 * 1024;
var request = function(url, body, func) {
if (typeof url !== 'object') {
url = parse(url);
}
@chjj
chjj / base64fix.js
Created Jun 15, 2011
base64 cipher fix
View base64fix.js
// a shim to fix base64 cipher output, untested
var Cipher = require('crypto').Cipher;
var update = Cipher.prototype.update,
final = Cipher.prototype.final;
Cipher.prototype.update = function(data, input, output) {
if (output === 'base64') {
data = update.call(this, data, input, 'binary');
return new Buffer(data, 'binary').toString('base64');
View fastuint32.js
// ignore the shims
// the original (slow) version
var Buffer1 = (function() {
var assert = {};
var fail = function() { throw new Error('assertion failed'); };
var Buffer = function() { this.length = 100; };
Buffer.prototype.writeUInt32 = function(value, offset, endian) {
var buffer = this;
@chjj
chjj / slice_args.js
Created Aug 9, 2011
slice arguments
View slice_args.js
(function() {
var bench = function(func, t) {
var start = new Date()
, i = t || 100000;
while (i--) func(1, 2, 3);
console.log('%s: %sms', func.name, new Date() - start);
};
var slice = Array.prototype.slice;
bench(function _slice() {
@chjj
chjj / coffeescript.poem
Created Aug 15, 2011
a poem about coffeescript
View coffeescript.poem
a poem about coffeescript in the style of the lord of the rings:
one does not simply walk into coffeescript
its syntax is guarded by more than just ruby devs
and the significant whitespace is ever present
it is a wasteland barren of curly braces
- riddled with class syntax, postfix conditionals, and operator aliases
the very code you write, is a poisonous fume
not with 10,000 men who knew javascript could you do this
View two_paragraphs.js
var fs = require('fs')
, marked = require('marked');
var text = fs.readFileSync(__dirname + '/test.md', 'utf8');
var two = function(str) {
var tokens = marked.lexer(str)
, paragraphs = 0
, i = 0
, token;
You can’t perform that action at this time.