Skip to content

Instantly share code, notes, and snippets.

@dobrokot
dobrokot / merge_friends_to_dot.py
Created November 1, 2012 15:17
simpliest lj foaf parse and merging to .DOT-file
import glob
from os.path import basename, splitext
ls = [l.strip() for l in open('_winnie.txt').read().splitlines() if l.strip()]
my_f = set(l[2:] for l in ls if l[0] != '#' and l[0] == '>')
my_f.remove('_winnie')
print 'digraph {'
@dobrokot
dobrokot / .vimrc
Created January 11, 2013 13:18
.vimrc
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
set showmatch
/**
* Fast computations of cumulative sums.
* D. Lemire, July 2012
*
* Best results with:
*
$ g++-4.7 -funroll-loops -O3 -o cumulsum cumulsum.cpp
$ ./unrolldeltas
#!/usr/bin/env python
import pylab as pl
import numpy as np
import random
import sys
stat = {}
@dobrokot
dobrokot / iospeed.cpp
Created March 13, 2013 11:35
Testing speed of ofstream and FILE*
#include <iostream>
#include <fstream>
#include <stdio.h>
const int N = 1000*1000*10;
void f1() {
std::ofstream out("out.txt", std::ios::binary);
for (int i = 0; i < N; ++i) {
@dobrokot
dobrokot / primes_ulam_spiral_rotated45.py
Created June 21, 2013 11:06
# ulam spiral, rotate 45 degree
# ulam spiral, rotate 45 degree
# http://users.livejournal.com/_winnie/392996.html
import Image
def is_prime(n):
if n <= 2:
return 1
k = 2
print "hello, world"
@dobrokot
dobrokot / exceptions.cpp
Created July 9, 2013 10:45
exceptions.cpp
#include <iostream>
#include <string>
#include <stdexcept>
#include <stdlib.h>
void g(int i) {
if (i % 4 == 0 && i % 6 == 0)
throw std::logic_error("FATALITY");
if (i % 3 == 0)
@dobrokot
dobrokot / fuzzy_search.py
Last active December 20, 2015 14:59
fuzzy search regexp generator
# usage:
# LC_ALL=C grep "$(python fuzzy_search.py "HELLO")" input.file.utf8.txt
import sys
s = sys.argv[1]
su = s.decode('utf-8')
utf8_any = '[^\x80-\xbf][\x80-\xbf]*'
$diff -u ~/tmp/grep-2.14/src/dfa.c.prev ~/tmp/grep-2.14/src/dfa.c
--- /home/dobrokot/tmp/grep-2.14/src/dfa.c.prev 2013-08-05 16:53:47.824514544 +0400
+++ /home/dobrokot/tmp/grep-2.14/src/dfa.c 2013-08-05 16:50:41.435058597 +0400
@@ -1978,6 +1978,52 @@
m->elems[m->nelem++] = s2->elems[j++];
}
+static void
+merge_inplace (position_set const *src, position_set *dst)
+{