Skip to content

Instantly share code, notes, and snippets.

View theikkila's full-sized avatar

Teemu Heikkilä theikkila

View GitHub Profile
@theikkila
theikkila / convert.js
Last active November 4, 2015 15:14
Dec -> base27
function checkletter (s) {
lcount = 26; // 26 letters
var i = 0;
var csum = s.split('').reduce(function(sm, c, idx) {
var n = c.charCodeAt(0)-65;
if (idx % 2 == 0) {
return sm + n;
} else {
return sm + n*2;
(defn auth-middleware [req]
(let [auth-headers (get-in req [:headers :auth])]
(assoc req :user
(if (= auth-headers "secret")
{:name "Secret User"}
nil))))
@theikkila
theikkila / spuce.rb
Last active April 14, 2017 11:31 — forked from rambo/spuce.rb
Edited spuce formula to fix compile problems
class Spuce < Formula
desc "A C++ library for DSP filters"
homepage "http://pyspuc.com"
head "https://github.com/audiofilter/spuce.git"
url "https://github.com/audiofilter/spuce/archive/0.4.3.tar.gz"
version "0.4.3"
sha256 "5688e107b57640ba0485790d64eb16bff855f54f6fa5b2fdab568ee91f6dc687"
depends_on "cmake" => :build
depends_on :python
@theikkila
theikkila / clojutils.clj
Last active February 9, 2018 15:58
Collection of clojure utilities and macros
(defmacro first-do
"Executes first expression of do-block and returns it's result after the rest of the body"
[fexpr & body]
`(let [a# ~fexpr]
(do ~@body a#)))
; EXAMPLE:
(def defaults {:a ["default-a"]
:b ["default-b"]
:c ["default-c"]
:d ["default-d"]})
(def ex1 [:a 1 2 :b 4 5 :c :d])
@theikkila
theikkila / ramdaReceipts.js
Created June 13, 2017 14:03
Ramda receipts
const partitionBy = (f, collection) => {
const r = collection.reduce(({result, currentPartition, partitions}, item) => {
const newResult = f(item)
if (result != undefined && result != newResult) {
return {result: newResult, currentPartition: [item], partitions: R.append(currentPartition, partitions)}
}
return {result: newResult, currentPartition: R.append(item, currentPartition), partitions}
}, {result: undefined, currentPartition:[], partitions: []})
return R.append(r.currentPartition, r.partitions)
}
@theikkila
theikkila / logstashes.sh
Created July 24, 2017 12:19
Logstash plans
# Read files from /log/*.json and output them into listening tcp-server
logstash -e 'input { file { path => "/log/*.json" } } output { tcp { host => "0.0.0.0" port => 3333 mode => "server" codec => line { format => "%{message}" }} }'
from datetime import datetime
import pytz
import requests
today = datetime.now().strftime('%Y-%m-%d')
API_URL = 'https://rata.digitraffic.fi/api/v1/trains/{}'.format(today)
r = requests.get(API_URL)
package main
import (
"fmt"
"io"
"crypto/md5"
)
func md5hex(d string) string {
h := md5.New()
; Finnish date parser with EBNF parser
(require '[instaparse.core :as insta])
;
; "huomenna",
; "ylihuomenna",
; "eilen",
; "huomenna aamupäivällä",
; "huomenna aamupäivästä",