Skip to content

Instantly share code, notes, and snippets.

View theikkila's full-sized avatar

Teemu Heikkilä theikkila

View GitHub Profile
@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)
}
(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 / 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:
@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
(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 / 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;
@theikkila
theikkila / vanilla-cookies.js
Last active August 29, 2015 14:18
Vanilla Cookie support for angular
var module = angular.module('CookieModule', []);
module.service('ckeystore', function(){
this.get = function (sKey, fromJson) {
if (!sKey) { return null; }
var value = decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
if (fromJson) {return JSON.parse(value); } else { return value; }
};
this.set = function (sKey, sValue, vEnd, sPath, sDomain, bSecure, toJson) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
@theikkila
theikkila / cloud-config.yml
Created February 16, 2015 21:34
CloudInit on UpCloud
#cloud-config
write_files:
- path: /run/cloud-config.yml
permissions: '0644'
content: |
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB....
<h1 id="protokollakuvaus">Protokollakuvaus</h1>
<script src="http://cdn.rawgit.com/knsv/mermaid/master/dist/mermaid.full.min.js"></script>
<h2 id="yleisesti">Yleisesti</h2>
<p>Kaikki Nodet pitävät listaa muista nodeista</p>
<p>esim klusteri G = {A, B, C, D}
<div class="mermaid">
graph TD;
A---B;
B---C;
C---A;
@theikkila
theikkila / keywords.json
Last active January 5, 2025 01:54
7000 skill keywords
[
"Automotive",
"Budgeting",
"HVAC",
"Heaters",
"Hydraulics",
"Logistics Management",
"Management",
"Negotiation",
"Project Planning",