Skip to content

Instantly share code, notes, and snippets.

@viperscape
viperscape / peek-drain.clj
Last active December 28, 2015 08:39
Quickly look at a core.async channel with only momentary blocking, pulls the data if it exists and thus alters the channel.Drain! will repeatedly call peek! until a maximum number of elements is pulled or until the channel is empty.
;;uses core.async and refers chan, >!, go, alts!! and timeout functions
(def c (chan))
(go (>! c {:msg "hi"}))
(defn peek! [ch & args]
"quickly looks at a channel for new incoming data, pulls it if it exists, quits otherwise;
returns seq if specifying max elements to pull"
(if-not (nil? args)
@viperscape
viperscape / matrix operations for 3d graphics.clj
Last active December 25, 2015 23:09
using core.matrix, perform some 3d graphics-related functions lookat, perspective projection, and building translation and rotation matrices; 'left' in the function name specifies left-handed coordinates
;; (ns somenamespace
;; (:refer-clojure :exclude [* - + == /])
;; (:use clojure.core.matrix)
;; (:use clojure.core.matrix.operators)
;; (:gen-class))
(defn inv [n] "returns the inverse, (* -1 n)" (* -1 n))
(defn projection [l r b t, n f, aspect fov]
@viperscape
viperscape / maps defentity's to the table listing in sql
Last active December 20, 2015 12:59
information schema to defentity in korma
(defentity INFORMATION_SCHEMA.tables)
(def tables (map #(get % :TABLE_NAME)
(select 'INFORMATION_SCHEMA.tables (fields :TABLE_NAME)
(where {:TABLE_TYPE "BASE TABLE"})))) ;notice the quote
(prn tables)
;(map #(def %) tables) ;additional concept
(map #(defentity %) tables) ;not sure this is required anymore
(select (first tables))