Skip to content

Instantly share code, notes, and snippets.

@saikyun
saikyun / break
Last active July 20, 2018 09:41
Taken from Joy of Clojure by Fogus and Houser. Use (break) to get a repl in the spot were break was called.
(defn contextual-eval [ctx expr]
(eval
`(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)]
~expr)))
(defn readr [prompt exit-code]
(let [input (clojure.main/repl-read prompt exit-code)]
(if (= input ::tl)
exit-code
@saikyun
saikyun / gist:79750e99f0b504167fe59c58b1138772
Created December 28, 2018 09:44
Get source of function in arcadia + emacs.
(defun inf-clojure-eval-in-ns (nsn command)
(interactive "sNamespace to go to: \nsCommand: ")
(inf-clojure--process-response
(concat "(do (if-not (find-ns '" nsn ") (try (require '" nsn " :reload) (catch Exception e (ns " nsn " )))) (in-ns '" nsn ")" command ")")
(inf-clojure-proc)))
(defun inf-clojure-eval-in-ns-of-current-file (command)
(interactive "sCommand: ")
(if-let ((ns (clojure-find-ns)))
(inf-clojure-eval-in-ns ns command)
@saikyun
saikyun / init.el
Last active January 1, 2019 21:27
Monroe jump to def for Arcadia
(require 'monroe)
(add-hook 'clojure-mode-hook 'clojure-enable-monroe)
(defvar *monroe-project-path* nil)
(defun monroe-new-session-handler (process)
"Returns callback that is called when new connection is established."
(lambda (response)
(monroe-dbind-response response (id new-session)
(when new-session
@saikyun
saikyun / save.clj
Last active February 11, 2019 23:49
Proto repl save functionality for ClojureCLR
(ns miracle.tools.save
(:require [clojure.walk :refer [postwalk]]))
(def ^:dynamic *max-saves* 1000000000)
(defn gensym? [s]
(re-find #"__\d+" s))
(defn fn->var
"Takes a function and returns a var. Works even on function objects."
@saikyun
saikyun / gist:a83bed977b2e16855c74776238ca1196
Last active January 24, 2019 19:22
Replace print by Tims
(defonce old-print-method-impl print-method) ; the clojure.lang.MultiFn instance itself
(def ^:dynamic *overriding-print-method* false)
(defn print-method-override-dispatch [x writer]
(if *overriding-print-method*
(type x)
:default))
(defmulti print-method-override #'print-method-override-dispatch)
@saikyun
saikyun / trace.clj
Last active February 4, 2019 13:38
basic profiling
;; Need to (:import System.Diagnostics.Stopwatch)
(defonce times (atom {}))
(defn reset-times! [] (reset! times {}))
(defn avg [vs] (/ (reduce + vs) (count vs)))
(defn avgs [] (into {} (map (fn [ [k vs] ] [k {:total (reduce + vs) :calls (count vs) :max (apply max vs) :min (apply min vs) :avg (avg vs)}]) @times)))
(defn avgs-hm [] (into (sorted-map) (map (fn [[k vs]] [(:total vs) (assoc vs :name k)]) (filter (fn [[k vs]] (or (< 10 (:total vs)) (and (< 10 (:calls vs)) (< 0.1 (:avg vs))))) (avgs)))))
@saikyun
saikyun / profiling.clj
Last active February 8, 2019 14:53
profiling
;;;;
;; profiling.clj -- simple profiling macros for Clojure CLR
;; by Jona Ekenberg, https://github.com/saikyun
;; February 6th, 2019
;; Copyright (c) Jona Ekenberg, 2019. All rights reserved. The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
Plugin 'clojure.genclass.clj.dll' is used from several locations:
Assets/Arcadia/Infrastructure/clojure.genclass.clj.dll would be copied to <PluginPath>/clojure.genclass.clj.dll
Assets/Arcadia/Export/clojure.genclass.clj.dll would be copied to <PluginPath>/clojure.genclass.clj.dll
Plugin 'clojure.uuid.clj.dll' is used from several locations:
Assets/Arcadia/Export/clojure.uuid.clj.dll would be copied to <PluginPath>/clojure.uuid.clj.dll
Assets/Arcadia/Infrastructure/clojure.uuid.clj.dll would be copied to <PluginPath>/clojure.uuid.clj.dll
Plugin 'clojure.core.clj.dll' is used from several locations:
Assets/Arcadia/Infrastructure/clojure.core.clj.dll would be copied to <PluginPath>/clojure.core.clj.dll
Assets/Arcadia/Export/clojure.core.clj.dll would be copied to <PluginPath>/clojure.core.clj.dll
Plugin 'clojure.core_deftype.clj.dll' is used from several locations:
@saikyun
saikyun / save.clj
Created March 31, 2019 09:49
Save local variables, then load them
(ns miracle.tools.save
(:require [clojure.walk :refer [postwalk]]))
(def ^:dynamic *max-saves* 50)
(defn gensym? [s]
(re-find #"__\d+" s))
(defn fn->var
"Takes a function and returns a var. Works even on function objects."
@saikyun
saikyun / hydration.clj
Last active October 6, 2019 06:21
hydrate/dehydrate arcadia
;; 1. Create an empty game object called "Beholder"
;; 2. Create a cube and add it as a child to the Beholder
;; 3. Run `(dehydrate-all!)`
;; 4. Move the created cube, then rotate it
;; 5. Run `(hydrate-all!)`
;; 6. Boom
(ns game.hydration
(:require [arcadia.core :refer :all]
[clojure.string :as str]