Skip to content

Instantly share code, notes, and snippets.

View kalexmills's full-sized avatar

Alex Mills kalexmills

View GitHub Profile
@kalexmills
kalexmills / Go2Go Snippets
Created April 16, 2025 23:34
Go2Go snippets from back when the Go generics proposal was still being considered
# Go2Go Snippets
To better understand the impact of the Go generics proposal, this repository collects a list of solutions to problems that could benefit from generics and links to implementations that run on [The go2go Playground](https://go2goplay.golang.org). Multiple implementations for the same problem are highly encouraged. Having a variety of solutions to look at and compare will help the community learn about approaches to generics that may and may not be useful.
Pull requests are welcome, both for solutions to the problems below and solutions of new problems! Just modify this file to a link to a go2go example that includes a `main` method demonstrating correct usage. Maintainers may run format on your submission and modify the link before merging, but we *will* preserve your original commit in the history.
If you are copying from an online source, please make sure 1) you are able to do so and 2) include a link back to the original material.
If you see an implementation in this list that you have
@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