Skip to content

Instantly share code, notes, and snippets.

@lilactown
lilactown / rebel.sh
Last active Jun 18, 2019
Start a Clojure(Script) REPL with rebel-readline and any other dependencies you want to include
View rebel.sh
# Add these to your .bash_profile / .zshrc / etc.
# Starts a Clojure repl
function rebel-clj() {
clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"} $@}}" -m rebel-readline.main
}
# Starts a browser REPL
function rebel-cljs() {
clojure -Sdeps "{:deps {com.bhauman/figwheel-main {:mvn/version \"0.1.7\"} com.bhauman/rebel-readline-cljs {:mvn/version \"0.1.4\"} $@}}" -m figwheel.main
@kennyjwilli
kennyjwilli / defspec-test.clj
Created Nov 5, 2016
clojure.spec.test integration with clojure.test
View defspec-test.clj
(defmacro defspec-test
([name sym-or-syms] `(defspec-test ~name ~sym-or-syms nil))
([name sym-or-syms opts]
(when t/*load-tests*
`(def ~(vary-meta name assoc :test `(fn []
(let [check-results# (clojure.spec.test/check ~sym-or-syms ~opts)
checks-passed?# (every? nil? (map :failure check-results#))]
(if checks-passed?#
(t/do-report {:type :pass
:message (str "Generative tests pass for "
@bhb
bhb / test_helper.clj
Last active Mar 6, 2019
Test helpers when using clojure.spec
View test_helper.clj
(ns foo.test-helper
(:require [clojure.spec :as s]
[clojure.spec.test :as st]
[clojure.string :as str]
[clojure.test :refer :all]
[clojure.test.check.generators :as gen]
[clojure.test.check.random :refer [IRandom]]
[clojure.test.check.rose-tree :as rose]))
(defn instrument-all
@lfn3
lfn3 / core.clj
Created Aug 29, 2016
Validating values put into a channel with clojure spec
View core.clj
(ns channel-of.core
(:require [clojure.spec :as s]
[clojure.core.async :as a]
[clojure.core.async.impl.protocols :as ap]))
(defmacro chan-of [spec & chan-args]
`(let [ch# (a/chan ~@chan-args)]
(reify
ap/ReadPort
(take! [_ fn1-handler#]
@bhb
bhb / dbg.clj
Created Mar 26, 2015
Debug macro for Clojure (dbg)
View dbg.clj
(defmacro dbg [body]
`(let [x# ~body]
(println "dbg:" '~body "=" x#)
x#))
@bhb
bhb / c
Created Mar 11, 2015
Copy text into clipboard
View c
#! /usr/bin/env ruby
# file: ~/bin/c
#
# usage: highlight lines and pipe them to stdout in your editor. nothing
# changes except they are copied to your paste buffer. should be modified to
# work with linux using xclip
$VERBOSE=nil
STDOUT.sync = true
@bhb
bhb / ext_finder.rb
Created Mar 8, 2013
Find all gems in a bundle that have native extensions.
View ext_finder.rb
# bundle exec ruby ext_finder.rb
require 'rubygems'
Gem::Specification.each do |spec|
ext = spec.extensions
puts "#{spec.name} (#{spec.version}) has extensions: #{ext}" unless ext.empty?
end
@joelittlejohn
joelittlejohn / find-unused-clj.sh
Last active Nov 6, 2020
Very quick and dirty command to find unused functions and vars in a Clojure project
View find-unused-clj.sh
#!/bin/bash
for f in $(egrep -o -R "defn?-? [^ ]*" * --include '*.clj' | cut -d \ -f 2 | sort | uniq); do
echo $f $(grep -R --include '*.clj' -- "$f" * | wc -l);
done | grep " 1$"