Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Jeffrey (JJ) chjj

View GitHub Profile
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;
View good_randomness.js
// small script i wrote to get strong randomness in node
// putting it here so i dont lose it
// copyright (c) 2011, christopher jeffrey, mit license, etc.
// example output:
// urandom: 0.17843490773309834
// Math.random: 0.7067500613629818
// random: 0.3154916005012327
@chjj
chjj / .vimrc
Last active Sep 27, 2015
vimrc, so i don't lose it
View .vimrc
"
" ~/.vimrc
" https://gist.github.com/chjj/1257074
"
" === options ==================================================================
set nocompatible " vim settings
set nomodeline " security measure
@chjj
chjj / archive
Created Oct 8, 2011
script for people who dont like file managers
View archive
#!/bin/sh
# easy manipulation of archives for people
# who don't like archivers or file managers
# copyright (c) 2011, christopher jeffrey
LIST=
EXTRACT=
CREATE=
ENCRYPT=
View frame_extents.c
static void
get_frame_extents(Display *dpy, Window w, int *top) {
long *extents;
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *data = NULL;
int result;
*top = 0;
@chjj
chjj / node_functions.sh
Created Nov 2, 2011
node functions for .bashrc
View node_functions.sh
# $ echo "console.log('hello world')" | runjs
runjs() {
cat | xargs -0 node -e
}
# usage:
# $ echo "hello world" | jsrx "/h\w+/g" "hi"
jsrx() {
local str=$(cat | sed "s/\\\/\\\\\\\/g" \
| sed "s/'/\\\'/g" | sed ':a;N;$!ba;s/\r\n\|\n/\\n/g')
@chjj
chjj / pocketfm.js
Created Dec 17, 2011
pocket-sized file manager/sharing so i dont have to start up samba
View pocketfm.js
/**
* pocketfm
* Pocket-sized File Manager
* Uses plain html to be as simple as possible
* Code is messy, needs revision and needs
* native mv, rm, cp implementations
* Copyright (c) 2011, Christopher Jeffrey (MIT License)
*/
process.title = 'pocketfm';
You can’t perform that action at this time.