Skip to content

Instantly share code, notes, and snippets.

(defn truncate [coll t]
(let [c coll
ct (first c)
rt (second c)]
[(if (>= (count ct) t)
(apply str (take t ct) "...")
ct)
(if (>= (count rt) t)
(apply str (take t rt) "...")
rt)]))
(defn truncate
"A one off truncation function which takes a coll in the form of \"[:a, :b]\". Provided a [t]runcation length (in characters), it will truncate :a or :b and supply a new \"[\":a...\", \":b...\"]\"."
[coll t]
(let [c coll
ct (first c)
rt (second c)]
[(if (>= (count ct) t)
(apply str (take t ct) "...")
ct)
(if (>= (count rt) t)
@devn
devn / core.clj
Created April 1, 2010 16:16 — forked from Licenser/core.clj
(defn truncate [t coll]
(map (fn [ct]
(if (>= (count ct) t)
(apply str (take t ct) "...")
ct)) coll))
(defn walton*
[#^String s t m?]
(let [result (walton-doc s)]
(ns walton.core
(:use clojure.contrib.duck-streams
clojure.contrib.str-utils
clojure.contrib.seq-utils
clj-html.core
net.licenser.sandbox
walton.integration
walton.web
ring.util.response)
(:gen-class))
;; load paths
(setq dotfiles-dir (file-name-directory
(or (buffer-file-name) load-file-name)))
(add-to-list 'load-path dotfiles-dir)
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
(let* ((my-lisp-dir "~/.emacs.d/elpa-to-submit")
(default-directory my-lisp-dir))
(setq load-path (cons my-lisp-dir load-path))
(defn connect [server]
(let [socket (Socket. (:name server) (:port server))
in (BufferedReader. (InputStreamReader. (.getInputStream socket)))
out (PrintWriter. (.getOutputStream socket))
conn (ref {:in in :out out})]
(doto (Thread. #(conn-handler conn)) (.start))
conn))
(defn write [conn msg]
(doto (:out @conn)
Warning: The file properties have changed:
File: /usr/bin/dpkg
Current hash: 8e820f6ffa1ba84be7c5256a8bd344a49fec7182
Stored hash : 7c5ab2420dfddf22f3794a1f2aa4b61243e44a08
Current inode: 52015 Stored inode: 1969
Current file modification time: 1268271700
Stored file modification time : 1253435089
Warning: The file properties have changed:
File: /usr/bin/dpkg-query
Current hash: b5a6de09d70cd24592cb59dbdd2d58e9280a7cc0
(ns walton.layout
(:use [hiccup core page-helpers form-helpers]
walton.core))
(defn application [text body]
(html
[:html
[:head
(include-js "../../resources/public/javascript/syntaxhilighter/scripts/shCore.js"
"../../resources/public/javascript/syntaxhilighter/scripts/shBrushClojure.js")
(defn rand-range [m n]
(+ m (rand-int (- n m))))
(defn with-transient [x f]
(persistent! (f (transient x))))
(defn swap-entries! [x i j]
(assoc! x i (x j) j (x i)))
(defn knuth-shuffle [xs]
(defn check-user
"Checks the nickname of the user. This functions as a basic authorization check for commands like \"!join\"."
[nick f]
(if (= nick "defn")
f
nil))
(def bot-fnmap
{:on-message
(fn [{:keys [nick channel message irc]}]