Skip to content

Instantly share code, notes, and snippets.

@aiba
aiba / pmapn.clj
Last active August 29, 2015 14:18
(require '[clojure.contrib.seq-utils :refer [indexed]])
(import (java.util.concurrent Executors ConcurrentHashMap))
(defn pmapn [n f coll]
(let [executor (Executors/newFixedThreadPool n)
total (count coll)
results (ConcurrentHashMap. total 0.75 n)]
;; enqueue work
(doseq [[i x] (indexed coll)]
(.execute executor #(.put results i (f x))))
/**
* Functional HTML library.
* Requires $ and _.
*/
(function(outerScopeObj) {
function toHTML(x) {
if (x.toHTML) {
return x.toHTML();
$ lein ancient
clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: org.joda.time.ReadablePartial, compiling:(ancient/ancient_clj/v0v3v13/clj_aws_s/v0v3v10/clj_time/v0v6v0/clj_time/core.clj:1:1)
at clojure.lang.Compiler.load (Compiler.java:7391)
clojure.lang.RT.loadResourceScript (RT.java:372)
clojure.lang.RT.loadResourceScript (RT.java:363)
clojure.lang.RT.load (RT.java:453)
clojure.lang.RT.load (RT.java:419)
clojure.core$load$fn__5677.invoke (core.clj:5893)
clojure.core$load.invokeStatic (core.clj:5892)
clojure.core$load.doInvoke (core.clj:5876)
;; I recommend mapping to C-c M-k
(defun my-cider-reset-buffer ()
(interactive)
(cider-interactive-eval "(remove-ns (ns-name *ns*))")
(cider-load-buffer))
@aiba
aiba / fastrepl.sh
Created November 18, 2012 03:42
Fast lein repl using drip
#!/bin/bash -e
if [ ! -f ./project.clj ]; then
echo "Run from a lein project directory."
exit 1
fi
mkdir -p ./.fastrepl/
if command -v md5 >/dev/null 2>&1; then
MD5=`md5 -q project.clj`
- redisplay_internal (C function) 3653 87%
- debug 3653 87%
- recursive-edit 3372 80%
- nrepl-client-filter 2894 69%
- nrepl--dispatch-response 2728 65%
- nrepl-log-message 2722 65%
- nrepl--pp 2698 64%
- nrepl--pp 2698 64%
- nrepl--pp 2597 62%
- nrepl--pp 2346 56%
@aiba
aiba / gist:91d330df7e98f25d23ab9e75cfb0d6eb
Created September 29, 2016 19:44
cpu-profiler-report-2
- redisplay_internal (C function) 19334 90%
- debug 19334 90%
- recursive-edit 15689 73%
- nrepl-client-filter 10656 50%
- nrepl--dispatch-response 10159 47%
- nrepl-log-message 9813 46%
- nrepl--pp 9800 46%
- nrepl--pp 9798 46%
- nrepl--pp 9712 45%
- nrepl--pp 9056 42%
@aiba
aiba / countries.txt
Created July 23, 2017 16:35
Countries sorted by ratio of word length to number of vowels
Kyrgyzstan
Cyprus
St Kitts & Nevis
Egypt
Chad
Marshall Islands
Myanmar, {Burma}
Netherlands
Switzerland
Czech Republic
(ns virgil.repl
(:require [clojure.set :as set]
[clojure.tools.namespace.dir :as ctn-dir]
[clojure.tools.namespace.file :as ctn-file]
[clojure.tools.namespace.find :as ctn-find]
[clojure.tools.namespace.parse :as ctn-parse]
[clojure.tools.namespace.repl :as ctn-repl]
[virgil.compile :refer [compile-all-java]])
(:import java.io.File
java.util.Arrays))
@aiba
aiba / linear_interpolate.clj
Last active October 17, 2019 20:30
linear interpolation transducer
(defn linear-interpolate
([]
(fn [rf]
(let [rrf (#'clojure.core/preserving-reduced rf)
skipped (volatile! 0) ;; n of contiguous nils
prev (volatile! nil)] ;; most recent value seen
(fn
([] (rf)) ;; init
([result] ;; completion -- skipped stay nils since no endpoint
(rf (reduce rf result (repeat @skipped nil))))