Skip to content

Instantly share code, notes, and snippets.

View ykarikos's full-sized avatar
🏡
Working from home

Yrjö Kari-Koskinen ykarikos

🏡
Working from home
  • Digitaalinen asuntokauppa DIAS
  • Helsinki
  • X @ykarikos
View GitHub Profile
@ykarikos
ykarikos / RandomLetters.scala
Last active December 14, 2015 01:39
Select random letters according to the distribution of letters in Finnish language
/**
* 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
@ykarikos
ykarikos / getFieldsAccessor.py
Last active December 18, 2015 11:39
A function that returns function that accesses a dict
#
# Third iteration, now with reduce!
#
def getFieldAccessor(fields):
return lambda a: reduce(lambda x, y: x[y], fields, a)
@ykarikos
ykarikos / gist:7831661
Created December 6, 2013 20:34
Scala stuff
// 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
// Install:
// npm install lodash request cheerio
// Usage:
// nodejs hwoteams.js
var request = require('request')
, cheerio = require('cheerio');
var fs = require('fs');
var _ = require('lodash');
@ykarikos
ykarikos / gist:0a4c13e6e349e2270b86
Last active August 29, 2015 14:06
convert bunch of avi files to mp4 for ipad with ffmpeg
for f in *.avi; do file=`basename "$f" .avi`; ffmpeg -i "$f" -acodec libfaac -ab 160000 -vcodec libx264 -b 1200k -threads 0 -f mp4 "$file.mp4"; done
@ykarikos
ykarikos / gist:25ebbb38e910c691a52d
Created September 26, 2014 09:14
Reaktor dev day Monads workshop exercise
-- #!/usr/bin/env runhaskell
import Control.Applicative
import Control.Monad
plus3 x = x + 3
data List a = Nil | Cons a (List a)
deriving (Show)
instance Functor List where
@ykarikos
ykarikos / create-tech-radar.py
Created October 28, 2014 09:15
Transform Tech radar questionnaire input into svg
#!/usr/bin/python
import sys
from math import sin, cos
prefix = """<svg width="800" height="800" xmlns="http://www.w3.org/2000/svg" >
<g transform="translate(400,400)">
<circle r="350" style="fill: rgb(190, 195, 230);"></circle>
</g>
<g transform="translate(400,400)">
@ykarikos
ykarikos / get-timezone-delta.clj
Created December 10, 2014 10:35
Calculate timezone difference between two dates
(defn get-timezone-delta [dateformat utc-time-string local-time-string]
(let [utc-time (f/parse dateformat utc-time-string)
local-time (f/parse dateformat local-time-string)
abs-delta (t/in-hours (t/interval (t/earliest utc-time local-time) (t/latest utc-time local-time)))]
(if (t/after? utc-time local-time)
(- abs-delta)
abs-delta)))
@ykarikos
ykarikos / backup.sh
Created December 29, 2014 12:32
Backup script
#!/bin/sh -e
HOME="/home/user"
HOST="foobar"
BACKUP_DIR="/var/backup/$HOST"
BACKUP_FILE="$HOST-`date -I`.tar.bz2.gpg"
MYSQL_FILE="mysql-`date -I`.bak.gpg"
RECIPIENT="me@myhost.com"
cd $BACKUP_DIR
@ykarikos
ykarikos / client repl.clj
Last active August 29, 2015 14:13
Full duplex Websocket connections with manifold streams and aleph http lib
user=> (use 'ws-test)
nil
user=> @state
{}
user=> (connect "localhost")
true
user=> @@connection
<< stream: {:type "splice", :sink {:type "netty", :sink? true, :closed? false}, :source {:pending-puts 0, :drained? false, :buffer-size 0, :permanent? false, :type "manifold", :sink? true, :closed? false, :pending-takes 1, :buffer-capacity 16, :source? true}} >>
user=> (send-message @@connection {:msg "It works!" :count 1})
<< true >>