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 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);
@xk
xk / lazyEventLoop.js
Created Dec 14, 2010
lazyEventLoop.js
View lazyEventLoop.js
setTimeout(function () {
t= Date.now()-t;
STOP= 1;
console.log(["ctr: ",ctr, ", t:", t, "ms -> ", (ctr/t).toFixed(2), "KHz"].join(''));
}, 2e3);
var ctr= 0;
var STOP= 0;
var t= Date.now()+ 2;
while (t > Date.now()) ; //get in sync with clock
@xk
xk / walkADir.js
Created Dec 15, 2010
walkADir.js
View walkADir.js
// 2010-12-15 jorge@jorgechamorro.com
// Uses 2 threads
function walk (file, cb) {
var fs = require('fs');
var e= {path:file, q:[]};
var q= [e];
begin();
function begin () {
@xk
xk / debugger.js
Created Dec 18, 2010
debugger.js
View debugger.js
// 2010-12-16 jorge@jorgechamorro.com
// loopFreq.js displays event loop tick period in ms and KHz
// with debugger; slows down to a crawl !
var k_ms= 1e3;
setTimeout(function display () {
t= Date.now()-t;
console.log(["ctr: ",ctr, ", t:", t, "ms -> ", (ctr/t).toFixed(2), "KHz"].join(''));
setTimeout(display, k_ms);
@xk
xk / wowAndFlutter.js
Created Dec 31, 2010
wowAndFlutter.js
View wowAndFlutter.js
// 2010-12-31 jorge@jorgechamorro.com
// JavaScript ms clock's wow and flutter
var kSample= 1e3;
var res= new Array(kSample);
var ctr;
var st= Date.now()+ 2; //start time
while (Date.now() < st) ; //get in sync with ms clock
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 takePhoto.js
(function () {
function photoOK (imageURI) {
console.log("**** photoOK");
console.log(imageURI);
}
function photoErr (mesage) {
console.log("**** photoErr");
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 test.js
function LinkedList() {
this._length = 0;
this._head = null;
this._tail = null;
}
LinkedList.prototype = {
add: function (data){
var node = { data: data, next: null};
if (this._length == 0) {
@xk
xk / rotate.js
Created Mar 4, 2011
phonegap:rotate.js
View rotate.js
<!DOCTYPE html>
<html>
<head>
<!-- Change this if you want to allow scaling -->
<meta name="viewport" content="width=default-width; user-scalable=no">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>gira</title>
You can’t perform that action at this time.