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
(ns cklist.model.generic | |
(use cklist.util)) | |
;; ========================================================================= | |
;; revision and timestamping support | |
(defn timestamp | |
"Returns object timestamped with the current system time in milliseconds" | |
[obj] | |
(assoc obj :timestamp (System/currentTimeMillis))) |
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
(ns cklist.validation | |
(:use clojure.test)) | |
(defn- vresult | |
[k msg] | |
{k #{msg}}) | |
(defn required | |
"Returns validator which requires field to be non-empty" | |
[msg k] |
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
(ns util.markdown | |
(import (java.io | |
BufferedReader | |
InputStreamReader))) | |
(defn markdown | |
[s] | |
(let [builder (java.lang.ProcessBuilder. ["Markdown.pl"]) | |
proc (.start builder) | |
stdin (.getOutputStream proc) |
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.io BufferedWriter FileWriter | |
PushbackReader BufferedReader FileReader)) | |
(defn form-seq | |
"Return lazy seq of forms in file at path. Closes reader only after | |
all forms are read." | |
[path] | |
(let [reader (-> path FileReader. BufferedReader. PushbackReader.) | |
eof (Object.) | |
next-form (fn next-form [] |
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.io File | |
BufferedWriter FileWriter | |
PushbackReader BufferedReader FileReader)) | |
(defn apply-code | |
[x code] | |
(apply (eval (first code)) | |
x | |
(rest (map eval code)))) |
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
;; warning: this is probably dangerous and stupid | |
(defmacro staticase | |
[expr & cases] | |
(let [case-pairs (partition 2 cases) | |
evaled-pairs (map (fn [[l r]] [(if (symbol? l) (eval l) l) r]) case-pairs) | |
evaled-cases (flatten evaled-pairs)] | |
`(case ~expr ~@evaled-cases))) |
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 ruby | |
# -*- coding: utf-8 -*- | |
# prints a sparkline in the terminal using the supplied list of numbers | |
# examples: | |
# spark.rb 10 20 30 100 90 80 | |
# spark.rb 1 2 0.4 0.1 1.3 0.7 | |
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇] | |
values = ARGV.map { |x| x.to_f } |
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 | |
for i in {1..1000} | |
do | |
fname=example-$(printf %08x $i).pdf | |
foo=$(basename $fname .pdf) | |
echo $i "=>" $fname | |
done |
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
;;;; Translation of Peter Norvig's sudoku solver to idiomatic Clojure | |
;;;; See http://norvig.com/sudoku.html | |
;;;; | |
;;;; Throughout this program we have: | |
;;;; r is a row, e.g. :a | |
;;;; c is a column, e.g. 3 | |
;;;; s is a square, e.g. [:a 3] | |
;;;; d is a digit, e.g. 9 | |
;;;; u is a unit, e.g. [[:a 1] [:b 1] [:c 1] ... [:i 1]] | |
;;;; grid is a grid, e.g. 81 non-blank chars, e.g. starting with ".18...7..." |
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
(ns anyclj.math) | |
(defn mean | |
"Returns the mean value of a dataset" | |
[coll] | |
(/ (apply + coll) (count coll))) | |
(defn median | |
"Returns the median value of a dataset" | |
[coll] |