Skip to content

Instantly share code, notes, and snippets.

@mrrodriguez
mrrodriguez / gist:5498087
Last active December 16, 2015 21:10
Personal Emacs configuration.
(setq mac-option-modifier 'control)
(setq mac-command-modifier 'meta)
;; fix the PATH variable
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -i -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
user> (defrecord MyRec [x])
user.MyRec
user> (def m (->MyRec 5))
#'user/m
user> (instance? MyRec m)
true
user> (eval (defrecord MyRec [x]))
user.MyRec
user> (def m2 (->MyRec 5))
#'user/m2
I have some Clojure clj files in a jar called A.jar.
This jar is started up, and I see that all of the clj files are loaded by the Application ClassLoader, along with the rest of the classes in the jar.
At runtime a new jar is added to the classpath, with some clj files that `require`s some of the clj files already loaded by the App ClassLoader.
What I have observed is that, when this newly added jar's clj files are being loaded, the `require`s they have on already loaded clj classes, are causing them to be reloaded.
The issue is that if these files that are reloaded, have something like `defrecord` in them, they load a new "version" of the same class, with a different classloader.
@mrrodriguez
mrrodriguez / gist:8046814
Last active December 31, 2015 21:29
Macro returning fn objects with closures
;;; case 1
(defn get-map-of-fn [x] (fn [] x))
;= #'user/get-map-of-fn
(defmacro map-of-fn [arg] (get-map-of-fn arg ))
;= #'user/map-of-fn
(map-of-fn 1)
;= #<user$get_map_of_fn$fn__9648 user$get_map_of_fn$fn__9648@47020d4>
package drools
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
import example.drools.*;
package example.drools;
public class Utils {
public static Boolean useless(final Object... os) {
System.out.println("here");
return true;
}
public static Boolean useless1(final Object... os) {
System.out.println("here");
return true;
@mrrodriguez
mrrodriguez / gist:e2138f220a9aa7eacc20
Created May 6, 2014 18:56
Comparing clj record ctor options performance
(defrecord MyTest [a b c d e f g h i j])
;= user.MyTest
(time (dotimes [_ 10000000]
(new MyTest 1 2 3 4 5 6 7 8 9 10)))
;= "Elapsed time: 11.227 msecs"
;= nil
(time (dotimes [_ 10000000]
(->MyTest 1 2 3 4 5 6 7 8 9 10)))
@mrrodriguez
mrrodriguez / print_method.clj
Last active August 24, 2016 16:10
print-method based clara-rules durability impl
(ns clara.rules.durability.print-method
(:require [clara.rules.durability :as d]
[clara.rules.memory :as mem]
[clara.rules.engine :as eng]
[clara.rules.compiler :as com]
[clojure.java.io :as jio]
[clojure.main :as cm])
(:import [clara.rules.durability
MemIdx]
[clara.rules.memory
@mrrodriguez
mrrodriguez / unindexing_durability.clj
Created August 19, 2016 18:56
Back when clara.rules.durability had the concept of "unindex"ing memory - was removed for efficiency
(ns clara.rules.durability
"Experimental namespace. This may change non-passively without warning.
Support for persisting Clara sessions to an external store.
See the serialize-session-state function to retrieve the full state of a session as a data structure that can
be easily serialized via EDN or Fressian. Sessions can then be recovered with the restore-session-state function.
TODO: diff support is pending -- functions for obtaining a diff of state from a previous point, allowing for a write-ahead log."
(:require [clara.rules :refer :all]
@mrrodriguez
mrrodriguez / clj-data-fressian-serde.clj
Last active May 10, 2023 15:46
Clojure Serialization With Fressian
;;;; Fressian dependency used in these examples
;; [org.clojure/data.fressian "0.2.1"]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Using only `org.clojure/data.fressian`
(require '[clojure.data.fressian :as fres])
(defn serde-obj