Skip to content

Instantly share code, notes, and snippets.

View bobrik's full-sized avatar

Ivan Babrou bobrik

View GitHub Profile
-# если вы дурак^W как я, и на руби пишете
-# в основном в состоянии расширенного сознания,
-# то вот вам пример, как делать условия в haml:
- if myfreakingvar == 'omg'
%p My freaking var is "omg". OMG!
-# штука в том, что строки, начинающиеся с «-»,
-# выполняются как ruby код, а всё, что уровнем
-# «ниже» по «дереву» - оборачивается в do .. end
@bobrik
bobrik / lazy_map.py
Created October 20, 2010 15:38
lazy map variant for python
#!/usr/bin/python
def lazy_map(func, *sequences):
"""
Ленивая реализация map, делающая вызовы только при необходимости
получения результата, т.е. итерации возвращаемого генератора.
При множественном вызове получается чистая композиция функций, т.е.
lazy_map(lambda: x+1, lazy_map(lambda x: x+2, [1, 2, 3]))
@bobrik
bobrik / memcached-0.1.5-compatibility.patch
Created October 12, 2011 10:04
memcached module for php with backward compatibility hacks
diff --git a/php_memcached.c b/php_memcached.c
index aecdc4f..7ad6c0d 100644
--- a/php_memcached.c
+++ b/php_memcached.c
@@ -115,17 +115,17 @@ typedef unsigned long int uint32_t;
/****************************************
Payload value flags
****************************************/
-#define MEMC_VAL_TYPE_MASK 0xf
+#define MEMC_VAL_TYPE_MASK 0x2f
@bobrik
bobrik / Spawner.js
Created October 13, 2011 15:55
es5 inheritance
exports.spawn = function(parent, props) {
var key,
defs = {
_parent: { value: parent, enumerable: true }
};
for (key in props) {
if (props.hasOwnProperty(key)) {
defs[key] = {
value : props[key],
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,
@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();
}