Skip to content

Instantly share code, notes, and snippets.

;; To get factorial of 5
(* 5 4 3 2 1)
;; To get factorial of n: n!
(apply * (range 5 0 -1)
(require '[clojure.test.check.random :as random]
'[clojure.test.check.generators :as gen]
'[clojure.test.check.rose-tree :as rt])
(defn shrinks
"Shows how a generator will shrink"
([g] (shrinks g 10 10))
([g size] (shrinks g size 10))
([g size sample] (take sample (distinct (map rt/root
(tree-seq (fn [_] true) rt/children (gen/call-gen g (random/make-random) size)))))))
(require '[clojure.test.check.generators :as gen])
(require '[clojure.string :refer [join]])
(require '[schema-generators.generators :as g])
(require '[schema.core :as s])
(def IP String)
#_(def IP (s/named String "IP"))
@m0smith
m0smith / bug_fix.clj
Created August 26, 2019 15:22
Fixes StackOverflowError with Cider, Datomic Ions and Nrepl
(ns bug-demo
(:require [datomic.ion.cast :as cast]
[clojure.java.io :refer [output-stream]]))
(cast/initialize-redirect :stderr) ; instead of :stdout
(cast/event {:msg "ShouldNotCauseAStackOverflowErrorInCider"})
@m0smith
m0smith / bug_demo.clj
Created August 26, 2019 15:17
Shows a problem with stackover flow using cider and datomic ions
(ns bug-demo
(:require [datomic.ion.cast :as cast]
[clojure.java.io :refer [output-stream]]))
(cast/initialize-redirect :stdout)
(cast/event {:msg "ShouldNotCauseAStackOverflowErrorInCider"})
@m0smith
m0smith / kaocha-deps.edn
Last active August 14, 2019 15:00
Koacha setup in deps.edn for use with Bitbucket Pipeline
:kaocha {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "0.0-529"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0-70"}
lambdaisland/kaocha-cloverage {:mvn/version "0.0-32"}
cloverage {:mvn/version "RELEASE"}
}
:main-opts ["-m" "kaocha.runner"
"--plugin" "kaocha.plugin/junit-xml"
"--plugin" "cloverage" "--no-cov-summary"
"--junit-xml-file" "target/test-results/junit.xml"]}
@m0smith
m0smith / vc.py
Created February 2, 2017 17:01
VC scripts for unified SVN and GIT
#!/usr/local/bin/python
import os
import subprocess
import sys
commands ={ ".svn" : ["svn","-u","status"],
".git" : ["git", "status"] }
def parent_dirs(f_or_d):
(defun list-to-hash (coll)
(let ((rtnval (make-hash-table :test 'equal)))
(cl-loop for r across coll
when r
do (puthash (elt r 1) nil rtnval))
rtnval))
(defun jdee-open-source-resource-in-archive-p (archive resource)
""
@m0smith
m0smith / tooling.out
Created March 19, 2015 17:42
Sample groovysh using Gradle Tooling
Groovy Shell (2.3.7, JVM: 1.7.0_45)
Type ':help' or ':h' for help.
groovy:000>
malabar = { classLoader = new groovy.lang.GroovyClassLoader();
Map[] grapez = [[group: 'com.software-ninja' , module:'malabar', version:'2.3.2-SNAPSHOT']];
groovy.grape.Grape.grab(classLoader: classLoader, grapez);
classLoader.loadClass('com.software_ninja.malabar.MalabarStart').newInstance().startCL(classLoader); };
malabar();
groovy:000> malabar = { classLoader = new groovy.lang.GroovyClassLoader();
@m0smith
m0smith / malabar-flycheck.el
Created December 10, 2014 15:13
Trying to get a flycheck checker that will be a callback from url-retrieve
(require 'flycheck)
(defun malabar-flycheck-command ( checker cback )
"Use flycheck to search the current buffer for compiler errrors."
(if (not (comint-check-proc "*groovy*"))
(funcall cback 'finished nil)
(let* ((pom (ede-find-project-root "pom.xml"))
(pom-path (format "%spom.xml" pom))
(script (if (buffer-modified-p) (buffer-file-name) (buffer-file-name))))