Skip to content

Instantly share code, notes, and snippets.

View scotthaleen's full-sized avatar
λ

スコット scotthaleen

λ
View GitHub Profile
@scotthaleen
scotthaleen / lein_uberjar_git_rev.clj
Created December 6, 2016 17:52
add the latest git revision to the uberjar file name
;; add the latest git revision to the uberjar file name
(defproject foo "4.3"
;;....
:uberjar-name ~(str
"foo-%s"
(try
(str "-"
;; :require [clojure.string :as s]
(defn print-logo
" Prints a Cool logo "
[]
(letfn [(fn-str [& args] (s/join \newline args))]
(print (fn-str
""
""
""
@scotthaleen
scotthaleen / docker_kill.sh
Last active September 8, 2021 07:13
docker kill all
#stop all containers:
docker kill $(docker ps -q)
#remove all containers
docker rm $(docker ps -a -q)
#remove all docker images
docker rmi $(docker images -q)
#remove intermediate containers, use "build --rm" to avoid them
@scotthaleen
scotthaleen / flatten_html.clj
Created November 5, 2016 19:28
Flatten HTML
;;include [clj-tagsoup "0.3.0"]
(require '[pl.danieljanus.tagsoup :as tags])
;; each node's structure is as such
;; [:tag attr-map node node ....]
(defn flatten [x]
(tree-seq (comp keyword? first) (partial drop 2) x))
@scotthaleen
scotthaleen / smallest_jpg_bytes.txt
Last active June 10, 2024 15:00
Smallest Valid JPG
# http://web.archive.org/web/20111224041840/http://www.techsupportteam.org/forum/digital-imaging-photography/1892-worlds-smallest-valid-jpeg.html
FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 48 00 48 00 00 FF DB 00 43 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF C2 00 0B 08 00 01 00 01 01 01 11 00 FF C4 00 14 10 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 08 01 01 00 01 3F 10
# Base64 Encoded
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA=
@scotthaleen
scotthaleen / stream_to_bytes.clj
Created October 20, 2016 21:15
Clojure: read an io/stream to a byte array
(require '[clojure.java.io :as io])
(def fp "/path/to/file")
(defn stream->bytes [is]
(loop [b (.read is) accum []]
(if (< b 0)
accum
(recur (.read is) (conj accum b)))))
@scotthaleen
scotthaleen / clojure_classpath.clj
Created September 15, 2016 20:46
Get a list of what is on the classpath
(->> (ClassLoader/getSystemClassLoader)
.getURLs
(map #(.getFile %)))
;; Add a filter
(->> (ClassLoader/getSystemClassLoader)
.getURLs
(map #(.getFile %))
(filter #(clojure.string/includes? % "resources")))
@scotthaleen
scotthaleen / parsing_json.clj
Created September 9, 2016 19:44
json to clojure keyword map
(ns clean.json
(:require
[clojure.data.json :as json]
[clojure.string :as s])
(:refer-clojure :exclude [read read-string]))
(defn key->keyword [key-string]
(-> key-string
(s/replace #"([a-z])([A-Z])" "$1-$2")
(s/replace #"([A-Z]+)([A-Z])" "$1-$2")
@scotthaleen
scotthaleen / cut.clj
Created August 12, 2016 21:59 — forked from ghoseb/cut.clj
Cut macro from SRFI-26 in Clojure
;;; http://srfi.schemers.org/srfi-26/srfi-26.html
(defn ^:private cut*
[[a f] form]
(cond
(nil? form) [a f]
(seq? (first form))
(let [[arg-list xform] (cut* [[] '()] (first form))]
(recur [(reduce conj a arg-list) (concat f (list xform))] (next form)))
@scotthaleen
scotthaleen / curry.clj
Created August 11, 2016 21:31 — forked from sunilnandihalli/curry.clj
a macro to create fixed-arity curryable function in clojure
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]