Skip to content

Instantly share code, notes, and snippets.

View kalexmills's full-sized avatar

Alex Mills kalexmills

View GitHub Profile
@kalexmills
kalexmills / path.go
Created August 15, 2023 17:12
A Simple Path struct for moving between points in sequence.
package main
// Path represents a looping sequence of points which are interpolated between.
// FIXME: this doesn't loop properly at the moment. It will need to be recreated whenever the animation completes.
type Path struct {
sequence *gween.Sequence
points []image.Point
idx int
}

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@kalexmills
kalexmills / DDL.sql
Last active November 12, 2020 16:13
CTEs for Hierarchical Data / Threaded Comments
-- sqlite3 flavored SQL
CREATE TABLE comment (
id INTEGER PRIMARY KEY ASC,
parent_id INTEGER,
content TEXT NOT NULL,
create_time TEXT NOT NULL,
is_deleted INTEGER DEFAULT 0,
FOREIGN KEY(parent_id) references comment(id)
@kalexmills
kalexmills / streamingio.go
Last active May 25, 2020 14:04
Filtered readers w/out extra buffer allocations (golang)
package main
import (
"fmt"
"io"
"log"
"strings"
)
func main() {
@kalexmills
kalexmills / Link.scala
Last active April 1, 2020 00:55
Hand-over-hand locking for cats-effect, along with as many type-classes as I could reasonably cram in.
@kalexmills
kalexmills / async-cbor.rs
Last active January 17, 2020 22:09
Rust: asyncronous CBOR channels over raw TCP using tokio-serde and serde_cbor.
/**
* Asynchronous CBOR message traffic via tokio / serde. More at https://cbor.io
*
* Test via `cargo run` and, in a separate terminal test using these messages.
*
* $ echo '00000017A2616364526561646161826568656C6C6F65776F726C64' | xxd -r -p | nc 127.0.0.1 6142
* $ echo '0000000FA1616D6B68656C6C6F20776F726C64' | xxd -r -p | nc 127.0.0.1 6142
*
* First 8 bytes are the length of the data frame, rest is the CBOR message.
*/
@kalexmills
kalexmills / MultiSet.scala
Last active December 23, 2019 17:01
MultiSet datastructure in Scala w/ Cats (Foldable and Monad)
package com.niftysoft.gennit.util
import cats._
import cats.implicits._
import scala.annotation.tailrec
case class MultiSet[V] private (data: Map[V,Int]) {
def filter(f: V => Boolean): MultiSet[V] = MultiSet(data.filter{case(v, mul) => f(v)})
@kalexmills
kalexmills / README.md
Last active December 14, 2019 23:53
Gennit README

Gennit

Simple DSL for stochastic generative grammars, written in Scala.

Getting Started

Use one of the below two commands to start the REPL.

$ bloop run root
$ sbt run
@kalexmills
kalexmills / Distribution.scala
Last active November 9, 2019 16:54
Efficient draws from probability distributions in Scala -- using cats
import cats.data.Reader
import scala.reflect.ClassTag
/**
* Distribution takes a PFloat and returns an A.
*/
type Distribution[A] = Reader[PFloat, A]
/**
* PFloat represents a Float describing a probability. Its value is always between
@kalexmills
kalexmills / interfaces.md
Last active September 3, 2018 15:34
Replace contracts with built-in interfaces...(and you can name them like this).

Contracts are a creative solution to generics, but they are also unexpected, weird, and possibly unnecessary.

Emily Maier's suggestion that contracts are superfluous is a good one. Interfaces in Go already serve as a kind of contract.

She has observed that, under the current proposal, it would be valid to copy-and-paste the function body into the contract. While the code would compile and presumably run. Go has already made design choices which limit the realm of the possible to keep developers from shooting themselves in the foot.

Contracts in Go only seem to be needed since code needs to assert at compile time that generic types can be used in built-in operations (i.e. that they satisfy a certain operational interface). Rather than introducing a new language construct, it seems more coherent to make these operational interfaces available