Skip to content

Instantly share code, notes, and snippets.

xk xk

Block or report user

Report or block xk

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 plistread.js
//plistread.js, 2012-12-30 jorge@jorgechamorro.com
var plist= require('plist');
var shell= require('child_process').exec;
var puts= console.log;
//process.argv[0] -> "node"
//process.argv[1] -> "plistread.js"
//process.argv[2] -> inputFile
//process.argv[3..n] -> property list keys
@xk
xk / Output on OS X Snow Leopard
Created Nov 4, 2012 — forked from bigeasy/Output on Fedora 16
Node.js Millisecond Timeout
View Output on OS X Snow Leopard
$ node timers.js
setInterval(ƒ,1) -> (µs) :
[ 1477,
1172,
1071,
1084,
1122,
1145,
1064,
1062,
@xk
xk / fib.js
Created Mar 13, 2012 — forked from ry/fib.js
a proper fibonacci server in node. with threads_a_gogo
View fib.js
var http = require('http')
var pool = require('threads_a_gogo').createPool(5).all.eval(fib);
function fib (n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
@xk
xk / SubArray.js
Created Oct 28, 2011 — forked from CrabDude/SubArray.js
Node.js Array subclass
View SubArray.js
// 20111028 jorge@jorgechamorro.com
// How to subclass Array
// In reply to https://gist.github.com/1100841/9c959db9314338a09c0f288c2c0ca5553816e400
function subArray () {
var nu= Array.apply(null, arguments);
nu.__proto__= subArray.prototype;
return nu;
}
@xk
xk / gist:991013
Created May 25, 2011 — forked from virtuo/gist:757317
Problem using crypto with base64 ouput format
View gist:991013
var crypto = require('crypto');
var key = "some keys are better than others";
var msg = "Attack Troy from within a wooden horse!";
var CYPHER = "aes256";
var test = function(msg) {
var cypher = crypto.createCipher(CYPHER, key);
var enc_msg = cypher.update(msg, "utf8", 'binary');
enc_msg += cypher.final('binary');
View expando-url.js
// testing the effect of using an ES5 Getter
// to get the parsedUrl on an object
var url = require("url")
function AutoParseUrl (u) {
this.url = u
}
Object.defineProperty(AutoParseUrl.prototype, "parsedUrl", {get:function () {
return url.parse(this.url)
View nodejs.js
var k= require('constants');
var fs = require('fs')
var b = new Buffer('AAAAAAAAAA');
fs.open('./f', k.O_WRONLY, 0666 , cb);
function cb (err, fd) {
fs.write(fd,b,0,10,10);
}
View snap-benchmark's pong implementation in node.js
function server (request, response) {
var uri = url.parse(request.url).pathname;
if(uri=='/pong') {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('PONG');
} else if ((match = uri.match(/^\/echo\/(.*)$/)) != null) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end(match[1]);
View walker.js
var fs = require("fs");
var util = require("util");
function walkSync(filename, cb) {
try {
var stat = fs.lstatSync(filename);
if(stat.isDirectory()) {
try {
if(cb(null, filename, stat)) {
var files = fs.readdirSync(filename);
You can’t perform that action at this time.