Skip to content

Instantly share code, notes, and snippets.

@mdr
mdr / gist:2753af206f4630421649c1c96f887d85
Created November 27, 2025 21:52
Advent of Code 2024, Day 1, Part 1: lambda calculus
((λa.λb.λc.(b (a c)) ((λd.λe.λf.(e (d f)) ((λg.λh.λi.(h (g i)) ((λj.λk.((j k) k) λl.λm.λn.(l (m n))) ((λo.λp.λq.(o (p q)) (((λr.(λs.(r λt.((s s) t)) λu.(r λv.((u u) v))) λw.λx.λy.λz.((z λA.λB.λC.(((w x) ((x y) A)) B)) y)) (λD.λE.λF.((D F) E) λG.λH.λI.((I G) H))) λJ.λK.K)) ((λL.(λM.(L λN.((M M) N)) λO.(L λP.((O O) P))) λQ.λR.λS.((S λT.λU.λV.(((R T) ((Q R) U)) S)) λW.λX.X)) ((λY.λZ.λaa.((Y aa) Z) ((λab.λac.(ac ab) λad.λae.(((((λaf.λag.λah.λai.(((ai af) ag) ah) λaj.((((λak.λal.λam.λan.(((an ak) al) am) λao.λap.ao) λaq.λar.λas.as) λat.at) ((λau.(λav.(av av) λaw.(au (aw aw))) λax.(((λay.λaz.λaA.λaB.(((aB ay) az) aA) λaC.λaD.λaE.aC) λaF.(λaG.λaH.λaI.λaJ.(aI (((aG aH) aI) aJ)) (ax aF))) λaK.(λaL.λaM.λaN.λaO.(aO (((aL aM) aN) aO)) (ax aK)))) aj))) λaP.(((λaQ.λaR.λaS.λaT.(((aT aQ) aR) aS) λaU.λaV.aV) λaW.(aP aW)) λaX.λaY.λaZ.aZ)) λba.λbb.(((bb (ba bb)) λbc.λbd.λbe.be) λbf.(ba bf))) ad) ((((λbg.λbh.λbi.λbj.(((bj bg) bh) bi) λbk.λbl.λbm.bk) λbn.λbo.λbp.λbq.(bp bn)) λbr.λbs.λbt.λbu.(bu br)) ae))) (λbv.λbw.λbx.(bv (bw bx)
@mdr
mdr / naturalDeduction.kt
Last active May 19, 2021 17:33
Natural deduction translation into Kotlin
@file:Suppress("NonAsciiCharacters")
sealed class Either<out A, out B>
data class Left<out A> constructor(val value: A) : Either<A, Nothing>()
data class Right<out B> constructor(val value: B) : Either<Nothing, B>()
typealias `∧`<φ, ψ> = Pair<φ, ψ>
typealias `∨`<φ, ψ> = Either<φ, ψ>
const loadSpec = async () => ({
given: () => "I have 100 shares of MSFT stock",
when: () => "When I ask to sell 20 shares of MSFT stock",
then: () => "Then I should have 80 shares of MSFT stock"
})
const printSpec = async () => {
const { given, when, then } = await loadSpec()
console.log(given())
console.log(when())
@mdr
mdr / Graph.scala
Created February 11, 2020 08:18
DAG
// Implementation of DAGs based on:
// Jeremy Gibbons, An Initial-Algebra Approach to Directed Acyclic Graphs, 1995
// https://www.researchgate.net/publication/2423982_An_Initial-Algebra_Approach_to_Directed_Acyclic_Graphs
//
// Good:
// ✅ Immutable, compositional representation that supports structural sharing
// ✅ Correct by construction: no way to create cyclic graphs, so no need to check
// ✅ Some graph operations are easy: topological sort, certain replacement graph transformations
// ✅ Cool underlying theory: graphs are arrows in a symmetric monoidal category
// ⚠️ Extensions to the default idea of a DAG: supports multiple edges between the same vertices, ordered ports, and
@mdr
mdr / gist:915a269a6a314d49f90041736480c5a4
Created October 28, 2019 07:58
debugDumpApp exception
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
'dart:ui/hash_codes.dart': Failed assertion: line 15: '<optimized out>': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
When the exception was thrown, this was the stack:
class AsyncSerializer {
constructor() {
this._previousPromise = Promise.resolve(null)
}
serialize = f => {
const newPromise = this._previousPromise.then(() => f())
this._previousPromise = newPromise
return newPromise
}
import React from 'react'
import { shallow } from 'enzyme'
const flushPromises = () => new Promise(resolve => setImmediate(resolve))
const fetchTheData = jest.fn()
class MyContainerComponent extends React.Component {
state = { error: null }
package gems.user.service
import com.google.inject.ImplementedBy
import com.google.inject.Inject
import gems.user.dao.UserDao
import gems.user.dao.entity.User
import gems.user.service.dto.Credentials
import gems.user.service.session.Session
import gems.user.service.session.SessionManager
backend | 15:51:16.951 [main] DEBUG Application - Class Loader: sun.misc.Launcher$AppClassLoader@75b84c92: [/home/gradle/app/backend/build/classes/java/main, /home/gradle/app/backend/build/classes/kotlin/main/, /home/gradle/app/backend/build/resources/main/, /home/gradle/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-server-netty/0.9.2/3ec623b4e61942af1968f44adf00ed14411705f3/ktor-server-netty-0.9.2.jar, /home/gradle/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-auth-jwt/0.9.2/e156bae7c5e75a2492822c7ebfb4611a51c09b55/ktor-auth-jwt-0.9.2.jar, /home/gradle/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-auth/0.9.2/cc9bcc5bd3fd1604071c6f25aa42fc3dfa9c615c/ktor-auth-0.9.2.jar, /home/gradle/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-jackson/0.9.2/424f4a16296755e21219d65190e03eac53b0843b/ktor-jackson-0.9.2.jar, /home/gradle/.gradle/caches/modules-2/files-2.1/org.mpierce.ktor.csrf/ktor-csrf/0.3.0/defdb620ad156ac64c265f0dcf3bdd1fb78f2bb9/ktor-csrf-0.3.0.jar, /home/gradle/.gradle/caches/modules-2/files-2.1
@mdr
mdr / Refuct.java
Created December 3, 2014 22:24
Refuct.java
strictfp \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0052\u0065\u0066\u0075\u0063\u0074\u0020\u007b
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu0020
interface λ<A, B> {
public B call(A x);
}
interface RecursiveFunc<F> extends λ<RecursiveFunc<F>, F> {
}
private static boolean isDivisibleBy(int n, final int m) {