Skip to content

Instantly share code, notes, and snippets.

@mvarela
mvarela / ibid.clj
Created February 2, 2020 09:39
A solution for the "Ibid." problem proposed by Gene Kim here: https://twitter.com/RealGeneKim/status/1201922587346866176?ref_src=twsrc%5Etfw. We avoid explicit recursion
(defn replace-ibids [coll]
(letfn [(go [{:keys [acc latest]} e]
(if (and (= e "Ibid.")
(some? latest))
{:acc (conj acc latest) :latest latest}
{:acc (conj acc e) :latest e}))]
(if (= "Ibid." (first coll))
(ex-info "Invalid ibid" {})
(-> (reduce go {:acc []} coll)
:acc))))
@mtnygard
mtnygard / responses.clj
Last active July 16, 2019 20:16
Build Pedestal response maps for every standard HTTP status code.
(defn response
([status body]
{:status status
:headers {}
:body body}))
(defmacro http-status [code sym]
`(def ~sym (partial response ~code)))
(defmacro http-statuses [& pairs]
@seancorfield
seancorfield / README.md
Last active October 28, 2022 04:11
map-vals and map-keys

NOTE: Clojure 1.11 Alpha 2 added update-keys and update-vals which provide similar functionality directly in clojure.core, but with the hash map first and the function second.

Running this code:

clj -Sdeps '{:deps 
             {seancorfield/map-utils 
              {:git/url "https://gist.github.com/seancorfield/6e8dd10799e9cc7527da5510c739e52f"
               :sha "cfde3c2c83379e93ab1a49752611ae663008129f"}}}'

That starts a REPL:

Set rz and sz on Mac

There are a mess of troubles in sending and receiving files from my macbook to dev server, since I had no permission to excute command scp on dev server. Here is a lightweight, quick, and convenience tools which related with ssh, called lrzsz. lrzsz is a unix communication package providing the XMODEM, YMODEM, ZMODEM file transefer protocol which usually has been already installed in most of servers.

Prerequisites

  • iTerm2 is necessary. [Here][] is the official website.
@stathissideris
stathissideris / tree-seq-extra.clj
Last active July 2, 2023 11:33
Like Clojure's tree-seq, but with depth info for each node or the full path (recursive - blow up the stack for deep trees)
(defn tree-seq-depth
"Returns a lazy sequence of vectors of the nodes in a tree and their
depth as [node depth], via a depth-first walk. branch? must be a fn
of one arg that returns true if passed a node that can have
children (but may not). children must be a fn of one arg that
returns a sequence of the children. Will only be called on nodes for
which branch? returns true. Root is the root node of the tree."
[branch? children root]
(let [walk (fn walk [depth node]
(lazy-seq
@michaelt
michaelt / latex.template
Created June 9, 2011 21:23
Simple Pandoc default.latex with comments
%!TEX TS-program = xelatex
\documentclass[12pt]{scrartcl}
% The declaration of the document class:
% The second line here, i.e.
% \documentclass[12pt]{scrartcl}
% is a standard LaTeX document class declaration:
% we say what kind of document we are making in curly brackets,
% and specify any options in square brackets.