Skip to content

Instantly share code, notes, and snippets.

@dobrokot
dobrokot / namedtuple_memory_test.py
Last active August 29, 2015 14:13
python tuple/named type memory test
from collections import namedtuple
import numpy
Point = namedtuple('Point', ['x', 'y'])
class Point2:
def __init__(self, x, y):
self.x = x
self.y = y
@dobrokot
dobrokot / alloc-mem-test.cpp
Created December 8, 2014 22:33
allocate memory to test system behavior
#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;
}
@dobrokot
dobrokot / download-build-clang.sh
Last active August 29, 2015 14:10
download and build clang
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 в существующую папку создаёт лишний уровень иерархии, поэтому проверка на несуществование
@dobrokot
dobrokot / glass_water_avva.py
Last active August 29, 2015 14:10
avva glass water problem
# -*- 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
@dobrokot
dobrokot / filename_punctuation_strip.py
Created November 3, 2014 13:38
strip punctiation from file names
import os, re
fs = []
for x in os.listdir('.'):
if x.endswith('.mp4'):
fs.append((os.path.getsize(x), x))
fs2 = []
#include "uatraits/details/branch.hpp"
#include "uatraits/details/definition.hpp"
-#include "uatraits/details/hash_utils.hpp"
#include "uatraits/details/regex_definition.hpp"
#include "uatraits/details/static_definition.hpp"
#include "uatraits/details/string_definition.hpp"
@@ -181,7 +180,7 @@
header = header.substr(0, header.length() - sizeof (to_strip) + 1);
}
mkdir src_dir
mkdir exec_dir
python generate_variants.py
ls src_dir | xargs -P 100 -IF gcc src_dir/F -o exec_dir/F.x 2>/dev/null
find exec_dir/ | xargs -n 1 -P 1000 ./check_prog.sh
(
find . -name '*.cpp' -or -name '*.h' | xargs grep -E '^ *[a-zA-Z0-9< >,:_]+ +[a-zA-Z0-9_]+;$' -o -h | grep '<' | grep '>' ;
find . -name '*.cpp' -or -name '*.h' | xargs grep -E '^ *[a-zA-Z0-9_]+ +[a-zA-Z0-9_]+;$' -o -h
) | awk '{print $2}' | sort -u | tr -d ';' > ../names.txt
find . -name '*.cpp' -or -name '*.h' | xargs fgrep --word-regexp -f ../names.txt -oh | sort | uniq -c | awk '$1 <= 2'
@dobrokot
dobrokot / select_print.cpp
Last active August 29, 2015 14:04
select different print for containers and non-containers
//compile with g++ -std=c++11 select_print.cpp
#include <vector>
#include <iostream>
#include <string>
namespace detail {
struct FromAny {
template <class T> FromAny(const T&) {}
@dobrokot
dobrokot / lambdaman.gcc
Created August 4, 2014 13:31
icfp 2014 lambda-man asm and code
LD 0 0 ; 00
LD 0 1 ; 01
LDF 5 ; 02
LDC 0 ; 03
TSEL 1824 1824 ; 04
LDC 1 ; 05
LDC 2 ; 06
LDC 3 ; 07
LDC 0 ; 08
CONS ; 09