This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import logging | |
import telegram | |
from time import sleep | |
try: | |
from urllib.error import URLError | |
except ImportError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int f(int x) { | |
if (x == 0) | |
return 0; | |
int sign = x < 0 ? -1 : 1; | |
return ((x&1) ? -x : +x) - sign; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A=10; B=20; bash -c "A=30; B=40; foo() { echo $A \$B; }; declare -f foo" | |
------------------------------------ | |
Output: | |
foo () | |
{ | |
echo 10 $B | |
} |
NewerOlder