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 assoc-autoinc [m k] | |
(if (get m k) | |
m | |
(let [v (inc (:last-value (meta m) -1))] | |
(with-meta | |
(assoc m k v) | |
(assoc (meta m) :last-value v))))) | |
(defn get-or-autoinc! [m k] | |
(if-let [v (get @m 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
(defn map-same | |
"like map, but returns a collection of the same type as the first input collection" | |
[f & colls] | |
(let [first-coll (first colls)] | |
(if (list? first-coll) | |
(list* (apply map f colls)) | |
(into (empty first-coll) (apply map f colls))))) |
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
user=> (defn audit-ns [ns] | |
(let [publics (ns-publics ns)] | |
(map key (remove #(let [m (-> % val meta)] (or (:doc m) (:added m))) publics)))) | |
#'user/audit-ns | |
user=> (audit-ns (find-ns 'clojure.core)) | |
(chunked-seq? find-protocol-impl chunk-buffer find-protocol-method EMPTY-NODE await1 -reset-methods *allow-unresolved-vars* proxy-call-with-super | |
munge print-doc *math-context* with-loading-context unquote-splicing chunk-cons chunk-append destructure -cache-protocol-fn print-dup | |
*use-context-classloader* proxy-name print-ctor chunk-rest method-sig print-method hash-combine chunk definterface unquote primitives-classnames | |
rational? chunk-first *source-path* *assert* print-special-doc chunk-next print-simple) |
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
;; routes.clj | |
(ns winston.ui.routes | |
(:use [clojure.contrib.except :only (throwf)]) | |
(:require [clojure.contrib.string :as str]))) | |
(defn path-for* [routefn route-args] | |
{:pre [routefn]} | |
(let [path (-> routefn meta ::http-path)] | |
(when (not path) |
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 System (getArgs) | |
import Data.Map hiding (map) | |
import Database.TokyoCabinet | |
import qualified Data.ByteString.Char8 as B | |
import Text.JSONb | |
fetch :: String -> Maybe Int -> TCM [(String,B.ByteString)] | |
fetch fileName maxElems = do | |
tc <- new :: TCM HDB -- alternatively you can use BDB or FDB | |
open tc fileName [OREADER] |
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 sig [x] | |
(:sig (meta (resolve x)))) | |
(defmulti type-of (comp type first list)) | |
(defmethod type-of :function [thing & _] (sig thing)) | |
(defmethod type-of java.util.List [expr & a] | |
(conj (map #(type-of % (first a)) (rest expr)) |
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 tokyo-read-reps [db-pathname & [proto str-load?]] | |
(let [ | |
proto (or proto Repliers) | |
init-params (let [par {:path db-pathname :read-only true}] | |
(if str-load? par | |
(merge par {:dump protobuf-dump :load (partial protobuf-load proto)}))) | |
db (tc/db-init init-params) | |
_ (tc/db-open db) | |
tc (:db db) | |
r (when (.iterinit tc) |
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
config: {"project.library.path"=>"/opt/local/lib"} | |
vars: {:script "bin/cake" :opts {:default ["deps"] :d [""]} :pwd "/s/w/clojure/cake" :args ["default" "-d" "deps"] :env {"MANPATH" "/s/src/srilm/current/bin:/s/src/srilm/current/bin/macosx/man:/opt/local/share/man:" "OLDPWD" "/Users/alexyk" "Apple_PubSub_Socket_Render" "/tmp/launch-QWcUGb/Render" "USER" "alexyk" "TMPDIR" "/var/folders/mw/mwJSf7ErEa4w8nWyKyyqD++++TY/-Tmp-/" "LC_CTYPE" "en_US.UTF-8" "TERM" "xterm-color" "DARCS_EMAIL" "[email protected] (Alexy Khrabrov)" "SSH_AGENT_PID" "474" "MAGICK_HOME" "/usr/local/ImageMagick" "GEM_HOME" "/Users/alexyk/.jgem" "PROMPT" "%~ " "SHLVL" "1" "__CF_USER_TEXT_ENCODING" "0x1F9:0:0" "LC_ALL" "en_US.UTF-8" "COMMAND_MODE" "legacy" "SHELL" "/bin/zsh" "DISPLAY" "/tmp/launch-VNuY4O/org.x:0" "LOGNAME" "alexyk" "LANG" "en_US.UTF-8" "DYLD_LIBRARY_PATH" "/usr/local/ImageMagick/lib" "PWD" "/s/w/clojure/cake" "PATH" "/opt/ocaml/bin:/opt/ocaml/sbin:/Users/alexyk/.cabal/bin:/opt/brew/bin:/Users/alexyk/bin:/opt/sbin:/opt/bin: |
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 printShowTable: tex -> ?verbose:bool -> | |
('a BatInnerIO.output -> 'b -> unit) -> | |
'c list list -> string -> unit = | |
fun tex ?(verbose=false) printOne table tableName -> | |
let oc = open_out tableName in | |
printTable oc tex printOne table tableName; | |
close_out oc; | |
if verbose then | |
printTable stdout tex printOne table tableName | |
else () |
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 read_lines ?skip ?maxn filename = | |
let ic = open_in filename in | |
let step,ctr = make_step_counter 0 in | |
E.from_while begin fun () -> | |
try | |
match skip,maxn with | |
| (Some s, _) when ctr () < s -> | |
ignore (input_line ic); step (); Some None | |
| (skip, Some n) when n > 0 && ctr () - (Option.default 0 skip) = n -> | |
close_in ic; None |