Skip to content

Instantly share code, notes, and snippets.

View Teemu's full-sized avatar

Teemu Teemu

View GitHub Profile
@Teemu
Teemu / C++-debug-code.cc
Created April 17, 2016 15:43
C++ debug macros
int PRINT_TIMES = 0;
#define PRINT(x) PRINT_TIMES++; if (PRINT_TIMES <= 40) {std::cout << #x << " = " << x << "\n";}
#define PRINT_VECTOR(x) PRINT_TIMES++; if (PRINT_TIMES <= 40){std::cout << #x << " = "; print_vector(x);}
template <typename T>
void print_vector(T &v) {
std::cout << "{";
bool first_value = true;
for (auto i = v.begin(); i != v.end(); ++i) {
if (first_value) {
@Teemu
Teemu / non_deterministic_automata_convertor.py
Created April 4, 2016 12:36
Convert a nondeterministic finite state automaton to a deterministic finite state automaton
"""Convert a nondeterministic finite state automaton to a deterministic finite state automaton"""
from collections import OrderedDict
START = 'a'
STATES = {
'a': {
0: {'a'},
1: {'a', 'b'}
},
@Teemu
Teemu / reset_webcam
Created March 14, 2016 11:04
Take timelapse with Raspberry Pi and unstable webcam
#!/bin/sh
# https://gist.github.com/x2q/5124616#file-usbreset-c-L41
/usr/bin/usbreset /dev/bus/usb/001/002
@Teemu
Teemu / XX_turing_machine
Last active March 14, 2016 11:16
Turing machine that detects {ww | w contains {a,b}*}, try it at http://turingmachinesimulator.com/shared/gfemhnbiqs
name: ww
init: Start
accept: Success
Start,a,_
GoRight,a,X,>,>
Start,b,_
GoRight,b,X,>,>
Start,a,Y
2GoLeft,a,Y,<,<
@Teemu
Teemu / hack.sh
Last active August 29, 2015 14:26
Creating virtualenv with Python3 when everything fails
pip3 install virtualenv
python3.4 `which virtualenv` --python=`which python3.4` --no-site-packages env
mv env ~/.virtualenvs/