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 / 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:
View gist:bad948b020e8708fc987
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import telegram
from time import sleep
try:
from urllib.error import URLError
except ImportError:
@dobrokot
dobrokot / haskell_like_lazy_lists.cpp
Last active Nov 4, 2015
haskell_like_lazy_lists.cpp
View haskell_like_lazy_lists.cpp
#include <memory>
#include <functional>
#include <iostream>
#include <assert.h>
struct ListNode {
private:
typedef std::function<std::shared_ptr<ListNode>()> NextGetterFunc;
NextGetterFunc next_getter;
std::shared_ptr<ListNode> cached_next;
@dobrokot
dobrokot / random_baskets.py
Created Jun 24, 2015
random basket number of elements variance
View random_baskets.py
import random
def main():
basket = [0]*5
rand = random.randrange
for i in xrange(27777777):
basket[rand(0, 5)%5] += 1
for v in basket:
View binomial_confidence_plot.py
# http://slobin.livejournal.com/515819.html
import math
def interval(k, n):
# http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
# Wilson score interval
z = 1.96 #95% confidence
p = 1.0*k / n
View test_mem_array_functions.c
#include <string.h>
#include <stdio.h>
typedef char *p;
volatile p src = NULL;
volatile p dst = NULL;
volatile size_t n = 0;
#define TEST(x) if (x) ; else { printf("error, %s\n", #x); }
View gist:0de3f031951988484f71
int f(int x) {
if (x == 0)
return 0;
int sign = x < 0 ? -1 : 1;
return ((x&1) ? -x : +x) - sign;
}
@dobrokot
dobrokot / suffix_array_sort.py
Last active Aug 29, 2015
suffix array sort
View suffix_array_sort.py
def trivial_suffix_sort(txt):
n = len(txt)
txt2 = txt + txt
tmp = sorted((txt2[i:i+n], i) for i in xrange(n))
return [x[1] for x in tmp]
def suffix_sort(txt):
# рассматривает txt как кольцо, и сортирует строки txt[i:i + len(l)],
# возвращает список индексов sort_permutation[i], где начинается i-ая сортированая строка
# см. также эквивалентную функцию trivial_suffix_sort
View f(f(x))=-x.cpp
#include <iostream>
#include <algorithm>
int f[100];
int mx[100]; // mx[x] = (-x modulo N)
int main() {
for (int i = 0; i < N; ++i) {
f[i] = i;
mx[i] = (N - i) % N;
View function_var_binding.sh
A=10; B=20; bash -c "A=30; B=40; foo() { echo $A \$B; }; declare -f foo"
------------------------------------
Output:
foo ()
{
echo 10 $B
}
You can’t perform that action at this time.