Skip to content

Instantly share code, notes, and snippets.

View nmmmnu's full-sized avatar

Nikolay Mihaylov nmmmnu

View GitHub Profile
@nmmmnu
nmmmnu / gist:2845220
Created May 31, 2012 18:21
Schema design
items {
dl { name => DELL6400, keyword:1 => computer, keyword:2 => DELL, keyword:3 => topseller }
hp { name => HP12345, keyword:1 => computer, keyword:2 => HP }
no { name => Nokia8210, keyword:1 => phone, keyword:2 => NOKIA }
}
// here I store keys of the items only,
// in reality I have denormalized most of items columns
keywords{
computer { webpage => www.domain.com/computer , item:dl => dl , item:hp => hp }
@nmmmnu
nmmmnu / gist:2959336
Created June 20, 2012 10:51
cassandra possible IntegerType bug?
in CLI:
create column family a
with column_type = 'Standard' and
comparator = 'IntegerType' and
default_validation_class = 'UTF8Type' and
key_validation_class = 'IntegerType';
=======================
@nmmmnu
nmmmnu / timeout.cc
Created August 19, 2012 13:05
Executes command for up to "time" seconds.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
//#define DEBUG
//Default livetime is 1:30
#define LIVETIME 90
Options for implementing HLL without read before write.
What I need:
I generally need something like grid / two dimentional array.
There will be 64, 128, 256, 512, 1024 grid "X" coordinate and 256 (because 1 byte can store 0-255 as value) grid "Y" coordinate.
There will be no value, but I can store there "1" (because we use PHP and it requires some value),
we can also store the byte value, in order to read data easier.
"""
Simple Linear Probabilistic Counters
Credit for idea goes to:
http://highscalability.com/blog/2012/4/5/big-data-counting-how-to-count-a-billion-distinct-objects-us.html
http://highlyscalable.wordpress.com/2012/05/01/probabilistic-structures-web-analytics-data-mining/
Installation:
pip install smhasher
pip install bitarray
@nmmmnu
nmmmnu / multiplication.php
Last active August 29, 2015 13:57
Multiplication with shift
<?
function multiplicate2($a, $b){
printf("%16b x %b\n%16b\n", $a, $b, $a * $b);
}
function multiplicate($a, $b){
printf("%1s %32d x %8d = %d\n", "", $a, $b, $a * $b);
printf("%1s %32b x %8b\n", "", $a, $b);
@nmmmnu
nmmmnu / oop_class_demo.c
Last active August 29, 2015 13:57
OOP using plane C
#include <stdlib.h>
#include <stdio.h>
/*
* Base class. It defines int area() method.
* The class is abstract so we did not made constructor.
* Calling the area() method will probably core dump.
*/
@nmmmnu
nmmmnu / div.sh
Last active August 29, 2015 13:57
$ php
<?
error_reporting(E_ALL);
$a = 5 / 0;
var_dump($a);
<ctrl-d>
#include <stdio.h>
#define MAX 2000000000
//#define IMPL 0
int do_loop(int max);
int main(){
printf("%d\n", do_loop(MAX) );
@nmmmnu
nmmmnu / read_prom.js
Created September 8, 2014 19:44
NodeJS Q Promises Demo
var fs = require('fs');
var Q = require("q");
/*
Q.all(
[
Q.ninvoke(fs, "readFile", "/etc/hosts", "utf8")
]
)
*/