Skip to content

Instantly share code, notes, and snippets.

@just-sultanov
just-sultanov / bb.edn
Last active January 8, 2022 18:18
Typical project tasks using babashka
{:min-bb-version "0.6.1"
:tasks
{:requires ([babashka.fs :as fs]
[babashka.process :as proc]
[clojure.string :as str]
[clojure.pprint :as pprint])
;; Helpers
@borkdude
borkdude / klein.clj
Last active September 23, 2021 12:39
#!/usr/bin/env bb
;; Ported from https://gist.github.com/pyr/d5e17af9c572b681a57de52895437298 to babashka
;; klein aims to be a small joker script to mimick
;; most of leiningen's default behavior while minimizing
;; divergence from standard facilities provided by
;; tools.deps
;; This is built as a single file script to simplify
;; deployment and will avoid requiring any code beyond
@borkdude
borkdude / api_diff_bb.clj
Created January 8, 2021 10:13
Print API breakage warnings
#!/usr/bin/env bb
;; Example usage:
;; api_diff_bb.clj org.clojure/clojure "1.9.0" "1.10.1"
;; Output:
;; clojure/core_deftype.clj:587:1: warning: Arity 4 of clojure.core/emit-method-builder was removed.
;; clojure/core/reducers.clj:24:1: warning: clojure.core.reducers/compile-if was removed.
(require '[babashka.pods :as pods])
@borkdude
borkdude / api_diff.clj
Last active September 30, 2021 19:37
Print API breakage warnings
#!/usr/bin/env bash
#_" -*- mode: clojure; -*-"
#_(
"exec" "clojure" "-Sdeps" "{:deps {clj-kondo/clj-kondo {:mvn/version \"2020.12.12\"} org.clojure/tools.deps.alpha {:mvn/version \"0.9.857\"} org.slf4j/slf4j-nop {:mvn/version \"1.7.30\"} lambdaisland/deep-diff2 {:mvn/version \"2.0.108\"} juji/editscript {:mvn/version \"0.5.4\"}}}" "-M" "$0" "$@"
)
;; Example usage:
;; api_diff.clj org.clojure/clojure "1.8.0" "1.10.1" > /tmp/diff.txt
(require '[clj-kondo.core :as clj-kondo])
@knazarov
knazarov / full_text_search_tarantool.lua
Created September 23, 2020 08:00
Full text search example for Tarantool
#!/usr/bin/env tarantool
local pickle = require('pickle')
local yaml = require('yaml')
function trivec(str)
str = string.lower(str)
local vec = ""
@yogthos
yogthos / clojure-beginner.md
Last active July 5, 2024 11:20
Clojure beginner resources

Introductory resources

@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@cgrand
cgrand / restrict-map.clj
Created May 29, 2012 10:15
Restricting nested maps to keys of interest
;; I could have used a closed dispatch (aka cond) but you may find this version more enjoyable
;; the spec format is the one provided by BG
(defprotocol Selector
(-select [s m]))
(defn select [m selectors-coll]
(reduce conj {} (map #(-select % m) selectors-coll)))
(extend-protocol Selector