Skip to content

Instantly share code, notes, and snippets.

View jkpl's full-sized avatar

Jaakko Pallari jkpl

View GitHub Profile
@jkpl
jkpl / macros.py
Created May 12, 2015 14:51
Macros for Poole
import os
import json
import iso8601
from datetime import datetime
from lesscss import LessCSS
# Defaults
page = {}
pages = []
@jkpl
jkpl / spotify.py
Created May 30, 2015 18:47
Spotify lookup in command line
#!/usr/bin/python
import urllib
import sys
import json
import re
SP_REGEX = re.compile('^http://[\S]+/track/([\S]+)')
SP_LOOKUP_BASEURL = 'http://ws.spotify.com/lookup/1/.json?uri=spotify:track:%s'
@jkpl
jkpl / spotifyctrl.sh
Created May 30, 2015 18:50
Spotify app controls in command line
#!/bin/bash
SPOTIFYCMD="dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player."
function spotify_oper {
${SPOTIFYCMD}$1
}
case $1 in
"play")
@jkpl
jkpl / box.js
Created July 28, 2015 21:38
Promise based queue
function mkBox() {
var box = {values: [], reads: []};
box.enq = function(value) {
box.values.push(value);
if (box.reads.length > 0) {
box.reads.shift().resolve(box.values.shift());
}
return box;
};
@jkpl
jkpl / ActorSequence.scala
Created August 6, 2015 08:22
Sequence of Akka actors
package shardaus
import akka.actor._
import scalaz._
import Scalaz._
object ActorSequence {
type SequenceProp = ActorRef => Props
@jkpl
jkpl / Striimaus.scala
Created August 12, 2015 10:24
Shoddy Akka Kafka example
package striimaus
import java.util.Properties
import akka.actor._
import akka.persistence.{Persistence, PersistentActor, PersistentView}
import com.typesafe.config.{Config, ConfigFactory}
import kafka.consumer._
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import kafka.serializer.StringDecoder
@jkpl
jkpl / AinakinKerran.scala
Last active September 10, 2015 10:11
At least once delivery with async persistence
package ainakin.kerran
import akka.actor._
import akka.persistence.{AtLeastOnceDelivery, PersistentActor}
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
object AinakinKerran {
def start(): Unit = {
val as = ActorSystem("AinakinKerran", ConfigFactory.load("common"))
@jkpl
jkpl / VirtaDekoodaus.scala
Last active September 10, 2015 10:11
Async stream decoding using scodec
package virta.dekoodaus
import java.nio.charset.Charset
import java.util.concurrent.Executors
import scodec.Codec
import scodec.bits.BitVector
import scodec.codecs._
import scodec.stream._
import scodec.stream.decode.StreamDecoder
@jkpl
jkpl / showkeepassx.sh
Created September 12, 2015 18:33
Script for showing/hiding KeepassX window. Bind to a global shortcut for max power.
#!/bin/sh -e
function xdokeepassx {
xdotool search --maxdepth 3 --classname keepassx $@
}
function show_keepassx {
local desktop="`xdotool get_desktop`"
xdokeepassx \
set_desktop_for_window %@ $desktop \
@jkpl
jkpl / to_csv.sh
Created September 13, 2015 12:48
Batch convert OpenDocument spreadsheets to CSV using LibreOffice
#!/bin/sh -e
LO_PROFILE_DIR="/tmp/LO_conversions"
libreoffice \
"-env:UserInstallation=file://$LO_PROFILE_DIR" \
--headless --invisible \
--convert-to csv *.ods \
--outdir csv