Skip to content

Instantly share code, notes, and snippets.

View sitepodmatt's full-sized avatar

Mãtt Freèman sitepodmatt

  • Everywhere
View GitHub Profile
@sitepodmatt
sitepodmatt / runtimetypes.ts
Created July 13, 2019 14:18
runtimetypes.ts
interface TypeRep<T> {
_UnderlyingType: T
}
class ValidatedType<T extends { [TKey in keyof T] : TypeRep<unknown> }> {
readonly _T!: { [TKey in keyof T] : T[TKey]['_UnderlyingType'] }
constructor(t : T) { }
}
async function sleepAsync(ms) {
return new Promise((r) => setTimeout(r, ms));
}
async function run() {
const numbers = [1,2,3,4,5]
// A - COMPLETE
@sitepodmatt
sitepodmatt / codec.cs
Last active July 25, 2019 15:09
fsharp union codec
public static class FSharpUnionCodecBuilder
{
public delegate T Decoder<T>(byte[] bytes, string subType);
public delegate byte[] Encoder<T>(T input);
public static Tuple<Decoder<T>,Encoder<T>> Build<T>(T unionType) where T : class
{
var unionCaseFields = FSharpType.GetUnionCases(typeof(T), BindingFlags.Public)
.ToDictionary(uc => $"{uc.DeclaringType.Name}:{uc.Name}",
uc => new Tuple<UnionCaseInfo, Type>(uc,
@sitepodmatt
sitepodmatt / babysteps.js
Last active July 13, 2019 13:56
babysteps.js
class DType<A> {
readonly _A!: { [P in keyof A] : A[P] }
constructor(t : A) {
}
}
const UserModel = new DType({ name: ""})
type Infer<C extends any> = C['_A']
@sitepodmatt
sitepodmatt / mapdiff.kt
Created February 28, 2019 08:42
Map diff util
sealed class MapDiffResult<T : Any,V : Any> {
data class Added<T : Any,V : Any>(val key : T, val v : V) : MapDiffResult<T, V>()
data class Removed<T : Any,V : Any>(val key : T, val oldValue : V) : MapDiffResult<T, V>()
data class Changed<T : Any,V : Any>(val key : T, val new : V, val old :V) : MapDiffResult<T, V>()
}
fun <K : Any,V : Any> Map<K,V>.diffMaps(to: Map<K,V>, isSame : (V, V?) -> Boolean = { v,v2 -> v == v2 }) : List<MapDiffResult<K, V>> {
val from = this
@sitepodmatt
sitepodmatt / example.kt
Created February 28, 2019 08:15
example.kt
import io.kotlintest.specs.StringSpec
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
class RequestContextTest : StringSpec({
"playing with human context" {
try {
runBlocking {
@sitepodmatt
sitepodmatt / example.kt
Created February 28, 2019 08:15
example.kt
import io.kotlintest.specs.StringSpec
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
class RequestContextTest : StringSpec({
"playing with human context" {
try {
runBlocking {
Hello,
In recent weeks, many of our customers have noticed instability, degraded performance, and increased rendering errors from imgix due to a series of ongoing issues. This by itself is unacceptable, and we have been working tirelessly to address it.
However, in the struggle to fix things, we have also failed in our duty to communicate with our customers. I have received complaints that imgix has not been transparent enough about the scope of the issues and when they will be resolved. As CEO, I take full responsibility for this. That is not the kind of company I want imgix to be. You deserve to know when there are issues that could negatively affect you. You deserve to know what we are doing to make it right.
In the spirit of transparency, I have published a blog post about the recent challenges. In this post, I document exactly what is happening, explain why it is happening, and lay out what we are doing to fix it so that it does not happen again. I invite you to read the post, and to contact me or you
@sitepodmatt
sitepodmatt / informer.js
Last active August 12, 2017 07:26
playing with async
class K8SInformer {
constructor() {
this.listeners = [];
this.queue = [];
}
addListener(listener) {
this.listeners.push(listener);
}
fun main(args: Array<String>) {
println("Foldwhile experiment")
val oneTo100 = 1 until 100
println(oneTo100.fold(0) { acc, v -> acc + v})
println("Stop folding when total is above 2000")
println(oneTo100.foldWhile(0, { acc, v -> acc + v }, { acc, _ -> acc < 2000 }))