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 os, re | |
fs = [] | |
for x in os.listdir('.'): | |
if x.endswith('.mp4'): | |
fs.append((os.path.getsize(x), x)) | |
fs2 = [] |
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
# -*- encoding: UTF-8 -*- | |
# http://avva.livejournal.com/2827068.html | |
# run as: | |
# ( echo шир. узк. ; python glass_water_avva.py | tac ) | column -t | |
# v1 - широкий стакан | |
# v2 - узкий стакан | |
from fractions import Fraction |
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
set -eu | |
#скачиваю и распаковываю архивы из интернета | |
curl -sS http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xz | tar -xJf - & | |
curl -sS http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xz | tar -xJf - & | |
curl -sS http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xz | tar -xJf - & | |
curl -sS http://llvm.org/releases/3.5.0/clang-tools-extra-3.5.0.src.tar.xz | tar -xJf - & | |
wait #жду, пока всё скачается | |
#mv в существующую папку создаёт лишний уровень иерархии, поэтому проверка на несуществование |
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 <stdio.h> | |
#include <stdlib.h> | |
// malloc some number of gigabytes, to test impact on system | |
// g++ -O3 alloc-mem-test.cpp && ./a.out | |
size_t WIDTH = 75; | |
int progress_bar(size_t i, size_t size) { | |
return i * WIDTH / size; | |
} |
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
from collections import namedtuple | |
import numpy | |
Point = namedtuple('Point', ['x', 'y']) | |
class Point2: | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y |
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 | |
} |
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
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
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
#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); } |