This file contains 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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"strings" | |
) |
This file contains 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
(defn insert-after | |
[pred coll x] | |
(let [[before after] (split-with (complement pred) coll)] | |
(concat before (take 1 after) x (drop 1 after)))) | |
(defn insert-before | |
[pred coll x] | |
(let [[before after] (split-with (complement pred) coll)] | |
(concat before x after))) |
This file contains 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
(defn split-after | |
[pred coll] | |
(let [post-accum (fn [accum x] | |
(update accum :after conj x)) | |
pre-accum (fn [accum x] | |
(cond-> (update accum :before conj x) | |
(pred x) (assoc :f post-accum)))] | |
((juxt :before :after) | |
(reduce (fn [{:keys [f] :as accum} x] (f accum x)) | |
{:before [] :after [] :f pre-accum} |
This file contains 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 sliding-window-counter.core | |
(:refer-clojure :exclude [inc])) | |
(defprotocol ICounter | |
(reset [this]) | |
(inc [this]) | |
(value [this])) | |
(defrecord SlidingWindowCounter [window-size bucket-size num-buckets buckets] | |
ICounter |
This file contains 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 square-roots | |
(:require [criterium.core :refer [bench]])) | |
(defn square [x] (* x x)) | |
(defn abs [x] (if (< 0 x) (- x) x)) | |
(defn sqrt-repeated-average | |
[x lo hi tolerance] | |
(if (<= (- hi lo) tolerance) |
This file contains 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 ring-of-primes | |
(:gen-class)) | |
(defn prime? | |
[n] | |
(and (> n 1) | |
(not-any? #(zero? (mod n %)) (range 2 (inc (int (Math/sqrt n))))))) | |
(defn neighbours | |
[xs ring] |
This file contains 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
# cms - simple CMS | |
# | |
# The simple-cms server is a Compojure application serving content for cms.1729.org.uk | |
description "CMS server" | |
start on filesystem or runlevel [2345] | |
stop on runlevel [!2345] | |
respawn |
This file contains 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
(require '[clojure.java.io :as io]) | |
(require '[oauth.twitter :refer [oauth-client]]) | |
(defn read-properties | |
"Parse a properties file, convert the property keys to Clojure | |
keywords and return as a Clojure map." | |
[resource-name] | |
(when-let [resource (io/resource resource-name)] | |
(let [properties (java.util.Properties.)] | |
(with-open [stream (io/input-stream resource)] |
This file contains 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
(defn expand-partition | |
"Given a partition of size n and an element, generate n new | |
partitions by adding `element` to each subset in turn." | |
[partition element] | |
(let [partition (vec partition)] | |
(for [i (range (count partition))] | |
(set (update-in partition [i] #(conj % element)))))) | |
(defn partitions | |
"Return all partitions of the set `X` into `n` non-empty subsets. |
This file contains 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
(defn filter-file [filename] | |
(with-open [rdr (io/reader filename)] | |
(reduce (fn [words line] | |
(into words (filter #(<= 4 (count %) 9) (str/split line #"\s+")))) | |
#{} | |
(line-seq rdr)))) |
NewerOlder