Skip to content

Instantly share code, notes, and snippets.

View Teemu's full-sized avatar

Teemu Teemu

View GitHub Profile
@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/
@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 / 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 / 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 / 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) {
#!/usr/bin/env python
import os
import random
computers = ['albatrossi', 'broileri', 'dodo', 'drontti', 'emu', 'fasaani', 'flamingo', 'iibis', 'kakadu', 'kalkkuna', 'karakara', 'kasuaari', 'kiuru', 'kiwi', 'kolibri', 'kondori', 'kookaburra', 'koskelo', 'kuukkeli', 'lunni', 'moa', 'pelikaani', 'pitohui', 'pulu', 'ruokki', 'siira', 'strutsi', 'suula', 'tavi', 'tukaani', 'undulaatti', 'akaatti', 'akvamariini', 'ametisti', 'baryytti', 'berylli', 'fluoriitti', 'granaatti', 'hypersteeni', 'jade', 'jaspis', 'karneoli', 'korundi', 'kuukivi', 'malakiitti', 'meripihka', 'opaali', 'peridootti', 'rubiini', 'safiiri', 'sitriini', 'smaragdi', 'spektroliitti', 'spinelli', 'timantti', 'topaasi', 'turkoosi', 'turmaliini', 'vuorikide', 'zirkoni']
os.system('ssh %s' % random.choice(computers))
for FILE in *.mp4
do
echo $FILE
rm output.jpg
rm output.gif
ffmpeg -ss 30 -i $FILE -vf "select=gt(scene\,0.4)" -frames:v 1 -vsync vfr -vf fps=fps=1/60 out%02d.jpg
convert output.jpg -resize 900x900 ${FILE}.jpg
#rm palette.png
#ffmpeg -ss 20 -y -t 20 -i $FILE -vf fps=1,scale=640:-1:flags=lanczos,palettegen palette.png
#ffmpeg -ss 20 -t 20 -i $FILE -i palette.png -filter_complex "fps=1,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
@Teemu
Teemu / cache_get.py
Created December 23, 2016 00:57
Request JSON data from API and cache the result so you won't abuse the servers when developing
def cache_get(url):
"""Request from API and cache the result"""
import hashlib
import json
import os
import requests
domain = url.split('/')[2].split('.')[-2]
path = os.path.join(
'.cache',
package example
import dispatch._, Defaults._
import play.api.libs.json._
object Hello extends App {
val svc = url("https://www.metaweather.com/api/location/search/?query=helsinki")
val response = Http.default(svc OK as.String)
val json = Json.parse(response())
val woeid = (json \ 0 \ "woeid").get
@Teemu
Teemu / connect_to_proximo.sh
Created May 21, 2018 10:10
Fetching a file through SFTP using Proximo w/ ncat
sftp -o ProxyCommand='ncat --proxy PROXIMO_URL:1080 --proxy-auth PROXIMO_USERNAME:PROXIMO_PASSWORD --proxy-type socks5 -w 4 %h %p' user@host:FILE