Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
stuartsierra / async-concat.clj
Last active January 2, 2016 21:29
concat in Clojure core.async (untested)
;; Totally untested
(defn concat [& chans]
(let [out (chan)]
(go-loop [[ch & more] chans]
(when ch
(let [val (<! ch)]
(if (nil? val)
(recur more)
(do (>! out val)
(recur chans))))))
@stuartsierra
stuartsierra / gist:8307722
Created January 7, 2014 22:02
The problem with stack trace pretty-printers: the pretty-printer threw an exception, so I can't see the actual exception that caused it
ERROR in (some-test) (Reflector.java:432)
Uncaught exception, not in assertion.
expected: nil
actual:
at java.util.regex.Matcher.getTextLength(Matcher.java:1233)
at java.util.regex.Matcher.reset(Matcher.java:308)
at java.util.regex.Matcher.<init>(Matcher.java:228)
at java.util.regex.Pattern.matcher(Pattern.java:1088)
at clj_stacktrace.utils$re_gsub.invoke(utils.clj:6)
at clj_stacktrace.core$clojure_ns.invoke(core.clj:14)
@stuartsierra
stuartsierra / project.clj
Created October 18, 2013 21:26
Sample Leiningen project.clj for trying out Austin
(defproject cljsfoo1 "0.1.0-SNAPSHOT"
:plugins [[lein-cljsbuild "0.3.4"]
[com.cemerick/austin "0.1.1"]]
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-1934"]
[ring "1.2.0"]
[compojure "1.1.5"]
[enlive "1.1.1"]]
:source-paths ["src/clj" "src/cljs"]
:cljsbuild {:builds
@stuartsierra
stuartsierra / gist:6903938
Created October 9, 2013 16:22
Maven dependency:tree of a project with failing Lamina / Potemkin interaction at load time.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building system-test 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ system-test ---
[INFO] <<<REDACTED>>>
[INFO] +- org.clojure:clojure:jar:1.5.1:compile
[INFO] +- <<<REDACTED>>>
@stuartsierra
stuartsierra / fresh-chrome.sh
Last active October 13, 2020 16:07
Launch new instances of Google Chrome on OS X with isolated cache, cookies, and user config
#!/usr/bin/env bash
# fresh-chrome
#
# Use this script on OS X to launch a new instance of Google Chrome
# with its own empty cache, cookies, and user configuration.
#
# The first time you run this script, it will launch a new Google
# Chrome instance with a permanent user-data directory, which you can
# customize below. Perform any initial setup you want to keep on every
@stuartsierra
stuartsierra / project.clj
Created July 19, 2013 20:16
sample project.clj file to test ClojureScript release 0.0-1845-RC1
(defproject your-project "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-1845-RC1"]]
:repositories {"sonatype-staging"
"https://oss.sonatype.org/content/groups/staging/"})
@stuartsierra
stuartsierra / mazejam.clj
Last active December 19, 2015 14:38
Maze Jam example from Lambda Jam 2013, Chicago, in Clojure
;; Maze Jam from Lambda Jam 2013, Chicago
;;
;; by Stuart Sierra, http://stuartsierra.com/
;;
;; There are probably bugs in this code.
;;
;; Copyright (c) 2013 Stuart Sierra
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
@stuartsierra
stuartsierra / spellcheck.clj
Created July 9, 2013 01:47
Example implementation of Norvig's Spellchecker in Clojure, using core.async
;; Example implementation of Norvig's Spellchecker in Clojure,
;; using core.async
;;
;; There are probably some bugs in this.
;;
;; Original problem: https://github.com/ericnormand/spelling-jam
;; from Lambda Jam, Chicago, 2013: http://lambdajam.com/
;;
;; Clojure core.async introduction:
;; http://clojure.com/blog/2013/06/28/clojure-core-async-channels.html
package example;
import java.math.BigInteger;
public class Factorial {
public static BigInteger factorial(final int n) {
BigInteger res = BigInteger.valueOf(1L); //build upresult
for (int i = n; i > 1; i--)
res = res.multiply(BigInteger.valueOf(i));
return res;
@stuartsierra
stuartsierra / sum.clj
Created June 18, 2013 17:51
Brief demonstration of JVM dead code elimination in Clojure 1.2 and 1.5
;; Demonstration of JVM dead code elimination in Clojure 1.2 and 1.5
;;
;; This Clojure script demonstrates some of the effects of dead code
;; elimination in the JVM. For unknown reasons, the bytecode produced
;; by Clojure 1.2.1 is more susceptible to elimination than the
;; bytecode produced by Clojure 1.5.1, making it seem like 1.2.1 is
;; faster. But when the code is forced to do real work, the difference
;; disappears.
;;
;; My results with Clojure 1.2.1: