This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Runner for stand-alone Clojure scripts. | |
set -o errexit | |
set -o nounset | |
: "${JAVA_CMD:=java}" | |
: "${CLOJURE_VERSION:=1.8.0}" | |
: "${CLOJURE_JAR:=${HOME}/.m2/repository/org/clojure/clojure/${CLOJURE_VERSION}/clojure-${CLOJURE_VERSION}.jar}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Shell script skeleton. Try each of these: | |
# ./skeleton | |
# ./skeleton one | |
# ENVIRONMENTAL=x ./skeleton one | |
# ENVIRONMENTAL=x ./skeleton one two | |
set -o errexit | |
set -o nounset | |
set -o pipefail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Useful commands for Maven POM maintenance. | |
- mvn dependency:analyze | |
- mvn dependency:tree | |
- mvn dependency:tree -Dverbose | |
- mvn versions:display-dependency-updates | |
- mvn versions:display-plugin-updates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Philosophers sitting around a table, one chopstick per person. | |
;; Dijkstra's "dining philosophers" problem. | |
(let [logger (agent nil)] | |
(defn log [& args] | |
(send-off logger #(apply println %2) args))) | |
(defn philosophers | |
"Returns a vector of philosophers with the given names, each having a | |
chopstick on their left and right. A chopstick contains a reference to the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ThreadLocalRandom; | |
import java.util.concurrent.locks.Lock; | |
import java.util.concurrent.locks.ReentrantLock; | |
/** | |
* Mutual exclusion without locks, as first discovered by Dijkstra in 1965. | |
* | |
* <p>The code is so strange because the point of this class is to not use any | |
* of the synchronisation primitives nor any of the concurrency utilities in the | |
* library. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Trampolining lexer for J sentences | |
;; Predicates | |
(def digits (set "0123456789_")) | |
(def alphabet (set "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) | |
(def space? (partial contains? #{\space \tab})) | |
(def alpha-n? (partial contains? (disj alphabet \N))) | |
(def n? (partial = \N)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Usage: vbench [non_standard_runtimepaths ...] input_script [reference_output] | |
# | |
# 'vbench' is a wrapper around vspec that adds benchmarking capabilities. | |
# | |
# vbench runs a test script, just like vspec. When the test script follows the | |
# convention of outputting a time measurement alongside a successful test | |
# result, in the following format, | |
# | |
# ok 1 - Test case outputs time measurement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Tiny library for conversion of numbers of bijective base-k number systems | |
" (number systems without zero) to decimal integers and vice-versa. Examples: | |
" | |
" base 3: 1 2 3 11 12 13 21 22 23 31 32 33 111 112 113 ... | |
" base 5 (digits {a b c d e}): a b c d e aa ab ac ad ae ba ... | |
" | |
" The public interface is numerals#CreateConverter(digitstring) which creates | |
" a {converter} for the number system defined by the digitstring. | |
" | |
" {converter}.ValueOf(int) - converts an integer to a base-k number string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Tool for exploring a time-tracking system | |
;; | |
;; Some time-tracking systems track time differently from what | |
;; an employee expects. Suppose you work 80%, Monday to Thursday. Some | |
;; time-tracking systems sum your hours up and distribute them over | |
;; the week: on average you'll work overtime Monday to Thursday, and | |
;; work too little on Friday. On average this is fair, but depending | |
;; on when the holidays are it can cost the employee a few hours. | |
(defn select |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
vgrep() { | |
local re=${1:-^} | |
local files=() | |
for arg in "${@:2}"; do | |
[ -f "${arg}" ] && files+=( "${arg}" ) | |
done | |
if [ -z "${files[*]:1}" ]; then | |
vim -Ni NONE -nes <<<"argdo g/${re////\\/}/p" -- "${files[@]}" | |
else |
NewerOlder