Skip to content

Instantly share code, notes, and snippets.

View bobrik's full-sized avatar

Ivan Babrou bobrik

View GitHub Profile
var fs = require("fs"),
file = fs.openSync("aa", "a+"),
bufs = {},
off = fs.fstatSync(file).size,
offs = {};
Object.keys(offs).forEach(function(o) {
offs[o] += off;
});
// for some reason from time to time it may output WTFs
// the way i run it: trace -f node buggy.js 2>&1 | grep '\(pwrite\|pread\|WTF\)'
// all reads come after writes
var fs = require("fs"),
file = fs.openSync("aa", "a+"),
bufs = {},
off = fs.fstatSync(file).size,
offs = {};
// /mnt/sdd/testfile is 4Gb file
// we read this file in 50 "threads"
// node.js results: ~1700 ops/s 7 Mb/s
// randomio results: ~290 ops/s 19 Mb/s
var fs = require("fs"),
fd = fs.openSync("/mnt/sdd/testfile", "r"),
i = 0,
l = 1204 * 64;
@bobrik
bobrik / rmatein
Created August 10, 2012 08:26
rmate as $PAGER shell variable (instead of less or whatever you use)
#!/bin/sh
# EDITOR should be set to rmate
# Usage: git diff | rmatein
# First arg may be set to file extension to hint rmate about file type
if [ -n "${1}" ]; then
POSTFIX=".${1}"
fi
(function() {
var shouldCall = false;
function first() {
console.log("first callback")
if (!shouldCall) {
shouldCall = true;
} else {
firstFinal();
}
@bobrik
bobrik / benchmark.js
Created July 11, 2012 10:12
lodash objectDifference implementation and benchmark code
(function(module) {
var Benchmark = require('../vendor/benchmark.js/benchmark.js'),
_ = require('../vendor/underscore/underscore.js'),
lodash = require('../lodash.js');
var numbers = [],
fourNumbers = [5, 25, 10, 30],
twoNumbers = [12, 21],
i;
@bobrik
bobrik / results.txt
Created July 11, 2012 10:06
new lodash difference method benchmark
# this is .difference method implementation performance test with different array sizes
# new method marked as "Objects"
# if you have arrays with 100s of elements - this is fast as hell compared with original .difference
# for 10k elements in arrays it is 200X faster (sic!)
# if you have more elements - this may your only hope: 100k is 350X faster
# so here are results from my apple macbook air late 2011 from latest master
=== testing simple ===
@bobrik
bobrik / lab1.asm
Created March 26, 2012 16:24
lab1 unknown subject
; calculate average of 4 numbers in registers 32-35 and write it to register 8
; ivan bobrov 2012
$MOD52
CSEG
ORG 0016h
MAIN:
@bobrik
bobrik / README.md
Created December 26, 2011 15:40
node.js incorrect net.Server.close behavior

This only happens on node.js 0.6.x, 0.4.x was fine. My node.js version is 0.6.6 (from homebrew, mac os x lion, but linux version is affected too). This may be not a but, maybe I just misread docs. Should it say that the server is closed when all connections destroyed?

What should you do to reproduce?

  1. In the first terminal tab:
node test-net.js
var twitter = require("ntwitter");
var ids = [284428360, 402607050, 14804140, 277829354, 184294175, 42931729, 66639438, 323618468,
315293821, 216261487, 64943419, 225771382, 397325621, 12067, 33495086, 222724928,
380661817, 28173504, 352674217, 183498392, 364038471, 161040541, 174672057, 129393710,
365406840, 29401562, 289940460, 298569251, 334544358, 284277979, 15953589, 324054488,
202629571, 71270409, 374156510, 14254332, 138206836, 19673977, 98792531, 386035729,
396548403, 160485521, 220606092, 42210677, 11029332, 184653870, 375251876, 322264568,
279906350, 374548190, 340684743, 258261357, 44394854, 132842469, 21283969, 137171866,
390602925, 84521296, 69276297, 387440969, 265980979, 65638508, 118425429, 148287455,