Skip to content

Instantly share code, notes, and snippets.

View SegFaultAX's full-sized avatar

Michael-Keith Bernard SegFaultAX

View GitHub Profile
@SegFaultAX
SegFaultAX / gen.go
Created May 14, 2022 03:48
Property-based testing, in Go! [go] [golang]
package main
import (
"fmt"
)
type RNG interface {
Next() (uint64, RNG)
}
@SegFaultAX
SegFaultAX / jltocsv.py
Last active September 25, 2023 04:00
JSON Lines (.jsonl) to CSV (.csv) [Python]
#!/usr/bin/env python
import csv
import json
import sys
import argparse
import dataclasses as dc
@dc.dataclass(frozen=True)
@SegFaultAX
SegFaultAX / redis.go
Created July 23, 2020 19:06
Handling SliceCmd in go-redis [Go]
package main
import (
"context"
"fmt"
"log"
"github.com/go-redis/redis/v8"
)
@SegFaultAX
SegFaultAX / restart_count.py
Created February 3, 2020 22:56
Singularity Restart Count [Python]
#!/usr/bin/env python
import re
import arrow
import argparse
import urllib.parse
import requests
CLUSTERS = {
@SegFaultAX
SegFaultAX / sql.py
Created November 14, 2019 01:03
Simple bulk inserts with lookups [sqlite] [sql] [python]
import sqlite3
class Column:
def __init__(self, key, column=None):
self.key = key
self.column = column or self.key
@property
def value(self):
return ":" + self.key
@SegFaultAX
SegFaultAX / optics.kt
Created July 30, 2019 18:20
Some basic optics [Kotlin]
package com.mkbernard.craps
interface PIso<S, T, A, B> {
fun get(s: S): A
fun reverseGet(b: B): T
fun set(b: B): (S) -> T = { reverseGet(b) }
fun set(s: S, b: B): T = set(b)(s)
fun modify(f: (A) -> B): (S) -> T = { reverseGet(f(get(it))) }
fun modify(s: S, f: (A) -> B): T = modify(f)(s)
@SegFaultAX
SegFaultAX / either.kt
Last active July 30, 2019 18:53
Either [Kotlin]
sealed class Either<out E, out A> {
data class Left<E>(val left: E) : Either<E, Nothing>()
data class Right<A>(val right: A) : Either<Nothing, A>()
fun <R> fold(ifLeft: (E) -> R, ifRight: (A) -> R): R =
when (this) {
is Left -> ifLeft(left)
is Right -> ifRight(right)
}
@SegFaultAX
SegFaultAX / typeclasses.scala
Last active July 20, 2019 00:01
Basic typeclasses [Scala]
object typeclasses {
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Apply[F[_]] extends Functor[F] {
def map2[A, B, C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C]
def ap[A, B](ff: F[A => B])(fa: F[A]): F[B] =
map2(ff, fa)(_(_))
@SegFaultAX
SegFaultAX / depaginate.scala
Created July 15, 2019 22:04
Depagination with loopM exploration [Scala]
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object Depaginate extends App {
trait Monad[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
def pure[A](a: A): F[A]
def flatMap[A, B](fa: F[A])(k: A => F[B]): F[B]
}
@SegFaultAX
SegFaultAX / logic.rb
Last active May 7, 2019 21:40
Basic algorithm for normalizing a first order logic formula into conjunctive normal form [Ruby]
module Formula
class Expr
end
class Lit < Expr
attr_reader :name
def initialize(name)
@name = name
end