Skip to content

Instantly share code, notes, and snippets.

@joelittlejohn
joelittlejohn / find-unused-clj.sh
Last active November 6, 2020 16:56
Very quick and dirty command to find unused functions and vars in a Clojure project
#!/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$"
@bhb
bhb / ext_finder.rb
Created March 8, 2013 17:08
Find all gems in a bundle that have native extensions.
# 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
@bhb
bhb / c
Created March 11, 2015 19:44
Copy text into clipboard
#! /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 / dbg.clj
Created March 26, 2015 18:31
Debug macro for Clojure (dbg)
(defmacro dbg [body]
`(let [x# ~body]
(println "dbg:" '~body "=" x#)
x#))
@lfn3
lfn3 / core.clj
Created August 29, 2016 20:47
Validating values put into a channel with clojure spec
(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 / test_helper.clj
Last active March 6, 2019 10:51
Test helpers when using clojure.spec
(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
@kennyjwilli
kennyjwilli / defspec-test.clj
Created November 5, 2016 01:37
clojure.spec.test integration with clojure.test
(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 "
@lilactown
lilactown / rebel.sh
Last active June 18, 2019 09:52
Start a Clojure(Script) REPL with rebel-readline and any other dependencies you want to include
# 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