Skip to content

Instantly share code, notes, and snippets.

@lepoetemaudit
lepoetemaudit / Tests.md
Last active August 29, 2015 14:21
Tests.md

Sum

sum1(1, 2, 3) == 6

Fizzbuzz

1 1
2 2
3 Fizz

4 4

@lepoetemaudit
lepoetemaudit / ws-state-machine.clj
Last active September 13, 2021 02:17
Dummy implementation a websocket server via a state machine in Clojure
(ns tokichat.core
(:use org.httpkit.server)
(:gen-class))
(defn handler [req]
(with-channel req channel
(on-close channel (fn [status]
(println "channel closed")))
"""
Extremely crude example of a timing attack
"""
import time
import timeit
actualPassword = '0BEA0239'
def checkpassword(passwd):
@lepoetemaudit
lepoetemaudit / toki_pona_nanpa.fs
Created August 14, 2015 10:28
Tail-recursive Toki Pona number to string function
let numberToTokiPona num =
let rec addNum num str =
if num >= 2 then addNum (num-2) (str + "twu ")
else if num = 1 then addNum (num-1) (str + "wan ")
else str
if num > 0 then addNum num ""
else "ala"
(numberToTokiPona 19) |> printfn "%s"
@lepoetemaudit
lepoetemaudit / mailbox_chat.fs
Created August 14, 2015 12:54
F# mailboxes
open System.Threading
type ChatMessage =
| SendMessage of string
| GetContent of AsyncReplyChannel<string list>
let agent = MailboxProcessor.Start(fun agent ->
let rec loop (state : string list) = async {
printfn "List length is now %d" state.Length
@lepoetemaudit
lepoetemaudit / async.fs
Last active August 29, 2015 14:27
F# Async.Parallel
open FSharp.Data
open System.Threading
["http://bbc.co.uk"; "http://www.google.co.uk"]
|> List.map (fun str ->
async {
let! html = Http.AsyncRequestString(str)
return sprintf "bbc len %d" html.Length
}
)
@lepoetemaudit
lepoetemaudit / toki_pona_nanpa.ml
Created August 25, 2015 23:13
The Toki Pona number converter implementation ported from F# to Ocaml
let numberToTokiPona num =
let rec addNum num str =
if num >= 2 then addNum (num-2) (str ^ "twu ")
else if num = 1 then addNum (num-1) (str ^ "wan ")
else str
in
if num > 0 then addNum num ""
else "ala";;
print_string (numberToTokiPona 19);;
@lepoetemaudit
lepoetemaudit / toki_pona_nanpa.clj
Created August 26, 2015 20:05
Toki Pona numbers in Clojure ported from OCaml
(defn numberToTokiPona [num]
(clojure.string/join " "
(loop [n num strs []]
(cond
(> n 1) (recur (- n 2) (conj strs "twu"))
(= n 1) (recur (- n 1) (conj strs "wan"))
:else strs))))
@lepoetemaudit
lepoetemaudit / toki_pona_nanpa.py
Created August 27, 2015 09:09
Toki Pona number conversion in Python
tokiPona = lambda num: (num / 2) * "twu " + ("wan" if num % 2 else "")
@lepoetemaudit
lepoetemaudit / polishnotation.clj
Last active October 27, 2015 15:32
Macro for polish notation (prefix, i.e. not postfix RPN) in Clojure
(defmacro pln [& args]
(let [operator-count (dec (/ (count args) 2))
operators (take operator-count args)
values (drop operator-count args)
op-vals (map vector operators (next values))]
(loop [form (first values)
op-vals op-vals]
(if (not-empty op-vals)