Skip to content

Instantly share code, notes, and snippets.

View bobrik's full-sized avatar

Ivan Babrou bobrik

View GitHub Profile
@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
@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 / 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 / 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;
(function() {
var shouldCall = false;
function first() {
console.log("first callback")
if (!shouldCall) {
shouldCall = true;
} else {
firstFinal();
}
@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
// /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;
// 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 = {};
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;
});
// rm aa; node buggy3.js | fgrep WTF | wc -l
// different results for each run
// writes are sequential
function FileWriterQueue(file) {
this.file = file;
this.queue = [];
}
FileWriterQueue.prototype.write = function(buffer, offset, callback) {