Skip to content

Instantly share code, notes, and snippets.

@ato
ato / TempoDirectory.java
Created October 1, 2013 05:55
TempDirectory java temporary directory delete on exit
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
class TempDirectory {
final Path path;
@ato
ato / README.md
Last active December 20, 2015 07:39
ShotgunServlet - A nimble code reloader for Java

I've now turned this into a proper project called JShotgun. JShotgun is even faster as it uses Java 7 WatchService and reloads in a background thread.

@ato
ato / ERB.java
Last active February 3, 2016 09:28
JRuby
package pavo;
import java.io.*;
import java.util.*;
import javax.script.*;
public class ERB {
static ScriptEngine jruby = initializeJRuby();
@ato
ato / _update-pom-list.sh
Created August 19, 2012 06:36
clojars data feed scripts
#!/bin/bash
#
# Clojars data feeds. This needs integrating into current master branch.
# See: https://github.com/ato/clojars-web/blob/no-db/src/clojars/feed.clj
#
set -e
cd /home/clojars/repo
find . -name '*.pom' | grep -v '/\.' | sort > all-poms.txt.new
cat all-poms.txt.new | gzip > all-poms.txt.gz.new
@ato
ato / ssl.clj
Created June 1, 2012 15:57
Bundling CA certs
(ns leiningen.core.ssl
(:require [clojure.java.io :as io])
(:import java.security.KeyStore
java.security.KeyStore$TrustedCertificateEntry
java.security.cert.CertificateFactory
javax.net.ssl.SSLContext
javax.net.ssl.TrustManagerFactory
javax.net.ssl.X509TrustManager))
(defn ^TrustManagerFactory trust-manager-factory [^KeyStore keystore]
@ato
ato / pandora2warc.clj
Created May 14, 2012 06:01
PANDORA display instance to WARC converter
(ns clj-warc.pandora2warc
"PANDORA display instance to WARC converter."
(:use clojure.java.io)
(:require [clojure.string :as str]
[clojure.contrib.seq-utils :as seq-utils])
(:import (org.archive.util Base32)
(java.nio.file Path Files SimpleFileVisitor FileVisitResult)
(java.nio.file.attribute FileTime BasicFileAttributes))
(:gen-class))
irb(main):010:0> (40
irb(main):011:1> + 40)
=> 40
irb(main):012:0> ("foo"
irb(main):013:1> + "baz")
NoMethodError: undefined method `+@' for "baz":String
from (irb):13
from :0
irb(main):014:0> ("foo" +
irb(main):015:1* "baz")
@ato
ato / gist:2036052
Created March 14, 2012 12:08
Clojure startup time hack: refer
clojure.core/refer is relatively heavyweight. It gets called 7 times during Clojure
startup (4 times in 1.3.0). There's potential to shave off 10% of the startup time
by improving it. Probably even more for projects with a large number of small
namespaces.
This is just a quick experiment to see what's possible, it would need much refining.
It's not thread safe, doesn't print warnings and could probably be written more
elegantly.
java -Xbootclasspath/a:clojure.jar -cp clojure.jar clojure.main -e "(System/exit 0)"
@ato
ato / gist:1117588
Created August 1, 2011 04:52
mucking with Aether
;; Maven hoopla
(defproject moopla "1.0.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
;; Dependency hoops!
[org.sonatype.aether/aether-api "1.8"]
[org.sonatype.aether/aether-util "1.8"]
[org.sonatype.aether/aether-impl "1.8"]
@ato
ato / complex.clj
Created December 27, 2010 00:30
Stuart Sierra's automated 2-argument type dispatch with protocols
;; Quick fixup of http://paste.lisp.org/display/93387 for the final
;; datatypes/protocols syntax.
;;
;; With subtraction fixed.
(defn swap-args [f]
(fn [x y] (f y x)))
(defmacro defdouble
"Creates a function with 2-argument type dispatch."