Skip to content

Instantly share code, notes, and snippets.

View halgari's full-sized avatar

Timothy Baldridge halgari

View GitHub Profile
#include "Python.h"
static PyObject *simple_example(PyObject *self, PyObject *args)
{
PyObject *x;
x = PyTuple_GetItem(args, 0);
PyObject *zero = PyInt_FromLong(0);
if (PyObject_RichCompareBool(x, zero, Py_EQ))
{
Py_DECREF(args);
(defn wrap-foo [foo]
(reify
IFn
(invoke [this arg]
(.myMethod foo arg))
IDeref
(deref [this]
foo)))
(def adder
(fn [x]
(fn [y]
(+ x y))))
(def add5 (adder 5))
(add5 3)
=> 8
(gen-plan
[a (assert-entity {:foo 42})
b (if pred?
(assert-entity {:a a :bar b})
(no-op))]
b)
(def philostate
(let [c (chan)]
(go (loop [state {:socrates :thinking
:plato :thinking
:hickey :thinking
:sussman :thinking
:stroustrup :thinking}]
(let [f (<! c)
new-state (f state)]
(defn make-read-only [c]
(reify clojure.core.async.impl.protocols/ReadPort
(take! [port handler]
(clojure.core.async.impl.protocols/take! c handler))))
(println (<!! (make-read-only (go 42))))
(let [error-chan (chan)]
(go
(try
...
(catch Exception ex (>! error-chan ex)))))
(ns hoare.problem
(:require [clojure.core.async :refer :all]))
(defn fan-in
([ins] (fan-in (chan) ins))
([c ins]
(go (while true
(let [[x] (alts! ins)]
(>! c x))))
c))
(defn close-at-end [x file]
(if x
(cons (first x) (lazy-seq (close-at-end (next x) file)))
(do (.close file)
nil)))
(defn throttle-chan [input]
(let [throttle-chan (chan)
output-chan (chan)]
(go
(loop [throttle-msec nil]
(let [t-chan (when (= :disabled throttle-msec)
(timeout throttle-msec))
[val c] (alt! [input throttle-chan])]
(if (= c throttle-chan)
(recur val)