Skip to content

Instantly share code, notes, and snippets.

(import '[javax.script ScriptEngineManager])
(let [engine (.getEngineByName (ScriptEngineManager.) "nashorn")]
(println (= (.eval engine "' \\r\\n' == 0") true)))
; CIDER 0.6.0alpha (package: 20140316.1007) (Clojure 1.5.1, nREPL 0.2.3)
user> (.maxMemory (Runtime/getRuntime))
103284736
user> (require '[clojure.java.io :as io])
nil
user> (with-open [f (io/writer "/tmp/foo")] (doseq [x (range 50000)] (.write f (prn-str [x (range 1000)]))))
nil
user> (.length (io/file "/tmp/foo"))
194988890
user> (slurp "/tmp/foo")
(in-ns 'eclj.core)
(defprotocol Fn
:on-interface clojure.lang.Fn
"Marker interface indicating invokeables that are explictly functions")
(defprotocol IFn
:on-interface clojure.lang.IFn
(^{:on :invoke} -invoke
[this]
(ns kleene)
;;
;; Inspired by "Regexes, Kleene Algebras and Real Ultimate Power"
;; http://plastic-idolatry.com/erik/oslo2014.pdf
;;
;; What do we want to do?...
;;
;; (def p1 (times (Var. "w") (Var. "o") (Var. "w"))
;; (matches? p1 "wow") ;; true
;; ## State Methods
(defmulti initial-state
"Multimethod that returns the initial state for the supplied
page." :name)
(s/defmethod initial-state :default [r :- Route s :- (s/maybe AppState)] {})
(defmulti page-title
"Returns the current page title for the supplied route." :name)
@noprompt
noprompt / complies.clj
Created March 16, 2015 04:13
complies? macro for ClojureScript. Verifies than an object not only satisfies a protocol but implements all of it.
(ns example.macros
(:require
[cljs.analyzer :as a]
[cljs.compiler :as c]))
(defmacro complies?
"True if x satisfies and implements all methods of a protocol.
Ex.
@Deraen
Deraen / silk-data.cljs
Last active August 29, 2015 14:27
Additional data to Silk routes
(deftype AdditionalData [data]
silk/Pattern
(-match [_ _]
data)
(-unmatch [_ _]
nil)
(-match-validator [_]
(constantly true))
(-unmatch-validators [_]
{}))
/*
On OS X, basic text manipulations (left, right, command+left, etc) make use of the system key bindings,
and don't need to be repeated here. Anything listed here will take precedence, however.
*/
[
{ "keys": ["super+shift+n"], "command": "new_window" },
{ "keys": ["super+shift+w"], "command": "close_window" },
{ "keys": ["super+o"], "command": "prompt_open" },
{ "keys": ["super+shift+t"], "command": "reopen_last_file" },
{ "keys": ["super+alt+up"], "command": "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} },
@ecmendenhall
ecmendenhall / speclj-check-that.clj
Created October 21, 2013 20:45
A macro for Speclj-style simple-check assertions.
(ns my-great-project.core-spec
(:require [speclj.core :refer :all]
[simple-check.core :as sc]
[simple-check.generators :as gen]
[simple-check.properties :as prop]
[my-great-project.core :refer :all]))
(defmacro check-that [desc n property]
`(it ~desc
(let [check# (sc/quick-check ~n ~property)
@currentoor
currentoor / reset_component.clj
Last active January 11, 2016 23:21
Reset the components of an entity without worrying about the current values or their entity-ids.
(defn reset-components [db eid attr new-comps]
(let [current-comps (-> (d/pull db [attr] eid) attr)
;; First we do a value based comparison ignoring component entity ids.
current-comp-vals (into #{} (map #(dissoc % :db/id) current-comps))
new-comp-vals (into #{} new-comps)
deletions (clojure.set/difference current-comp-vals new-comp-vals)
additions (clojure.set/difference new-comp-vals current-comp-vals)