Skip to content

Instantly share code, notes, and snippets.

View postspectacular's full-sized avatar
Celebrating 24 years of building open source tools

Karsten Schmidt postspectacular

Celebrating 24 years of building open source tools
View GitHub Profile
jackrusher / dbpedia.clj
Created June 1, 2014 07:14
Some leftover code from a livecoding data gathering/analysis in Clojure workshop I taught in Berlin a few days ago. (N.B. This code is meant to help one understand the concepts involved -- if one were to put something like this in production, it'd be much better to use one of the many excellent open source libraries available for this purpose.)
;; semantic web data is often formatted as RDF/XML, but I think that
;; format is horrible, so I generally prefer to use something like
;; n-triples (N3):
;; for the sake of this gist we'll limit ourselves to the flavor of N3
;; produced by dbpedia
(def fetch-n3
"Fetch N3 data for a given dbpedia resource. Expects a URL like
gfredericks / brainfuck.clj
Last active August 29, 2015 14:02
A lazy brainfuck interpreter in Clojure
(ns brainfuck
"A lazy brainfuck interpreter.
Memory consists of a fixed-length array of bytes in the range
0..255, where arithmetic wraps around. Moving the data pointer
out of the range of memory throws a SEGFAULT error.
Input must be given as a string or sequence when calling one
of the eval functions, and if the program tries to read after
input has been exhausted an exception will be thrown.")
# Welcome to Sonic Pi v2.0
use_bpm 140
in_thread do
loop do
4.times do
3.times do
sample :ambi_choir, amp: 0.8
sleep 2
ykarikos / client repl.clj
Last active August 29, 2015 14:13
Full duplex Websocket connections with manifold streams and aleph http lib
user=> (use 'ws-test)
user=> @state
user=> (connect "localhost")
user=> @@connection
<< stream: {:type "splice", :sink {:type "netty", :sink? true, :closed? false}, :source {:pending-puts 0, :drained? false, :buffer-size 0, :permanent? false, :type "manifold", :sink? true, :closed? false, :pending-takes 1, :buffer-capacity 16, :source? true}} >>
user=> (send-message @@connection {:msg "It works!" :count 1})
<< true >>
(ns sliders)
(defmacro slider [l]
(let [dashes (vec (repeat l "-"))]
`(do ~@(map (fn [i]
~(symbol (clojure.string/join (assoc dashes i "*")))
~(/ i (- l 1))))
(range l)))))
krisleech /
Last active August 29, 2015 14:18
ReAgent Introduction


Reagent binds components to data using an atom. An atom is a ClojureScript reference type. An atom references an immutable value, but the reference itself is mutable, it can be changed using reset! and swap! to reference a different imumtable value. Changes to atom's are atomic.

The value can be retrived by dereferencing the atom using deref or the @ prefix.

Functions can be attached to atoms to watch for changes, the function will get the atoms old and new state as arguments.

Reagent provides its own atom, reagent/atom, which has watches setup to rerender compontents which reference the atom.

paniq / tet.csp
Last active August 29, 2015 14:19
render tetrahedron without vertex buffers
; shader
(compile-program tet-pg
(#version 150)
(#include "lib/ext.glsl")
(#include "lib/projection.glsl")
(#include "lib/hslhsv.glsl")
(#escape ubo_decls)
(import LLVM
(let [module (LLVM/ModuleCreateWithName "my_module")
params (into-array [(LLVM/Int32Type) (LLVM/Int32Type)])
fntyp (LLVM/FunctionType (LLVM/Int32Type) params false)
lspector / evolvegeo.clj
Created December 9, 2011 17:27
Clojure code for a simple genetic programming system with trivial geography, for demonstration purposes.
;; Lee Spector ( 20111018 - 20111121
(ns evolvegeo
(:require [ :as zip]))
;; Like evolvefn.clj (, this this code
;; defines and runs a genetic programming system on the problem
;; of finding a function that fits a particular set of [x y] pairs.
;; Unlike evolvefn.clj, this code incorporates trivial geography
;; (
fogus / generative.clj
Created June 27, 2012 19:45 — forked from cemerick/generative.clj
"Integrating" clojure.test and test.generative
;; My good-enough glomming together of clojure.test and test.generative
(ns cemerick.generative
(:require [clojure.test.generative.generators :as gens]
[clojure.test.generative :as gen])
(:use clojure.test))
;; Too bad last-report isn't sent an action upon success as well.
;; Perhaps this should just be replaced with a try/catch/rethrow
;; around the body in defspectest