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
The regex patterns in this gist are intended to match any URLs, | |
including "mailto:[email protected]", "x-whatever://foo", etc. For a | |
pattern that attempts only to match web URLs (http, https), see: | |
https://gist.github.com/gruber/8891611 | |
# Single-line version of pattern: | |
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])) |
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
(defvar *buffer-size* 512) | |
(defun concatenate-vectors (total-length vectors) | |
"Given a list of VECTORS containing LENGTH octets in total, return a | |
single vector containing the same octets in the same order." | |
(let ((vector (make-string total-length))) | |
(loop for start = 0 then (+ start (length sub-vector)) | |
for sub-vector in vectors | |
do (replace vector (the (simple-string) sub-vector) | |
:start1 start)) |
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
;;;;;;;;;;;;;;;;;; | |
;; $Rev$ | |
;; textflow is a trivial generator of RFC like call flow (a.k.a sequence diagrams) | |
;; | |
;; Example usage: | |
;; (flow [Alice Bob Tzach] | |
;; [[mmm Tzach Bob] | |
;; [xxx Bob Alice] | |
;; [] | |
;; [zzz Alice Tzach]]) |
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
; #^{:doc "Iterator macro | |
; implements a simple and extendable iteration facility on top of clojure loop"} | |
(ns hoeck.iterate | |
(:use clojure.walk | |
clojure.contrib.macro-utils | |
clojure.contrib.except | |
clojure.test)) |
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
;; Example implementation of Norvig's Spellchecker in Clojure, | |
;; using core.async | |
;; | |
;; There are probably some bugs in this. | |
;; | |
;; Original problem: https://github.com/ericnormand/spelling-jam | |
;; from Lambda Jam, Chicago, 2013: http://lambdajam.com/ | |
;; | |
;; Clojure core.async introduction: | |
;; http://clojure.com/blog/2013/06/28/clojure-core-async-channels.html |
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 test-clj-byte-chunk-seq | |
(:import (java.io InputStream OutputStream | |
FileInputStream FileOutputStream))) | |
(set! *warn-on-reflection* true) | |
(def ^:const ONE_MEG (* 1024 1024)) | |
(deftype ByteArrayChunk [^bytes array ^int offset ^int end] | |
clojure.lang.IChunk |
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
;;; XML parsing and clojure.zip | |
;;; There's got to be a cleaner way to do this. | |
;;; I have code like this: | |
(defn jdks-loc [xml-zipper] | |
(zip/down | |
(first | |
(filter #(let [n (zip/node %)] |
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 resource | |
"Automatic resource cleanup." | |
(:import (java.lang.ref ReferenceQueue PhantomReference))) | |
(def ^:private queue (ReferenceQueue.)) | |
(def ^:private cleanup-fns {}) | |
(defn resource | |
"Returns a reference to x. At some point after the reference is |
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
(defn subscriber-seq | |
[ch qname] | |
(let [[message-seq put] (pipe)] | |
(letfn [(message-handler [ch msg-meta payload]) | |
(put {:ch ch :msg-meta msg-meta :payload payload})] | |
(lc/subscribe ch qname message-handler :auto-ack true)) | |
message-seq)) | |
(defn payload-str | |
[x] |
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
(let [[message-seq put] (pipe)] | |
(letfn [(message-handler [ch msg-meta payload]) | |
(put {:ch ch :msg-meta msg-meta :payload payload})] | |
(lc/subscribe ch qname message-handler :auto-ack true)) | |
message-seq) | |
(let [[message-seq put] (pipe)] | |
(letfn [(message-handler [ch msg-meta payload] | |
(put {:ch ch :msg-meta msg-meta :payload payload}))] | |
(lc/subscribe ch qname message-handler :auto-ack true)) |