Skip to content

Instantly share code, notes, and snippets.

View Kah0ona's full-sized avatar

Marten Sytema Kah0ona

View GitHub Profile
jQuery(document).ready(function($){
$('.tabs').click(function(evt){
evt.preventDefault();
$('.tabtargets').hide();
var clicked = $(evt.currentTarget);
var toShow = clicked.attr('data-target');
$(toShow).show();
});
@Kah0ona
Kah0ona / Solving 24 flippo's
Created March 2, 2015 19:36
solve a flippo by using t [2,2,7,1]
import Data.List
t :: [Double] -> [[Char]]
t f =
let
perms = permutations f
opers = [("+", (+)), ("-", (-)), ("*", (*)), ("/" ,(/))]
in
["(((" ++ (show $ truncate a) ++ n1 ++ (show $ truncate b) ++ ")" ++ n2 ++ (show $ truncate c) ++ ")" ++ n3 ++ (show $ truncate d) ++ ")" |
[a ,b ,c ,d ] <- perms,
@Kah0ona
Kah0ona / testcase.clj
Created July 25, 2016 12:33
Testcase addition for url encoding.
(deftest complex-params-to-str
; other clauses.
(is (= "d=b%20c" (params-to-str {"d" "b c"})))
(is (= "d=b%20%26%20c" (params-to-str {"d" "b & c"}))))
@Kah0ona
Kah0ona / test.clj
Created September 7, 2017 19:39
Transducer that merges consecutive elements if they are similar
(declare merge-peak-with-first)
(defn concatenate-similar-peaks-xf []
(fn [xf]
(let [prev (volatile! ::none)]
(fn
([] (xf))
([result] (xf result))
([result input]
(let [prior @prev]
| :time | :pace | :speed |
|----------+-------+------------|
| 02:30:00 | 3:33 | 16.88 km/h |
| 02:30:30 | 3:34 | 16.82 km/h |
| 02:31:12 | 3:35 | 16.74 km/h |
| 02:31:54 | 3:36 | 16.67 km/h |
| 02:32:37 | 3:37 | 16.59 km/h |
| 02:33:19 | 3:38 | 16.51 km/h |
| 02:34:01 | 3:39 | 16.44 km/h |
| 02:34:43 | 3:40 | 16.36 km/h |
@Kah0ona
Kah0ona / marathonpaces.txt
Created November 10, 2019 13:06
Marathon paces
| 02:48:47 | 4:00 min/km | 15.0 km/h |
| 02:49:29 | 4:01 min/km | 14.9 km/h |
| 02:50:11 | 4:02 min/km | 14.9 km/h |
| 02:50:54 | 4:03 min/km | 14.8 km/h |
| 02:51:36 | 4:04 min/km | 14.8 km/h |
| 02:52:18 | 4:05 min/km | 14.7 km/h |
| 02:53:00 | 4:06 min/km | 14.6 km/h |
| 02:53:42 | 4:07 min/km | 14.6 km/h |
| 02:54:25 | 4:08 min/km | 14.5 km/h |
| 02:55:07 | 4:09 min/km | 14.5 km/h |
@Kah0ona
Kah0ona / half_marathon.txt
Created November 21, 2019 10:55
paces halve marathon
| :time | :pace | :speed |
|----------+-------------+-----------|
| 01:20:00 | 3:47 min/km | 15.8 km/h |
| 01:20:11 | 3:48 min/km | 15.8 km/h |
| 01:20:32 | 3:49 min/km | 15.7 km/h |
| 01:20:53 | 3:50 min/km | 15.6 km/h |
| 01:21:14 | 3:51 min/km | 15.6 km/h |
| 01:21:35 | 3:52 min/km | 15.5 km/h |
| 01:21:56 | 3:53 min/km | 15.4 km/h |
| 01:22:17 | 3:54 min/km | 15.4 km/h |
@Kah0ona
Kah0ona / script.clj
Created March 29, 2020 15:09
Clojure script to count number of chats per person from WhatsApp export
(ns user
(:require [clojure.string :refer [lower-case includes? trim]]))
(defn parse-line
"Returns the name of the message, or nil if it can't be found"
[l]
(->> l
trim
(re-find #"\[.{19}\].(.[A-Za-z\ \-]+):")
second))
(ns user
(:require [clojure.string :as string]))
(defn ⁵
"Returns n to the fifth power.
Note we use the UTF-character of superscript-5 as function name, because we can. ;-)"
[n]
(let [sq (* n n)]
(* sq sq n)))
@Kah0ona
Kah0ona / fails.clj
Created March 9, 2021 08:42
catching asserts inside a future body fails silently, but why?
(future
(try
(println "inside future body")
(assert false) ;;
(catch Exception e
(println "error" (.getMessage e))))) ;; no error printed
(try ;; not in a future, but just normal
(println "inside future body")