Skip to content

Instantly share code, notes, and snippets.

@ghoseb
ghoseb / ns-cheatsheet.clj
Last active May 20, 2024 13:01 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
@nazgob
nazgob / ctags.setup
Created January 6, 2012 13:44
ctags setup on mac
# you have ctags but it does not work...
$ ctags -R --exclude=.git --exclude=log *
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
#you need to get new ctags, i recommend homebrew but anything will work
$ brew install ctags
#alias ctags if you used homebrew
$ alias ctags="`brew --prefix`/bin/ctags"
@scottdw
scottdw / stats.clj
Created June 20, 2012 14:07
Some helper functions in Clojure for statistics
(ns stats)
(defn mode [vs]
(let [fs (frequencies vs)]
(first (last (sort-by second fs)))))
(defn quantile
([p vs]
(let [svs (sort vs)]
(quantile p (count vs) svs (first svs) (last svs))))
@ct27stf
ct27stf / font-stacks.css
Created July 7, 2012 18:11
Similar looking fonts for Windows, Linux, Mac
.mono-font-stack {
font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
}
.times-font-stack {
font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
}
.modern-font-stack {
font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif;
@john2x
john2x / 00_destructuring.md
Last active July 9, 2024 01:38
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@tawus
tawus / byte_range.file.clj
Last active December 11, 2023 13:51
byte range aware file-response for ring
(ns byte-range.file
(:require [ring.util.response :as ring-resp :refer
[header status get-header content-type]]
[ring.util.time :refer [parse-date format-date]]
[ring.util.request :as request]
[ring.util.codec :as codec]
[pantomime.mime :refer [mime-type-of]]
[clojure.string :as str]
[clojure.java.io :as io])
(:import [java.io RandomAccessFile]
(ns experimental-clojure.congeal-consecutives)
(def v [1 3 4 5 7 9 10 11 12])
(defn congeal-consecutives [coll]
(->> coll
(map-indexed (fn [i x] [(- x i) x]))
(partition-by first)
(mapv (fn [pairs]
(mapv second pairs)))))
@valichek
valichek / gist:6bff5ff0ff626aaea666
Last active November 4, 2021 20:35
Thread safe println #clojure #debug
;http://yellerapp.com/posts/2014-12-11-14-race-condition-in-clojure-println.html
(defn safe-println [& more]
(.write *out* (str (clojure.string/join " " more) "\n")))
@paul356
paul356 / clojure-ctags.md
Last active November 7, 2022 14:35
Add Clojure support to exuberant ctags and vim-tagbar

ctags

Add the following to ~/.ctags (thanks, xzj / clojure.ctags):

--langdef=Clojure
--langmap=Clojure:.clj
--langmap=Clojure:+.cljs
--langmap=Clojure:+.cljx
--regex-clojure=/\([ \t]*create-ns[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/n,namespace/
--regex-clojure=/\([ \t]*def[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/d,definition/
@dims
dims / Dockerfile
Last active May 10, 2022 21:48
Experiment with Kubernetes with a custom Docker Image
FROM python:3
EXPOSE 8000
CMD ["python", "-m", "http.server"]