Skip to content

Instantly share code, notes, and snippets.

@oskarth
oskarth / gates.clj
Created November 1, 2012 17:45
chipper.gates
;; nand* is not defined in terms of other gates
;; read the source to find out how we deal with that
(defgate not* [in] => [out]
(nand* [in in] => [out]))
(defgate and* [a b] => [out]
(nand* [a b] => [w])
(not* [w] => [out]))
@oskarth
oskarth / long.clj
Created November 1, 2012 18:07
chipper.long-form.gates
(defn nand* [a b]
(let [[out] (if (= 2 (+ a b)) [0] [1])
out))
(defn not* [in]
(let [[out] (nand* in in)]
out))
(defn and* [a b]
(let [[w] (nand* a b)
@oskarth
oskarth / core.clj
Created November 1, 2012 17:31
chipper.core
(defn- arrow?
"predicate that returns true if x is =>"
[x]
(and (symbol? x) (= (name x) "=>")))
(defn- split-body
"splits expression into two parts, one with input
pins and the other with => and outputs"
[body]
(split-with (complement arrow?) body))
@oskarth
oskarth / stacktrace
Created December 5, 2012 19:55
clojurescript reflex computed-observables
;; using reflex clojurescript library
;; works
(def a (atom 0))
(def b (computed-observable (inc @a)))
(def c (computed-observable (dec @a)))
(def d (computed-observable (str @b)))
;; doesn't
;; maximum call stack exceeded
$ znc --version
ZNC 0.206+deb1 - http://znc.in
$ which znc
/usr/local/bin/znc
$ /usr/local/bin/znc --version
ZNC 1.1-git-20121207-8ffab186 - http://znc.in
IPv6: yes, SSL: yes, DNS: threads
@oskarth
oskarth / gist:4260501
Created December 11, 2012 17:33
minikanren break
#lang r5rs
;; chapter 3 minikanren
(define-syntax var
(syntax-rules ()
((_ x) (vector x))))
(define-syntax var? (syntax-rules ()
((_ x) (vector? x))))
##
## Arch Linux repository mirrorlist
## Generated on 2013-07-08
##
## Germany
#Server = https://archlinux.limun.org/$repo/os/$arch
## Greece
#Server = https://foss.aueb.gr/mirrors/linux/archlinux/$repo/os/$arch
@oskarth
oskarth / rands.py
Created March 20, 2016 16:08
Precomputing a series of 5 As and 5 Bs in a secret random order.
# Usage:
# python rands.py
#
# head -n 1 output
# head -n 2 output
# etc...
import random
f = open('output', 'w')
lst = [0]*5 + [1]*5
@oskarth
oskarth / flushfun.clj
Created July 13, 2016 15:35
Flush fun lightning talk
(ns flushfun.core
(:require [clojure.core.async :refer [chan go go-loop close! <!! timeout]]
[amazonica.aws.sqs :as sqs]))
(def queue (sqs/find-queue {:endpoint "eu-west-1"} "flushfun"))
(defn commit-fn [message] (fn [] (sqs/delete-message (assoc message :queue-url queue))))
(defn flush-messages [{:keys [messages commits]}]
(println "FLUSHING" (map :body messages))
@oskarth
oskarth / Example output
Last active February 6, 2017 08:36
Script to generate Ledger entries that distribute a cost over several days
➜ finance git:(master) ✗ ./bin/distribute-cost Expenses:Misc:Buffer 150 USD 2017/02/01 28
Expenses:Misc:Buffer 0.20 USD ; [=2017/02/01]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/01]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/02]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/03]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/04]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/05]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/06]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/07]
Expenses:Misc:Buffer 5.35 USD ; [=2017/02/08]