Skip to content

Instantly share code, notes, and snippets.

@kawas44
kawas44 / build.clj
Created March 25, 2024 22:55
Add tools.build to Missionary
(ns build
(:require [clojure.tools.build.api :as b]))
(def lib 'missionary/missionary)
(def version "b.34p") ;;;; warning: local version
(def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
;; delay to defer side effects (artifact downloads)
(def basis (delay (b/create-basis {:project "deps.edn"})))
@kawas44
kawas44 / reducible.clj
Created July 31, 2023 19:53
Play with Clojure IReduceInit interface
(ns reducible
(:require [clojure.java.io :as io])
(:import (clojure.lang IReduceInit)))
(defn file-lines
"Returns a reducible collection over lines of a file.
It is not lazy and releases resources when reduction ends."
[filepath]
(reify IReduceInit
(reduce [_this rf start]
@kawas44
kawas44 / 50-libinput.conf
Created June 18, 2023 11:34
Xorg libinput & synaptics
Section "InputClass"
Identifier "Kensington Eagle Trackball"
MatchProduct "Primax Kensington Eagle Trackball"
MatchDriver "libinput"
Option "Rotation Angle" "270.0"
EndSection
Section "InputClass"
Identifier "Nulea Trackball"
MatchProduct "Compx 2.4G Receiver Mouse"
@kawas44
kawas44 / logback.xml
Last active February 13, 2024 09:18
Just enough Clojure data logging with Logback and LogstashEncoder
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration debug="true">
<import class="ch.qos.logback.core.ConsoleAppender"/>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.core.rolling.RollingFileAppender"/>
<import class="ch.qos.logback.classic.filter.ThresholdFilter"/>
<import class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"/>
<import class="net.logstash.logback.encoder.LogstashEncoder"/>
@kawas44
kawas44 / assoc-some.clj
Created March 23, 2022 14:55
assoc-some
(defn assoc-some
([m k v]
(cond-> m
(some? v) (assoc k v)))
([m k v & kvs]
{:pre [(even? (count kvs))]}
(reduce (fn [acc [k v]]
(assoc-some acc k v))
(assoc-some m k v)
(partition 2 kvs))))
@kawas44
kawas44 / attributes
Last active March 1, 2022 19:17 — forked from amalloy/.gitattributes
Clojure-aware git-diff hunk headers
;; save user defined attributes in default location:
;; ~/.config/git/attributes
*.clj diff=clojure
*.cljs diff=clojure
*.cljc diff=clojure
@kawas44
kawas44 / varargs.clj
Last active February 8, 2022 09:51
Clj var-args helpers
;;;; Varargs helpers
(defn- simple-name
[s]
(if-let [idx (str/index-of s \$)] (subs s (inc idx)) s))
(defn- helper-name
[cls]
(-> (simple-name cls)
(str/replace #"([a-z0-9])([A-Z]+)" "$1-$2")
@kawas44
kawas44 / my-i3status.sh
Last active September 25, 2019 14:01
Show current keyboard layout in i3status bar
#!/bin/bash
# Script to show current keyboard layout in i3status bar
# Requires https://github.com/nonpop/xkblayout-state
# Inspiration from https://github.com/vzaliva/scripts_and_configs/blob/master/scripts/i3status.sh
# set your keymap as you wish
# ex: setxkbmap -layout 'us,us,fr' -variant 'mac,colemak,oss' -option grp:ctrls_toggle -option caps:escape