Skip to content

Instantly share code, notes, and snippets.

View aperiodic's full-sized avatar

Dan Lidral-Porter aperiodic

  • BlackBerry
  • Seattle, WA
View GitHub Profile
(defn remove-first [pred coll]
(let [[xs ys] (split-with (complement pred) coll)]
(concat xs (rest ys))))
(definterface FirstRemover
(^clojure.lang.LazySeq removeFirst [coll]))
(definterface FirstRemoverFactory
(^user.FirstRemover makeRemover [pred]))
(defn remove-first
[pred coll]
(apply concat ((juxt take-while (comp rest drop-while)) (complement pred) coll)))
(remove-first (partial = 3) [1 2 3 1 2 3])
;;; (1 2 1 2 3)
(remove-first even? [1 2 3 1 2 3])
;;; (1 3 1 2 3)
@timmc
timmc / rest.swear.clj
Last active December 15, 2016 15:24
rest in curje [now called swearjure]
;; An exercise in writing #'rest without [0-9a-zA-Z], by Tim McCormack
;; Note that the input must be a vector, although the code could easily be
;; modified to vector-ify any input coll.
;; Let's take this a step at a time...
(#(((% 1) :main) %) ;; call the main method with the input and fns
[[0 1 2 3 4 5] ;; the input is hardcoded here
;; fns are accessed by static indices into the fn table
{:main #(if (= (% 0) [])
@timmc
timmc / fact.swear.clj
Last active July 5, 2022 13:34
Factorial in Clojure without using alphanumeric characters
;; It all started here: http://clojure-log.n01se.net/date/2011-04-06.html#19:04
(#((% (+(*))) %) ;; call arg 1 with all args
[;; data
(+ (*)(*)(*)(*)(*)(*)(*))
;; main fn -- simulate 'if' with map lookup and closures
#(({(+) (% (+(*)(*)))} ;; if zero return 'then' clause
(% (+)) ;; dispatch on first arg
(% (+(*)(*)(*)))) ;; call 'else' clause (n not found in map)
%)
import SimpleOpenNI.*;
import processing.opengl.*;
SimpleOpenNI kinect;
boolean running = false;
boolean devinMode = false;
boolean debug = true;