Skip to content

Instantly share code, notes, and snippets.

dobrokot

Block or report user

Report or block dobrokot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dobrokot
dobrokot / write_png_to_memory_with_libpng.cpp
Created Apr 11, 2014
encode and write PNG to memory (std::vector) with libpng on C++
View write_png_to_memory_with_libpng.cpp
#include <png.h>
#include <vector>
#include <iostream>
#include <stdlib.h>
//encode and write PNG to memory (std::vector) with libpng on C++
typedef unsigned char ui8;
#define ASSERT_EX(cond, error_message) do { if (!(cond)) { std::cerr << error_message; exit(1);} } while(0)
@dobrokot
dobrokot / sRGB_color_mixing.py
Created Jan 24, 2016
test color mixing in sRGB
View sRGB_color_mixing.py
def sRGB_to_linear(c):
a = 0.055
if c <= 0.04045:
return c / 12.92
else:
return ((c + a) / (1+a)) ** 2.4
def linear_to_sRGB(c):
a = 0.055
if c <= 0.0031308:
@dobrokot
dobrokot / auto_differentiate.cpp
Created Jan 12, 2014
auto_differentiate.cpp
View auto_differentiate.cpp
#include <math.h>
#include <stdio.h>
template <class Number>
Number f(Number x) {
Number z = x;
for (int i = 0; i < 4; ++i) {
z = z*z - 0.1 + sin(z*3);
}
if (z < 1) {
View print_word_search_expectation.py
import sympy
def make_id(size):
return sympy.Matrix([[int(i==j) for j in xrange(size)] for i in xrange(size)])
def add_absorb(k, m):
size = len(m)
assert size == len(m[0])
return [row + [0] for row in m] + [ [0]* (size-1) + [k,1] ]
@dobrokot
dobrokot / count_random_words.py
Created Jan 1, 2014
substring probability, n successes in a row
View count_random_words.py
#!/usr/bin/env python
import random
def id_mat(n):
return [[int(i == j) for j in xrange(n)] for i in xrange(n)]
def my_pow(x, n, mul_fun, one):
r = one
assert n >= 0 and int(n) == n
@dobrokot
dobrokot / fast_grep_patch3.diff
Last active Dec 21, 2015
faster state sets merge in grep utility, dfa.c (avoid O(N^2) algorithms)
View fast_grep_patch3.diff
Index: dfa.c
===================================================================
--- dfa.c (revision grep-2.14-faster-dfa)
+++ dfa.c (revision grep-2.14)
@@ -1992,6 +1992,133 @@
s->elems[i] = s->elems[i + 1];
}
+/* Merge implementation of sorted sets, then number of sets smore than 2.
+ Priority queue aka 'heap' data structure used to select maximum of
@dobrokot
dobrokot / fast_grep_patch2.diff
Created Aug 25, 2013
faster state sets merge in grep utility, dfa.c (avoid O(N^2) algorithms)
View fast_grep_patch2.diff
--- dfa.c.back 2013-08-05 16:53:47.824514544 +0400
+++ dfa.c 2013-08-25 04:23:18.783885918 +0400
@@ -1992,6 +1992,115 @@
s->elems[i] = s->elems[i + 1];
}
+/* merge implementation of sorted sets, then number of sets smore than 2
+ priority queue aka 'heap' data structure used to select maximum of
+ many elements */
+
@dobrokot
dobrokot / cpp_iostream_fail_open_file.cpp
Created Aug 17, 2013
How to handle non-existing opened file with ifstream ?
View cpp_iostream_fail_open_file.cpp
#include <iostream>
#include <fstream>
int main() {
std::ifstream empty("empty.txt");
std::ifstream no_file("no_file.txt");
std::cout << "bool: " << (empty?"e 1":"e 0") << ' ' << (no_file?"n 1":"n 0") << '\n';
std::cout << "rdstate:" << (empty.rdstate()?"e 1":"e 0") << ' ' << (no_file.rdstate()?"n 1":"n 0") << '\n';
@dobrokot
dobrokot / fast-python-utf8.cpp
Created Aug 6, 2013
faster conversion to unicode from UTF-8 for python 2.*
View fast-python-utf8.cpp
#include <Python.h>
#include <stdlib.h>
#include <stdio.h>
#define UTF8_ACCEPT 0
#define UTF8_REJECT 1
#include <stdint.h>
View faster_grep_patch.diff
$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)
+{
You can’t perform that action at this time.