Skip to content

Instantly share code, notes, and snippets.

@noisesmith
noisesmith / user.clj
Created August 2, 2019 23:36
function to run clojure tests under a directory by ns regex
(require '[clojure.java.io :as io]
'[clojure.main :as m]
'[clojure.test :as test])
(defn run-matching-tests
"(re)loads and runs tests under dir/ which match your regex,
useful for running all tests under a specific prefix
or containing a common name element like \"integration\""
([match]
(run-matching-tests match "test/" false))
@noisesmith
noisesmith / user.clj
Created June 13, 2019 22:22
custom user.clj, including a bunch of stuff I don't often use...
(ns user
(:require [clojure.test :as test]))
(defmacro lf
[f]
(load-file (str "/tmp/" (str f) ".clj")))
(defmacro l
[f]
`(lf ~(str "/clj-tmp-files/" f)))
@noisesmith
noisesmith / clean-slate.sh
Created May 3, 2016 18:13
clean some things from zk, kafka, mongo
#!/bin/sh
# vars
## EDITOR/VISUAL - what process to use to pick targets interactively
## ZK_WL - regex for zookeeper paths not to remove
## KAFKA_WL - regex for kafka topics not to remove
## MONGO_WL - regex for mongo item ids not to remove
# set -x
--exclude=.git
--exclude=.svn
--exclude=resources/*
--exclude=*/resources/*
--exclude=*/public/*
--exclude=.repl/*
--exclude=*/.repl/*
--exclude=out/*
--exclude=*/out/*
--exclude=target/*
@noisesmith
noisesmith / gist:d9a804212f3759043053
Created January 29, 2016 23:09
start a clojure 1.8 socket repl
=> (clojure.core.server/start-server {:name "debug connection" :port 5555 :accept 'clojure.core.server/repl})
#object[java.net.ServerSocket 0x631883f0 "ServerSocket[addr=localhost/127.0.0.1,localport=5555]"]
@noisesmith
noisesmith / .ctags
Created April 17, 2017 17:06
improved exuberant ctags config for clojure users
--exclude=.git
--exclude=.svn
--exclude=resources/*
--exclude=*/resources/*
--exclude=*/public/*
--exclude=.repl/*
--exclude=*/.repl/*
--exclude=out/*
--exclude=*/out/*
--exclude=target/*
@noisesmith
noisesmith / repl session
Created July 28, 2018 00:04
using rename with refer-clojure
(ins)user=> (ns foo.bar (:refer-clojure :rename {map pam}))
nil
(ins)foo.bar=> (pam inc [1 2 3])
(2 3 4)
@noisesmith
noisesmith / repl session
Created June 1, 2018 00:58
weird circleci bug with assertion errors
user=> (ns foo.broken)
nil
foo.broken=> (require 'circleci.test 'clojure.test)
nil
foo.broken=> (defn foo [] {:pre [false]} true)
#'foo.broken/foo
foo.broken=> (clojure.test/deftest foo-test (foo))
#'foo.broken/foo-test
foo.broken=> (circleci.test/run-tests 'foo.broken)
test-results-dir: target/test-results
@noisesmith
noisesmith / download.cljs
Created May 25, 2017 21:47
create a download of some data in a clojurescript repl (eg. figwheel)
(defn download
; adapted from https://stackoverflow.com/a/3665147
[data filename encoder]
(let [el (.createElement js/document "a")
data-str (js/encodeURIComponent (encoder data))]
(doto el
(.setAttribute "href" (str "data:text/plain;charset=utf-8,"
data-str))
(.setAttribute "download" filename))
(aset (.-style el) "display" "none")
+user=> (def c (ProcessBuilder. (into-array ["cat"])))
#'user/c
+user=> (def p (.start c))
#'user/p
+user=> (def o (.getOutputStream p))
#'user/o
+user=> (.write o (.getBytes "hello\n\n"))
nil
+user=> (.flush o)
nil