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 / mbox_stuff.py
Created November 19, 2016 08:17
Playing with gmail mbox dump from Google Takeout (writes all attachments as separate files etc under /tmp)
#! /usr/bin/env python3
# Usage: mbox_stuff.py All\ mail\ Including\ Spam\ and\ Trash.mbox
import mailbox
import traceback
import sys
from itertools import chain
num = 1
def get_parts(msg,n=0):
global num
@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 / ppxml.py
Last active August 24, 2020 11:40
Pretty print XML files with python xml.dom.minidom
#!/usr/bin/env python
# ppxml - pretty print XML from stdin or argv files
#
# NB: if multiple XML files are specifies, concatenates the prettyprinted
# versions one after the other.
#
# Python 2 and Python 3 compatible AFAICT.
#
import sys
import xml.dom.minidom as md
@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',