Skip to content

Instantly share code, notes, and snippets.

View timsgardner's full-sized avatar

Tims Gardner timsgardner

  • Arcadia Technologies
  • Brooklyn, NY
View GitHub Profile
@timsgardner
timsgardner / gist:4c5bd1c685b26c8d5a03
Created December 27, 2014 21:28
invocation time
(defn time-it
"Signature slightly awkward to resemble that of time-it-mac"
([f] (time-it f 1))
([n f]
(. clojure.lang.RT (StartStopwatch))
(dotimes [_ n] (f))
(let [t (. clojure.lang.RT StopStopwatch)]
(/ t n))))
(defmacro time-it-mac
(ns invocation-cost)
(defn time-it
"Signature slightly awkward to resemble that of time-it-mac"
([f] (time-it f 1))
([n f]
(. clojure.lang.RT (StartStopwatch))
(dotimes [_ n] (f))
(let [t (. clojure.lang.RT StopStopwatch)]
(/ t n))))
@timsgardner
timsgardner / clesgo.clj
Last active August 29, 2015 14:12
clesgo
(ns madness)
(defn reset []
((fn clesgo [n]
(defn go-clesgo [m]
(clesgo (+ n m)))
n)
1))
(defn abandon-hope []
invocation-cost=> (time-it-mac 1e6 ((fn [x] x) :hi))
0.012968
invocation-cost=> (let [f (fn [x] x)]
(time-it-mac 1e6 (f :hi)))
1.1E-05
@timsgardner
timsgardner / unchecked.clj
Created January 28, 2015 04:14
unchecked
(defn unchecked-on []
(alter-var-root #'*unchecked-math* (constantly true)))
(defn unchecked-off []
(alter-var-root #'*unchecked-math* (constantly false)))
@timsgardner
timsgardner / array-mac.clj
Last active August 29, 2015 14:14
array-mac
(defmacro array-mac [t & elements]
(let [^Type tt (resolve t)
atypesym (symbol (str (.FullName tt) "[]"))
asym (gensym "array_")
setexprs (->> elements
(map-indexed
(fn [i x]
`(aset ~asym ~i ~x))))]
`(let [~(with-meta asym {:tag atypesym}) (make-array ~t ~(count elements))]
~@setexprs
@timsgardner
timsgardner / vector_reader.clj
Created January 28, 2015 08:07
vector reader
(binding [*data-readers* {'v3 (fn [[x y z]] (UnityEngine.Vector3. x y z))}]
(eval (read-string "#v3[1 2 3]")))
;; => (1.0, 2.0, 3.0)
@timsgardner
timsgardner / def_compget.clj
Last active August 29, 2015 14:14
def-compget
(defmacro condcast-> [expr xsym & clauses]
(let [exprsym (gensym "exprsym_")
[clauses default] (if (even? (count clauses))
[clauses nil]
[(butlast clauses)
[:else
`(let [~xsym ~exprsym]
~(last clauses))]])
cs (->> clauses
(partition 2)
@timsgardner
timsgardner / axis_angle.cs
Last active August 29, 2015 14:14
axis angle
using clojure.lang;
using System;
using UnityEngine;
namespace urbanOutfitters.moholy
{
[Serializable] // really?
public class axis_angle : AFunction
{
//
// Static Fields
@timsgardner
timsgardner / fuzzy_finder_fn.clj
Created February 5, 2015 04:10
fuzzy-finder-fn
(defn fuzzy-finder-fn [name-fn resource-fn]
(fn [string-or-regex]
(let [f (if (instance? System.Text.RegularExpressions.Regex string-or-regex)
#(re-find string-or-regex (name-fn %))
(let [^String s string-or-regex]
#(let [^String n (name-fn %)]
(.Contains n s))))]
(filter f (resource-fn)))))
;; example: