Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
stuartsierra / gist:1212314
Created September 12, 2011 20:29
Enable Electric Ruby Mode in Emacs
;; Add this to ~/.emacs
;; Missing from ruby-mode.el, see https://groups.google.com/group/emacs-on-rails/msg/565fba8263233c28
(defun ruby-insert-end ()
"Insert \"end\" at point and reindent current line."
(interactive)
(insert "end")
(ruby-indent-line t)
(end-of-line))
@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 / 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 / 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 / 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 / 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 / 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 / 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: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)