Skip to content

Instantly share code, notes, and snippets.

View eliask's full-sized avatar
🥼

Elias Kunnas eliask

🥼
View GitHub Profile
@eliask
eliask / hinton.py
Created February 16, 2012 22:10 — forked from dwf/hinton.py
A function for drawing Hinton diagrams with matplotlib.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/292018 - augmented to plot row/column labels
"""
Draws Hinton diagrams using matplotlib ( http://matplotlib.sf.net/ ).
Hinton diagrams are a handy way of visualizing weight matrices, using
colour to denote sign and area to denote magnitude.
By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf)
with thanks to Geoffrey Hinton for providing the MATLAB code off of
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
# Usage: double_utf8_fix.py < input > output
import sys, re
# functions to detect/fix double-encoded UTF-8 strings
# Based on http://blogs.perl.org/users/chansen/2010/10/coping-with-double-encoded-utf-8.html
DOUBLE_ENCODED = re.compile("""
\xC3 (?: [\x82-\x9F] \xC2 [\x80-\xBF] # U+0080 - U+07FF
| \xA0 \xC2 [\xA0-\xBF] \xC2 [\x80-\xBF] # U+0800 - U+0FFF
@eliask
eliask / akureyri_data_2016.py
Created May 3, 2016 20:57
Random data munging as a Service at Akureyri :)
#!/usr/bin/env python3
import re
from itertools import *
A='''
Cod
Ár (Year) Lína (Long line) Dragnót (Demersal seine) Botnvarpa (Demersal trawl) Net (Gill net) Öll veiðarfæri (All gear)
Fjöldi (Numbers) Þyngd (Weight) Fjöldi (Numbers) Þyngd (Weight) Fjöldi (Numbers) Þyngd (Weight) Fjöldi (Numbers) Þyngd (Weight) Fjöldi (Numbers) Þyngd (Weight)
Brottkast % brottk. Brottkast % brottk. Skekkja Brottkast % brottk. Brottkast % brottk. Skekkja Brottkast % brottk. Brottkast % brottk. Skekkja Brottkast % brottk. Brottkast % brottk. Skekkja Brottkast % brottk. Brottkast % brottk.
(Discards) (% disc.) (Discards) (% disc.) (C.V) (Discards) (% disc.) (Discards) (% disc.) (C.V) (Discards) (% disc.) (Discards) (% disc.) (C.V) (Discards) (% disc.) (Discards) Tonn (% disc.) (C.V) (Discards) (% disc.) (Discards) (% disc.)
n Tonn n Tonn n Tonn n n Tonn
@eliask
eliask / nordea_scrape_pdf_dumps.py
Last active November 23, 2016 06:27
Scrape transaction data from Nordea web bank PDF account statements
#!/usr/bin/env python3
#
# Hacky but functional script for extracting data from (Finnish) Nordea web bank account statement PDF files.
#
# 1. Presumes you have some account statements to clean up (for hledger, for instance).
# 2. The normal {Transactions,Tapahtumat}_<IBAN>.txt CSV files are by far superior to work with,
# but they are no longer available after just a year or two (better archive them while you can!).
# 3. I wanted to have more history available, so I devised this hacky method to extract it
# sort of cleanly from the PDF account statements in Finnish.
#
@eliask
eliask / autocomplete.sh
Created December 1, 2016 07:26
Auto-complete from command-line (bash) using Google Autocomplete API.
function c() {
url='https://www.google.com/complete/search?client=hp&hl=en&xhr=t'
# NB: user-agent must be specified to get back UTF-8 data!
curl -H 'user-agent: Mozilla/5.0' -sSG --data-urlencode "q=$*" "$url" |
jq -r .[1][][0] |
sed 's,</\?b>,,g'
}
@eliask
eliask / download_instagram_images_from_har.sh
Created January 30, 2017 10:09
Download Instagram original quality images from a HAR dump
#!/usr/bin/env bash
har=www.instagram.com.har
time jq -r .log.entries[].request.url "$har" |
grep scontent |
sed 's#[ps][0-9]*x[0-9]*/sh0\.08/##;s#[sp][0-9]*x[0-9]*/##' |
sort -u |
xargs wget --timestamping --trust-server-names
@eliask
eliask / keybase.md
Created February 18, 2017 17:06
keybase.md

Keybase proof

I hereby claim:

  • I am eliask on github.
  • I am eliask (https://keybase.io/eliask) on keybase.
  • I have a public key ASDtKagWNb0t4v2MDGYurC6MNHwumDQg3zem-JSZHazG_wo

To claim this, I am signing this object:

@eliask
eliask / nomador.py
Created March 3, 2017 14:53
Random Nomador.com API request using Python Requests
#NB. Generated with https://github.com/eliask/curlconverter using "Copy as cURL"
import requests
cookies = {
'gsScrollPos': '',
'NOMADOR_SESSION': '',
}
headers = {
'Accept-Encoding': 'gzip, deflate, sdch, br',
@eliask
eliask / randomize_mac_periodically.sh
Created June 9, 2017 14:33
Randomize MAC address periodically with spoof-mac (brew install spoof-mac) -- Useful for time-limited wifi hotspots
#! /bin/sh
if test $# = 0 ; then
echo "Usage: $0 <sleep interval like 15m>"
exit 1
fi
while true
do
echo "Randomizing MAC now"
spoof-mac randomize en0
@eliask
eliask / .bashrc
Created July 13, 2017 15:21
bash: tmp() instead of rm
# tmp: move files to /tmp instead of removing them outright.
# /tmp is cleaned up on reboot or so, so there is time to rectify mistakes.
#
# Usage: tmp [files or directories...]
# batch "do stuff to a file" files...
function batch() {
p="$1"
shift
for x in "$@"; do