Skip to content

Instantly share code, notes, and snippets.

View ahmed1hsn's full-sized avatar
🎯
Focusing

Ahmed Hassan ahmed1hsn

🎯
Focusing
View GitHub Profile
@radarroark
radarroark / datascript+xitdb.md
Last active January 16, 2026 12:49
Datascript + xitdb: your humble, single-file, mini Datomic

xitdb-clj is a new immutable database for Clojure. It can time travel like Datomic, and store data in a single file like SQLite. On its own, though, it has no query language. Enter Datascript...

Datascript is normally an in-memory database, but it lets you use anything as backing storage. What if we combined them?

Datascript's storage feature doesn't tell us exactly what changed, so I added one more trick: Editscript, the diffing library. I use it to figure out how to update the database with the minimal number of changes.

The end result is a sort of mini Datomic that writes to a single file. And yet, this setup can do something Datomic can't: it can branch off of any old copy of the database. The example below reverts to an older copy of the database.

Keep in mind that all reads and writes are incremental. The database is not being loaded into memory at once, so you can use it to

@mlabbe
mlabbe / microjournal.el
Created December 6, 2025 19:52
Microjournal
(defcustom microjournal-path "~/.journal.org.gpg"
"name for the microjournal file"
:type 'file
:group 'microjournal)
(defun microjournal-insert-year ()
"Create a root header for the current year if it doesn't exist"
(interactive)
(let ((header-name (format-time-string "%Y")))
(goto-char (point-max))
@daveliepmann
daveliepmann / assert-or-not.md
Last active March 2, 2025 12:24
A guide to orthodox use of assertions in Clojure.

When to use assert?

In JVM Clojure, Exceptions are for operating errors ("something went wrong") and Assertions are for programmer and correctness errors ("this program is wrong").

An assert might be the right tool if throwing an Exception isn't enough. Use them when the assertion failing means

  • there's a bug in this program (not a caller)
  • what happens next is undefined
@henryw374
henryw374 / flexi_clock.clj
Created October 17, 2024 16:11
clojure java.time clock
(ns flexi-clock
(:import (java.time Clock Duration Instant ZonedDateTime)))
(defn clock
"potential library function (e.g. in tick or tempo).
This just implements the platform Clock - which works because non-test code only uses that API.
Any manipulation of time (which happens in testing code) is done via changing
what get-instant and get-zone return"
[get-instant get-zone]
@WebReflection
WebReflection / sqlite-as.md
Last active January 25, 2025 15:12
Bun sqlite `.as(Class)` alternative

This is a simple demo of how latest Bun could've implemented .as(Class) instead of using the quite jurassic Object.create which is slow, bloated due descriptors logic, if used at all, and incapable to play nicely with features introduced after Object.create was even specified.

// what `as(Class)` should return
const { assign } = Object;
const asClass = new WeakMap;
const setAsClass = Class => {
  class As extends Class {
    constructor(fields) {
      assign(super(), fields);
@rafd
rafd / flowstorm.md
Last active March 30, 2025 12:27
Ideal FlowStorm Setup

FlowStorm Quickstart

FlowStorm is a time-travelling debugger for clojure.

IMO, Clojure has the best development experience with its REPL-driven workflow. FlowStorm makes it even better.

Most notably:

  • "time-traveling" retrospective debugger (walk forward and backward, search for values)
  • zero-config tap> destination
  • retroactively add print statements to previous evaluations
@shvets-sergey
shvets-sergey / jst.clj
Created August 14, 2023 00:54
Implements a hiccup-like compiler into js templates
(ns jst
(:require [camel-snake-kebab.core :as csk]
[clojure.string :as string]
[hyperfiddle.rcf :refer [tests]]))
(hyperfiddle.rcf/enable!)
;; Implements a hiccup compiler into js-template.
;;
;; Usage: (jst cljs-symbol? template-fn? hiccup), where:
;; cljs-symbol - what symbol implements js-template in cljs (default: shadow.cljs.modern/js-template)
@dustingetz
dustingetz / electric-references.md
Last active June 5, 2025 13:07
Reference list — Electric Clojure

References — Electric Clojure

Electric Clojure implements a form of arrowized continuous time dataflow programming with extensions for network-transparent function composition.

@dustingetz
dustingetz / missionary-concept-map.md
Last active October 24, 2025 14:56
Missionary concept map

Missionary concept map

Missionary primitives fit into three categories:

Effect descriptions = pure functional programming which is about trees not graphs

  • continuous flow, m/?< (switch)
  • m/watch, m/latest, m/cp
  • m/observe
  • m/reductions, m/relieve
@pmonks
pmonks / java-members.clj
Last active August 20, 2025 15:39
Pretty prints results from clojure.reflect/reflect on an object or class in an idiomatic Clojure fashion
;
; Copyright © 2023 Peter Monks
;
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at https://mozilla.org/MPL/2.0/.
;
; SPDX-License-Identifier: MPL-2.0
;