Skip to content

Instantly share code, notes, and snippets.

View core.clj
(ns core
[clj-http.client :as http]
[cheshire.core :as json]
[ring.adapter.jetty :refer [run-jetty]]))
;; Clojure sequences can be chunked in batches of 32 items
;; for the test I want to emit items one at a time
(defn unchunk [s]
nbardiuk / aoc-stats-tree.user.js
Last active Dec 20, 2020
Render AoC stats as christmass tree
View aoc-stats-tree.user.js
// ==UserScript==
// @name AoC stats tree
// @namespace
// @version 0.2
// @description Render AoC stats as christmass tree
// @author nbardiuk
// @match*/stats
// @license MIT License
// @copyright Copyright (C) 2020, by Nazarii Bardiuk
// @grant none
nbardiuk / script.clj
Last active Nov 28, 2020
Clojure shebang wtih arguments
View script.clj
#!/usr/bin/env -S clj -Sdeps '{:deps {clj-http/clj-http {:mvn/version "3.11.0"} cheshire/cheshire {:mvn/version "5.10.0"}}}'
(require '[clj-http.client :as http])
(require '[cheshire.core :as json])
(require '[clojure.pprint :refer [pprint]])
(let [url (or (first *command-line-args*) "")
{:keys [body headers]} (http/get url)]
(pprint headers)
(pprint (json/decode body)))
nbardiuk / Makefile
Last active Oct 14, 2020
Clojure tdd (test watch) using headless lein and rep
View Makefile
.PHONY: tdd
tdd: .nrepl-port
watchexec --clear --no-shell rep '(repl/refresh)(doto "$(only)" (run-tests))'
.PHONY: kill-repl
@if [ -f .nrepl-port ];\
kill $$(lsof -ti ":$$(cat .nrepl-port)" -sTCP:LISTEN) ;\
View moving-avarage.clj
(defn- slide [window x]
(-> window (subvec 1) (conj x)))
(defn- windows [n xs]
(let [first-window (vec (take n xs))
the-rest (drop n xs)]
(when (and (< 0 n) (= n (count first-window)))
(reductions slide first-window the-rest))))
(defn- avarage [xs]
nbardiuk / escape.vim
Last active Jan 30, 2020
Vim escape javascript string
View escape.vim
" paste escaped java/javascript string
nmap <leader>jp :call setreg('e', json_encode(@+))\| normal "ep<CR>
xmap <leader>jp :<C-U>call setreg('e', json_encode(@+))\| normal gv"ep<CR>
nmap <leader>jP :call setreg('e', json_encode(@+))\| normal "eP<CR>
" yank unescaped java/javascript string
xmap <leader>jy :<C-U>execute 'normal! gv"ey'\| :call setreg('+', json_decode(@e))<CR>
nbardiuk / .vimrc
Created Jan 25, 2020
sexp element pair
View .vimrc
" emulate text object for pair of elements
" i.e. key/value binding/expr test/expr
" pair forward
xmap <buffer> ip <Plug>(sexp_inner_element)<Plug>(sexp_move_to_next_element_tail)
omap <buffer> ip :<C-U>normal vip<CR>
" pair backward
xmap <buffer> iP <Plug>(sexp_inner_element)o<Plug>(sexp_move_to_prev_element_head)
omap <buffer> iP :<C-U>normal viP<CR>
import java.util.Arrays;
import java.util.function.BiFunction;
import java.util.function.Function;
class Scratch {
public static void main(String[] args) {
Monoid<Integer> sum = Monoid.of(0, Integer::sum);
Fold<String, Integer> sumStrings = Fold.of(Integer::parseInt, sum);
Integer result = sumStrings.fold(Arrays.asList("1", "2", "3"));
nbardiuk / .cvimrc
Last active Mar 21, 2018
cvim options
View .cvimrc
let defaultengine="duckduckgo"
let smoothscroll="true"
let scrollduration="200"
map J nextTab
map K previousTab

How to GPG as a Scala OSS Maintainer

tl;dr Generate a GPG key pair (exercising appropriate paranoia). Send it to key servers. Create a Keybase account with the public part of that key. Use your keypair to sign git tags and SBT artifacts.

GPG is probably one of the least understood day-to-day pieces of software in the modern developer's toolshed. It's certainly the least understood of the important pieces of software (literally no one cares that you can't remember grep's regex variant), and this is a testament to the mightily terrible user interface it exposes to its otherwise extremely simple functionality. It's almost like cryptographers think that part of the security comes from the fact that bad guys can't figure it out any more than the good guys can.

Anyway, GPG is important for open source in particular because of one specific feature of public/private key cryptography: signing. Any published software should be signed by the developer (or company) who published it. Ideally, consu