Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Working from home

Yrjö Kari-Koskinen ykarikos

🏡
Working from home
  • Tomorrow Tech
  • Helsinki
View GitHub Profile
@ykarikos
ykarikos / csvsum.py
Created Dec 24, 2011
Count together the CSV rows' last columns and use the first n rows as the key
View csvsum.py
#!/usr/bin/python
# Count together the CSV rows' last columns and use the first n rows as the key.
# Use cut to crop the key space, e.g.
# $ cut -d\; -f 3-4,8 | csvsum.py
import sys
sums = {}
@ykarikos
ykarikos / smtpToMaildir.pl
Created Mar 22, 2012
SMTP Listener that writes everything in a Maildir
View smtpToMaildir.pl
#!/usr/bin/perl -w
#
# smtpToMaildir.pl (C) 2009 Yrjö Kari-Koskinen <ykk@peruna.fi>
#
# This program is licensed under Version 2 of the GPL.
# The perl package dependencies can be satisfied with the following
# Debian/Ubuntu packages: libmail-box-perl libnet-smtp-server-perl
use strict;
@ykarikos
ykarikos / gist:2405068
Created Apr 17, 2012
Git log analysis
View gist:2405068
# List amount of commits in git repository per month and author
git log --pretty='format:%ad %ae' --date=short | sed 's/@.*//'| cut -b -7,11- |sort |uniq -c |awk '{ printf "%s %30s ", $2, $3; count=int($1/2); for(i=0; i<count; i++) { printf "*" } printf "\n"; }'
# List amount of commits on different times of day
git log --pretty='format:%ad' --date=iso | cut -b 12-13|sort |uniq -c|awk '{ printf "%s %30s ", $2, $3; count=int($1/2); for(i=0; i<count; i++) { printf "*" } printf "\n"; }'
# Find inhumane commit times
git log --pretty='format:%ad %ae %s' --date=iso | egrep -v "^2012-[0-9-]* ([12]|0[7-9])"
@ykarikos
ykarikos / gist:2411905
Created Apr 18, 2012
Hide Trello board-widgets
View gist:2411905
javascript:(function(){$(".board-widgets").hide();$("#board").css("width","98%");})();
@ykarikos
ykarikos / transpose.py
Created May 28, 2012
Transpose utf-8 string columns as rows and vice versa
View transpose.py
#!/usr/bin/python
#
# transpose.py (C) 2012 Yrjo Kari-Koskinen <ykk@peruna.fi>
#
# This program is licensed under Version 2 of the GPL.
#
# Transpose utf-8 string columns as rows and vice versa
# You might need to set PYTHONIOENCODING=utf_8 before calling transpose.py
import sys
@ykarikos
ykarikos / png2svg.sh
Created Jun 7, 2012
Convert png to svg using imagemagick and potrace
View png2svg.sh
#!/bin/bash
if [ "$1" == "" ]; then
echo Usage: $0 pngfile
exit 0;
fi
FILE=`basename $1 .png`
if [ ! -e $FILE.png ]; then
@ykarikos
ykarikos / gist:3511914
Created Aug 29, 2012
Imperative Java Shit
View gist:3511914
private String getCustomerKeys(List<Customer> customers) {
StringBuilder keys = new StringBuilder();
if (customers != null) {
for (Customer customer: customers) {
if (keys.length() > 0) {
keys.append(", ");
}
keys.append(customer.customerKey.toString());
}
return keys.toString();
@ykarikos
ykarikos / label.bst
Created Sep 12, 2012
BibTeX bibliography style `label'
View label.bst
% BibTeX bibliography style `label'
% Modified from the `alpha' style
% Changes:
% * New entry labelkey added. If it is present, it will be used as the
% label. Otherwise the alpha style label is used.
% * The first line of the bibliography will contain only the label.
% * The command \textsc will be removed from the beginning of the labelkey
% for sorting (see the sortifysc function).
% * New entries url and ref added. If url is nonempty it will be typeset
@ykarikos
ykarikos / charFrequency.py
Last active Dec 10, 2015
Count character frequencies
View charFrequency.py
#!/usr/bin/python
# charFrequency.py (C) 2013 Yrjo Kari-Koskinen <ykk@peruna.fi>
#
# This program is licensed under Version 2 of the GPL.
#
# Use PYTHONIOENCODING=utf_8 environment variable to read and write utf8 to files.
import sys, unicodedata
def letter(l):
@ykarikos
ykarikos / random-letters.py
Last active Dec 14, 2015
Select random letters according to the distribution of letters in Finnish language
View random-letters.py
#!/usr/bin/python
# Select random letters according to the distribution of letters in Finnish language:
# https://docs.google.com/spreadsheet/ccc?key=0AiZHeDrg3BuddFZfTXVnclQ5UWNkaGVuWmdVT3dzMEE&usp=sharing
# Ignore the uncommon letters c, z, w, q, x and ao
import random
from itertools import repeat
from collections import Counter