Skip to content

Instantly share code, notes, and snippets.

View elfenlaid's full-sized avatar
🐧
Slow Distillation ⚗️💭

Egor Mihnevich elfenlaid

🐧
Slow Distillation ⚗️💭
View GitHub Profile
defmodule CollectionListener do
use GenServer
defstruct [:topology, :collection, :handler, :cursor_task, :token]
@impl true
def init(args) do
topology = Keyword.fetch!(args, :topology)
collection = Keyword.fetch!(args, :collection)
handler = Keyword.fetch!(args, :handler)
@elfenlaid
elfenlaid / CodableVersioning.swift
Created October 17, 2022 09:18 — forked from nicklockwood/CodableVersioning.swift
Example demonstrating how to use versioning for Codable structs
// This gist demonstrates how you can implement versioning for a Codable struct to support loading
// old serialized data after changing the structure. Notable features of this solution:
//
// * No need to make new properties optional, or to perform post-processing on the struct after
// loading in ordeer to populate missing values
// * No need to change the call site - from the outside this struct behaves just the same
// as if we had implemented codable directly in the normal way.
// * Versioning can be applied individually to parents or leaves in a larger tree of
// structs without affecting the other elements
// * This approach will work even if the original struct was not designed with versioning in mind
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@elfenlaid
elfenlaid / States-v3.md
Created July 20, 2022 07:51 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@elfenlaid
elfenlaid / HeterogeneousDictionary.swift
Created April 22, 2022 18:50 — forked from ole/HeterogeneousDictionary.swift
Code for my article "A heterogeneous dictionary with strong types in Swift" https://oleb.net/2022/heterogeneous-dictionary/
// A heterogeneous dictionary with strong types in Swift, https://oleb.net/2022/heterogeneous-dictionary/
// Ole Begemann, April 2022
/// A key in a `HeterogeneousDictionary`.
public protocol HeterogeneousDictionaryKey {
/// The "namespace" the key belongs to. Every `HeterogeneousDictionary` has its associated domain,
/// and only keys belonging to that domain can be stored in the dictionary.
associatedtype Domain
/// The type of the values that can be stored under this key in the dictionary.
associatedtype Value
@elfenlaid
elfenlaid / issues.json
Last active June 10, 2021 05:52
Good First Issue Repositories
[
"easy-first-issue",
"starter-task",
"difficulty: easy",
"difficulty: moderate",
"difficulty: medium",
"difficulty: just a custom template away! easiest way to contribute!",
"difficulty: beginner",
"difficulty: intermediate",
"easy contribution",
@elfenlaid
elfenlaid / logs.swift
Created May 21, 2021 07:46
Custom Swift String Interpolation: Logs Privacy
struct Message {
enum Privacy {
case `public`
case `private`
}
var value: String
}
extension Message: CustomStringConvertible {
{
"owner": "SwiftPackageIndex",
"name": "SwiftPackageIndex-Server"
}
@elfenlaid
elfenlaid / README.md
Created April 28, 2021 06:38
Tailwind typography dark scheme