Skip to content

Instantly share code, notes, and snippets.

View akx's full-sized avatar
👹
rer

Aarni Koskela akx

👹
rer
View GitHub Profile
class FireAndForgetThreadedHTTPTransport(AsyncTransport, HTTPTransport):
scheme = ['http', 'https', 'faf+http', 'faf+https']
def send_sync(self, data, headers, success_cb, failure_cb):
try:
super(ThreadedHTTPTransport, self).send(data, headers)
except Exception as e:
failure_cb(e)
else:
success_cb()
@akx
akx / parse_migr_resvas.py
Created July 11, 2016 12:41
parse_migr_resvas.py
# download: http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?file=data/migr_resvas.tsv.gz
import gzip
from collections import defaultdict
geo_to_citizen = defaultdict(dict)
for line in gzip.GzipFile("migr_resvas.tsv.gz"):
line = line.decode("utf8")
if not line.startswith("T,TOTAL"): # Ignore non-total lines
continue
@akx
akx / git-lastmod.sh
Created July 25, 2016 06:45
git-lastmod.sh: print the last commit dates of currently existing files in the current repository
#!/bin/bash
# print the last commit dates of currently existing files in the current repository
(
git ls-files | sed 's/^/+ /'
git log --format=format:"~ %aI" --name-only .
) | gawk '
/^~/ {date=$2;}
/^+/ {extant[$2] = 1;}
/^[^~+]/ {dates[$1] = date;}
END { for (file in dates) if(extant[file]) print(dates[file], file); }
@akx
akx / velhosuomi.js
Created October 4, 2016 09:13
Velhosuomi bookmarklet
javascript:!function(){function e(e){var o=Math.random()<.7?"aeiou":"äeiöy";return e.replace(/[aeiouyåäö]+/gi,function(e){var n=o[0|5*Math.random()];return e[0].toUpperCase()==e[0]&&(n=n.toUpperCase()),n})}function o(n){n.nodeType==Node.TEXT_NODE&&/\S/.test(n.nodeValue)?n.nodeValue=e(n.nodeValue):[].slice.call(n.childNodes).map(o)}o(document.body)}();
from urllib import urlencode
import hashlib
import os
import requests
import sys
import tempfile
def build_hash(text, engine, voice, language, fx=None, fx_level=None):
fragments = [
@akx
akx / zay.py
Created October 21, 2016 12:15
#!/usr/bin/env python3
# `brew install sox` first
import argparse, tempfile, subprocess, os
ap = argparse.ArgumentParser()
ap.add_argument('-v', '--voice', default='Mikko')
ap.add_argument('-p', '--pitch', type=int, default=0)
ap.add_argument('-t', '--tempo', type=float, default=None)
ap.add_argument('-s', '--speed', type=float, default=None)
ap.add_argument('text')
akx@monolith:/tmp$ source kkek/bin/activate
(kkek) akx@monolith:/tmp$ UWSGI_EMBED_PLUGINS=stats_pusher_statsd pip install uwsgi
Collecting uwsgi
Using cached uwsgi-2.0.14.tar.gz
Building wheels for collected packages: uwsgi
Running setup.py bdist_wheel for uwsgi ... done
Stored in directory: /home/akx/.cache/pip/wheels/c4/ad/56/f70a70b63fa4b0f2c0518db6f41381c9d33cd5cc5ac9a9494b
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.14
<!DOCTYPE html>
<html lang="en">
<body>
<script>
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 800;
var ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
function lerpPoint(pa, pb, alpha) {
const shortid = require('shortid');
const redis = require("redis");
const client = redis.createClient();
function t() {
const id = shortid.generate();
client.sadd('sids', id, (err, res) => {
if(err) throw err;
if(res != 1) { // redis will return the number of new items, so if we added anything other than 1, something broke
throw new Error('gack, duplicate ' + id);
+ #emblem
+ #marketing-hero
+ #marketing-hero form
+ #marketing-hero form .control-label
+ #marketing-hero h1
+ #messages
+ #messages li
+ #messages ul
+ #messages.dismissed
+ .affix