Instantly share code, notes, and snippets.

# dobrokot

• Sort options
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:
Created Dec 17, 2015
 #!/usr/bin/env python # -*- coding: utf-8 -*- import logging import telegram from time import sleep try: from urllib.error import URLError except ImportError:
Last active Nov 4, 2015
 #include #include #include #include struct ListNode { private: typedef std::function()> NextGetterFunc; NextGetterFunc next_getter; std::shared_ptr cached_next;
Created Jun 24, 2015
random basket number of elements variance
 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:
Last active Aug 29, 2015
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
Created Apr 16, 2015
View test_mem_array_functions.c
 #include #include 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); }
Created Apr 10, 2015
View gist:0de3f031951988484f71
 int f(int x) { if (x == 0) return 0; int sign = x < 0 ? -1 : 1; return ((x&1) ? -x : +x) - sign; }
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
Last active Aug 29, 2015
View f(f(x))=-x.cpp
 #include #include 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;
Created Mar 10, 2015
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.