Skip to content

Instantly share code, notes, and snippets.

View reborg's full-sized avatar

reborg reborg

View GitHub Profile
@reborg
reborg / atlas.sh
Created November 8, 2016 21:17
Get neanderthal library with ATLAS custom build
lean new neander
cd neander
# change project.clj to include [uncomplicate/neanderthal "0.8.0"]
# this fetches a “atlas-3.10.2” locally
apt-get source atlas
sudo apt-get build-dep atlas
sudo apt-get install devscripts
cd atlas-3.10.2
fakeroot debian/rules custom
@reborg
reborg / most-used-fns.clj
Last active January 28, 2019 11:02
Clojure functions usage frequencies
;; The list of (almost) all Clojure public functions and macros ordered by usage. Source: Github code search for Clojure repositories.
(["ns" 394490]
["defn" 293918]
["require" 279210]
["let" 237654]
["def" 172983]
["refer" 163654]
["map" 159781]
["fn" 154482]
@reborg
reborg / game-of-life.clj
Last active August 16, 2016 22:11
Game of life Clojure
(defn count-neighbors [h w x y cells]
(->> (for [dx [-1 0 1]
dy [-1 0 1]
:let [x' (+ x dx)
y' (+ y dy)]
:when (and (not (= dx dy 0))
(<= 0 x' (dec w))
(<= 0 y' (dec h)))] [x' y'])
(filter cells)
count))
@reborg
reborg / clojure-primitive-support.md
Last active July 16, 2017 15:18
Clojure Primitive Support (2008)

Introduction

I found a link to this now disappeared Clojure wiki page giving a pretty good explanantion of Clojure support for fast-math by Rich. I then found it again at http://clojure.org/old_news and on the original thread on the ML. The document illustrates the rationale behind some early Clojure optimisations that are still integral part of Clojure nowadays. The changes Rich describes here are mainly to enable the JVM JIT inlining of primitive operations and bring Clojure performance on primitive types (including arrays) on par with Java.

Below I also added the related IRC chat with some additional explanation.

You can consider this an extended comment to the work encompassing (roughly) git commit https://github.com/clojure/clojure/commit/5d9e87e8a30dfc99fe41c3be0a8ddc5ddd4e1d8d to

@reborg
reborg / clojure-irc-pdf-links
Last active July 16, 2017 15:18
PDF Links #Clojure IRC
@reborg
reborg / tsp.clj
Created December 18, 2013 11:29
An implementation of the travel salesman problem as clojure lazy seq
;; An implementation of a lazy seq that given a graph in the form of a list
;; of edges (e.g. ["AB" "BC" "CD"] can be de-queued of any number
;; of valid paths (in the above example ["AB" "BC" "CD" "ABC" "BCD"] only).
;; Returns nils for acyclic graphs after the number of all
;; available paths have been exhausted. So if you take 100 from the above,
;; the returned collection will have nils after 5 elements. For cyclic graphs
;; it will follow the cycles infintely. To prevent infinte loops, it will
;; exit after a threshold anyway.
;; The approach is definitely brute-force. Optimisations can be done by
;; introducing weight for edges and operating on less costly paths first.
;; with reference to http://www.learningclojure.com/2013/09/efficiency-and-progress-my-god-clojure.html
(ns cljperf.core
(:use criterium.core))
;; assumptions: we are searching for raw clojure speed for some problem
;; that requires just performances. We can give up some of the Clojure simplicity
;; and expressivness because we connected a profiler and we know what we are doing.
;; Second: we know how to measure. The time macro is too unreliable at this scale,
;; we'll use criterium.
@reborg
reborg / tmux.sh
Created June 10, 2013 15:07
Handy tmux.sh to add to your new Clojure project that creates a single window with one main Vim pane and a secondary small at the bottom which runs Midje autotest on top of a lein repl session.
export PROJECT_NAME=$1
export WORKING_DIR=/me/prj/$PROJECT_NAME
cd $WORKING_DIR;
# create the session
tmux start-server
tmux new-session -d -s $PROJECT_NAME -n work
# start vim in working dir
tmux select-window -t$PROJECT_NAME:1
@reborg
reborg / ants.clj
Created July 13, 2012 20:50 — forked from jjcomer/ants.clj
Ant Simulation -- From Clojure Concurrency Presentation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;As shown in the presentation: http://blip.tv/clojure/clojure-concurrency-819147
@reborg
reborg / StringUtils.java
Created July 13, 2012 16:36
isBlank from StringUtils apache commons
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false)) {
return false;
}
}