Skip to content

Instantly share code, notes, and snippets.

View filipesilva's full-sized avatar

Filipe Silva filipesilva

  • Dublin, Ireland
View GitHub Profile
@filipesilva
filipesilva / datascript+xitdb.md
Created January 13, 2026 22:18 — forked from radarroark/datascript+xitdb.md
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

(ns pie-a-la-mode
(:require [clojure.core.async :as a]))
;; Concurrency example from The Pragmatic Programmers. Waiters check if there's
;; enough pie and ice cream before they sell an order, but if they don't
;; coordinate it's still possible to sell more than we have.
;;
;; The below code should return either :ok or :not-available for a given order.
(def recipes
@filipesilva
filipesilva / profile.js
Created July 19, 2019 14:40
Angular CLI profiling script
const fs = require("fs");
const path = require("path");
// Usage instructions:
// - open node_modules/@angular/cli/lib/init.js
// - replace the code below
// ```
// cli({
// cliArgs: process.argv.slice(2),
// inputStream: standardInput,
NM353851668766
LN353852700559
BC351914564584
FO447771501423
SA351936839220
FS353852190819
@filipesilva
filipesilva / self-rep.js
Created November 9, 2016 15:40
self-rep.js
let program = `
let program = \`#ref\`;
let delimiter = String.fromCharCode(92) + String.fromCharCode(96);
program = program.replace(\`#ref\`, program.replace(/\`/g, delimiter));
console.log(program);
`;
let delimiter = String.fromCharCode(92) + String.fromCharCode(96);
program = program.replace(`#ref`, program.replace(/`/g, delimiter));
console.log(program);
### Keybase proof
I hereby claim:
* I am filipesilva on github.
* I am filipematossilva (https://keybase.io/filipematossilva) on keybase.
* I have a public key whose fingerprint is 0179 763D 3D1D AFBC BCDC D3F0 44C2 1C75 D66E D0B2
To claim this, I am signing this object: