Yrjö Kari-Koskinen ykarikos

View gist:7831661
1 2 3
// Detect primes naively
def prime(x: Int): Option[Int] = if ((2 until x).forall(x % _ != 0)) Some(x) else None
def primeRatio(x: Int): Double = (x - (1 until x).map(prime).count(_ == None)).toDouble/x
View getFieldsAccessor.py
1 2 3 4 5
#
# Third iteration, now with reduce!
#
def getFieldAccessor(fields):
return lambda a: reduce(lambda x, y: x[y], fields, a)
View RandomLetters.scala
1 2 3 4 5 6 7 8 9 10
/**
* 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 å
*/
import scala.util.Random
 
object RandomLetters {
val rnd = Random
View random-letters.py
1 2 3 4 5 6 7 8 9
#!/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
View charFrequency.py
1 2 3 4 5 6 7 8 9 10
#!/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):
View label.bst
1 2 3 4 5 6 7 8 9 10
% 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
View gist:3511914
1 2 3 4 5 6 7 8 9 10
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();
View png2svg.sh
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
 
if [ "$1" == "" ]; then
echo Usage: $0 pngfile
exit 0;
fi
 
FILE=`basename $1 .png`
 
if [ ! -e $FILE.png ]; then
View transpose.py
1 2 3 4 5 6 7 8 9 10
#!/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
View gist:2411905
1
javascript:(function(){$(".board-widgets").hide();$("#board").css("width","98%");})();
Something went wrong with that request. Please try again.