This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//plistread.js, 2012-12-30 [email protected] | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node timers.js | |
setInterval(ƒ,1) -> (µs) : | |
[ 1477, | |
1172, | |
1071, | |
1084, | |
1122, | |
1145, | |
1064, | |
1062, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 20111028 [email protected] | |
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |