Skip to content

Instantly share code, notes, and snippets.

View Teemu's full-sized avatar

Teemu Teemu

View GitHub Profile
@Teemu
Teemu / useful_aliases.sh
Last active May 29, 2019 09:30
List of useful aliases
alias gpu='git push -u origin $(git symbolic-ref --short HEAD)'
alias gitbackup='git checkout -b backup/`git rev-parse --abbrev-ref HEAD`/`date +%Y%m%d-%H%M%S` && git checkout -'
alias acommit='git add -A :/ && git commit -a'
alias changedfiles='git diff --name-status master..`git rev-parse --abbrev-ref HEAD`'
alias rebasemaster='git checkout master && git pull && git checkout - && git rebase master'
alias updatebranch='git fetch && git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)'
alias changed='git diff HEAD'
alias gitbranch="git for-each-ref --color=always --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' | tail -15"
killport () {
if [ -z "`lsof -i tcp:${1:-5000}`" ]
@Teemu
Teemu / refactor.py
Created February 22, 2019 11:10
Refactor projects since IDE support is too much to ask
import click
import os
import glob
@click.command()
@click.option('--dry/--no-dry', default=False)
@click.argument('root_path', type=click.Path())
@click.argument('replace_strings', nargs=-1)
def replace_all(dry, root_path, replace_strings):
@Teemu
Teemu / open_pull_request.py
Created January 23, 2019 11:33
Open a pull request in Github
from sh import git, open
branch = git('rev-parse', '--abbrev-ref', 'HEAD').strip()
location = git('remote', 'get-url', 'origin').split('[email protected]:')[1].split('.git')[0]
url = 'https://github.com/%s/compare/%s?expand=1' % (
location,
branch
)
open(url)
#!/usr/local/bin/python3
from pycookiecheat import chrome_cookies
from requests_html import HTMLSession
import requests
import click
import time
import pync
@click.command()
@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
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 / 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',
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
#!/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))
@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) {