Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
stuartsierra / clojurescript-project.clj
Created January 20, 2012 18:04
project.clj for ClojureScript project
(defproject foo "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/clojurescript "0.0-927"]])
@stuartsierra
stuartsierra / errors.clj
Created April 20, 2012 14:27
Example error messages from common mistakes with Datomic
;; Some example error messages resulting from common mistakes
;; using Datomic 0.8.4138
(ns errors
(:use [datomic.api :as d :only (db q)]))
(def uri "datomic:mem://database")
(d/create-database uri)
@stuartsierra
stuartsierra / lein2-issue.md
Created July 6, 2012 21:04
'file:' repositories in Leiningen 2.0.0-preview5 and later

Sample Project

Starting from:

lein new foo
cd foo

Say I have a random JAR file that is not available in any repository:

touch README.md

@stuartsierra
stuartsierra / data_json_0_1_compat.clj
Created October 25, 2012 02:29
data.json 0.1.x compatibility shim
;;; data.json 0.1.x compatibility shim
;; Loading this file alongside data.json version 0.2.0 adds
;; definitions which make it compatible with the public API of
;; data.json version 0.1.3.
;; Copyright (c) Stuart Sierra, 2012. All rights reserved. The use and
;; distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
@stuartsierra
stuartsierra / gist:5788531
Last active August 14, 2018 16:45
Cannot convey data from an exception within a Datomic transaction
;; Example showing that I cannot convey data from an exception within
;; a transaction.
(ns example
(:require [datomic.api :as d])) ; Datomic Free 0.8.4007
(def uri "datomic:mem:example")
(d/create-database uri)
@stuartsierra
stuartsierra / Sum.java
Created June 18, 2013 17:15
Brief demonstration of dead-code elimination in the JVM
/* Demonstration of dead-code elimination in the JVM.
*
* This class demonstrates some of the difficulties of benchmarking
* code which may be subject to dead-code elimination by the JVM.
* There are two loops, both calling the same function. But only the
* second loop actually uses the result of the function.
*
* When I run this code, I get results like this:
*
* Dead code:
@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:
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 / 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
@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