Skip to content

Instantly share code, notes, and snippets.

View joneskoo's full-sized avatar

Joonas Kuorilehto joneskoo

View GitHub Profile
@joneskoo
joneskoo / entropy.py
Created October 29, 2011 06:10
Entropy calculation
#!/usr/bin/env python3
import math
def H(data):
entropy = 0
if not data:
return entropy
for x in range(256):
p_x = float(data.count(chr(x))/len(data))
@joneskoo
joneskoo / doomsdaydevice.sh
Created November 24, 2011 14:33
irssi killer - kill all irssis, 50 at a time
#!/bin/bash
IRSSI=$(pgrep irssi)
while [[ -n $IRSSI ]]; do
tokill=$(pgrep irssi | head -n 100)
kill $tokill
echo "Killing 100 irssis. Hit enter to kill more."
echo $(pgrep irssi|wc -l) to go
read
IRSSI=$(pgrep irssi)
@joneskoo
joneskoo / headers.cgi
Created November 26, 2011 13:33
Print all headers available to the web server except some non-public headers
#!/usr/bin/python
print "Content-type: text/plain; charset=UTF-8"
print
import os
ignore_these = [
'PATH',
'DOCUMENT_ROOT',
@joneskoo
joneskoo / runlatex.py
Created December 1, 2011 05:19
Run latex in a automatically destroyed temporary directory
#!/usr/bin/env python3
# Joonas Kuorilehto 2011
import os.path
from subprocess import Popen, PIPE
import shutil
from contextlib import contextmanager
from tempfile import mkdtemp
@joneskoo
joneskoo / snapshot.sh
Created December 6, 2011 17:54
Find zfs snapshots for current path
function zfs-snapshots () {
if [[ $PWD =~ "/.zfs" ]]; then
echo "Not supported under .zfs directory"
return
fi
local oIFS
declare -A snapshots
oIFS=$IFS
IFS=$'\t' # the display name and path are \t separated, \0 terminated
snapshot_list=()
@joneskoo
joneskoo / gist-backup.py
Created December 15, 2011 06:13
Clone all my gists automatically (gist backup?)
#!/usr/bin/env python
# Git clone all my gists
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
USER = os.environ['USER']
@joneskoo
joneskoo / walk-binary-tree.py
Created May 27, 2012 10:19
Walk a binary tree
#encoding: utf-8
class Node:
left = None
right = None
parent = None
key = None
def __init__(self, key):
self.key = key
@joneskoo
joneskoo / wellsfargo-csv.py
Created December 30, 2012 01:45
Sort Wells Fargo CSV account activity by actual payment date, not post date
#!/usr/bin/env python
# Sort Wells Fargo CSV account activity by actual payment date, not post date
# By Joonas Kuorilehto. This script is Public Domain.
# Input: CSV file downloaded from Wells Fargo account activity
# Output: list of payments by transaction date
import re
import csv
import sys
@joneskoo
joneskoo / sms-mailer.py
Last active December 31, 2022 14:33
Send unread SMS messages (from adb shell) to email
#!/usr/bin/env python3
# Joonas Kuorilehto 2013
# This script is Public Domain.
import csv
import subprocess
import pipes
from datetime import datetime
import smtplib
@joneskoo
joneskoo / .htaccess
Last active October 25, 2020 06:41
Kapsi Django example project
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://lakka.n.kapsi.fi:31859/$1 [L,P]