Skip to content

Instantly share code, notes, and snippets.

View peterstorm's full-sized avatar

Peter Storm peterstorm

View GitHub Profile
@ChristopherDavenport
ChristopherDavenport / Streaming.scala
Created July 9, 2020 17:23
Pure Pull/Creek Invariant Implementation
object Streaming {
sealed trait Pull[O, R]{ self =>
protected def step: Eval[Either[R, (O, Pull[O, R])]]
def map[R2](f: R => R2): Pull[O, R2] = flatMap(r => Pull.pure(f(r)))
def flatMap[R2](f: R => Pull[O, R2]): Pull[O, R2] = new Pull[O, R2]{
protected def step: Eval[Either[R2, (O, Pull[O, R2])]] = {
Eval.defer(self.step).flatMap{
@cyrenity
cyrenity / k8s-using-talos-in-vms.md
Last active October 24, 2025 08:56
Setup kubernetes cluster using Talos (Lab)

Setup Kubernetes cluster in minutes using Talos

1. Get talosctl

Download and install talosctl binary

wget https://github.com/talos-systems/talos/releases/download/v0.8.1/talosctl-linux-amd64
@inscapist
inscapist / flake-direnv.md
Last active August 9, 2024 17:24
Nix Flakes and Direnv on Mac OSX (Catalina)

Development environment with Nix Flakes and Direnv

This document is targeted at those who seek to build reproducible dev environment across machines, OS, and time.

It maybe easier for remote teams to work together and not spending hours each person setting up asdf/pyenv/rbenv, LSP servers, linters, runtime/libs. Nix is probably the closest thing to Docker in terms of development environment.

Flake is used here because it provides hermetic build, with absolutely no reliance on system environment (be it Arch/Catalina/Mojave). Also it freezes dependencies in flake.lock so builds are reproducible.

This gist provides the setup to develop Java/Clojure/Python applications on Nix. But it can be easily adapted to ruby, nodejs, haskell.

import com.sksamuel.avro4s.SchemaFor
import com.sksamuel.avro4s.refined._
import io.estatico.newtype.Coercible
import io.chrisdavenport.fuuid.FUUID
import java.util.UUID
import scala.concurrent.duration.FiniteDuration
import io.circe.{Json, JsonObject}
import com.comcast.ip4s.Ipv4Address
object avro extends SchemaForCoercible {
@ChristopherDavenport
ChristopherDavenport / SetOnceCache.scala
Last active October 11, 2021 13:06
Set Once Cache
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import scala.concurrent.duration._
import io.chrisdavenport.mapref._
trait SetOnceCache[F[_], K, V]{
def get(k: K): F[V]
@ChristopherDavenport
ChristopherDavenport / Lock.scala
Last active October 11, 2021 13:10
Reentrant Lock
import cats._
import cats.syntax.all._
import cats.data._
import cats.effect._
import cats.effect.syntax.all._
import cats.effect.std.Semaphore
trait Lock[F[_]]{ self =>
def lock: F[Unit]
def unlock: F[Unit]
@jmatsushita
jmatsushita / README
Last active October 29, 2025 09:57
Setup nix, nix-darwin and home-manager from scratch on an M1 Macbook Pro
###
### [2023-06-19] UPDATE: Just tried to use my instructions again on a fresh install and it failed in a number of places.
###. Not sure if I'll update this gist (though I realise it seems to still have some traffic), but here's a list of
###. things to watch out for:
### - Check out the `nix-darwin` instructions, as they have changed.
### - There's a home manager gotcha https://github.com/nix-community/home-manager/issues/4026
###
# I found some good resources but they seem to do a bit too much (maybe from a time when there were more bugs).
# So here's a minimal Gist which worked for me as an install on a new M1 Pro.
@quelgar
quelgar / typed_errors.md
Last active January 16, 2024 09:36
Every Argument for Static Typing Applies to Typed Errors

Every Argument for Static Typing Applies to Typed Errors

Think of all the arguments you've heard as to why static typing is desirable — every single one of those arguments applies equally well to using types to represent error conditions.

An odd thing I’ve observed about the Scala community is how many of its members believe that a) a language with a sophisticated static type system is very valuable; and b) that using types for error handling is basically a waste of time. If static types are useful—and if you like Scala, presumably you think they are—then using them to represent error conditions is also useful.

Here's a little secret of functional programming: errors aren't some special thing that operate under a different set of rules to everything else. Yes, there are a set of common patterns we group under the loose heading "error handling", but fundamentally we're just dealing with more values. Values that can have types associated with them. There's absolutely no reason why the benefits of static ty

@ftzm
ftzm / Test.hs
Last active May 31, 2022 12:38
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
module Test where
import Control.Monad.Reader
import Data.Generics.Product.Typed
@viercc
viercc / gadt-filter-with-typeable.hs
Created October 27, 2022 08:08
Generalising / DRYing functions which apply to GADTs
{-# LANGUAGE GADTs, DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Typeable (cast)
import Type.Reflection