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 / defstg.clj
Created October 18, 2014 20:29
defstg
(defmacro defstg [name & body]
`(do (declare ~name)
(let [bldg# (do ~@body)]
(when-not
(instance? clojure.lang.Var+Unbound
(var-get (resolve (quote ~name))))
(destroy ~name))
(def ~name bldg#))))
@timsgardner
timsgardner / condcast_example.clj
Last active August 29, 2015 14:08
condcast-> example
(import '[UnityEngine Quaternion Vector3])
(set! *warn-on-reflection* true)
;; note this takes an optional default value. This macro is potentially
;; annoying in the case that you want to branch on a supertype, for
;; instance, but the cast would remove interface information. Use with
;; this in mind.
(defmacro condcast-> [expr xsym & clauses]
(let [exprsym (gensym "exprsym_")
@timsgardner
timsgardner / quaternion_exploration.clj
Last active July 13, 2016 01:21
Playing around with quaternions in Arcadia
(ns quaternion-exploration
(:import [UnityEngine Quaternion Vector3])
(:use arcadia.core
arcadia.hydrate
clojure.repl
clojure.pprint))
;; like emacs. kind of.
(defn kill! [x]
(let [spec (dehydrate x)]
@timsgardner
timsgardner / set_with.clj
Last active August 29, 2015 14:08
set-with!
;; funny little macro to make interop bit less painful
(set! *warn-on-reflection* true)
(defmacro set-with! [obj [sym prop] & body]
`(let [obj# ~obj
~sym (. obj# ~prop)]
(set! (. obj# ~prop) (do ~@body))))
;; use: ----------------------------------------
(def ^:dynamic *x* :default-x)
(def ^:dynamic *y* :default-y)
(def ^:dynamic *z* :default-z)
(def ^:dynamic *opts* {:x *y* :y *z* :z *x*})
(defn awesome-fn [f x y z & {:as opts
:keys [x y z]
:or {x *x*
y *y*
(require '[clojure.string :as s])
(set! *print-length* nil)
(def starspeck-raw
(vec
(s/split-lines
(slurp "/Volumes/DUv3_9pview/Digital Universe/data/milkyway/specks/stars.speck"))))
(let [fields
[:x :y :z :colorb-v :lum :absmag :appmag :texnum :distly :dcalc :plx :plxerr :vx :vy :vz :speed :hipnum]]
;; at the moment, array population works by swapping out existing
;; array for new one (possibly of greater length). Should work for
;; components, which copy their arrays anyway, might be problematic in
;; other cases though. wonder if this will even work in the case of eg
;; meshes, or if some other setting pattern is needed. This whole
;; thing is kind of sketchy, treatment of arrays breaks idea of spec
;; type agnosticism.
(defn- set-clause-array-populate [setable ctx]
(let [et (element-type ...)]
`(let [~instsym (. ~targsym ~name)
using clojure.core.protocols;
using clojure.lang;
using compile__stub.clojure.core;
using Microsoft.Scripting.Utils;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
namespace clojure.core
{
(defn problematic-case-fn [x]
(case x
:xnw "xnw" :ltg "ltg" :qmu "qmu" :tff "tff" :btw "btw" :zpo "zpo" :dsq "dsq" :tvk "tvk" :iey "iey" :vut "vut" :qyg "qyg" :xgj "xgj" :bpa "bpa" :pgk "pgk" :ovf "ovf" :wqi "wqi" :vwd "vwd" :nfn "nfn" :une "une" :iru "iru" :eyu "eyu" :lfa "lfa" :mmh "mmh" :fze "fze" :siv "siv" :ggq "ggq" :yrf "yrf" :zcz "zcz" :uhl "uhl" :xiu "xiu" :mpi "mpi" :rxa "rxa" :wlg "wlg" :jgi "jgi" :cur "cur" :gbv "gbv" :ddm "ddm" :dki "dki" :lai "lai" :kek "kek" :gia "gia" :dxz "dxz" :tlg "tlg" :odc "odc" :xvx "xvx" :cdg "cdg" :zes "zes" :hci "hci" :voh "voh" :cmu "cmu" :ucc "ucc" :psw "psw" :eia "eia" :tao "tao" :elp "elp" :hzj "hzj" :mux "mux" :twh "twh" :uuy "uuy" :qkj "qkj" :tbu "tbu" :ply "ply" :xws "xws" :ztw "ztw" :gky "gky" :egz "egz" :cwu "cwu" :bby "bby" :usv "usv" :cun "cun" :nlo "nlo" :gvu "gvu" :rdk "rdk" :bla "bla" :ddu "ddu" :yrz "yrz" :xej "xej" :imk "imk" :kfm "kfm" :xvw "xvw" :cre "cre" :eqo "eqo" :rnd "rnd" :otf "otf" :ubf "ubf" :aqn "aqn" :xmx "xmx" :cxf "cxf" :dvx "dvx" :
@timsgardner
timsgardner / normal
Created November 29, 2014 02:36
case disassembly issue
public override object invoke (object obj)
{
string arg_4889_0;
switch (Util.hash (obj) >> 0 & 4095)
{
case 67:
if (obj == case_problem$unproblematic_case_fn__69.const__0)
{
arg_4889_0 = "lai";
return arg_4889_0;