Skip to content

Instantly share code, notes, and snippets.

View lachezar's full-sized avatar
🏗️
Maker of unrepresentable illegal states

Lachezar Yankov lachezar

🏗️
Maker of unrepresentable illegal states
View GitHub Profile
@ghostdogpr
ghostdogpr / rbac.sc
Last active June 7, 2024 06:47
Role-based access control with Caliban
//> using dep com.github.ghostdogpr::caliban-quick:2.7.1
import caliban.*
import caliban.CalibanError.*
import caliban.Value.StringValue
import caliban.execution.FieldInfo
import caliban.parsing.adt.Directive
import caliban.quick.*
import caliban.schema.Annotations.*
import caliban.schema.Schema
@tjarvstrand
tjarvstrand / Middleware.scala
Created July 25, 2023 12:39
zio-telemetry middleware
import io.opentelemetry.api.baggage.Baggage
import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator
import io.opentelemetry.context.propagation.TextMapGetter
import io.wolverinebeach.zio.telemetry.Tracing
import zio.Trace
import zio.ZIO
import zio.ZIOAspect
import zio.http.*
import java.lang
@btlines
btlines / F.scala
Created September 6, 2020 13:34
A better Future
package effects
import cats.{MonadError, StackSafeMonad}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}
final case class F[+E, +A](value: Future[Either[E, A]]) extends AnyVal {
def fold[B](fe: E => B, fa: A => B)(implicit ec: ExecutionContext): Future[B] = value.map {
@vijayanant
vijayanant / HigherRankedTypes.hs
Last active June 28, 2024 19:29
Rank N Types in Haskell
{-# LANGUAGE RankNTypes #-}
module RankN where
-- Rank 0:
-- add1 is momomorphic
add1 :: Int -> Int
add1 x = x + 1
-- Rank 1
@domnikl
domnikl / build.gradle.kts
Last active April 12, 2024 22:34
Gradle Kotlin DSL: set main class attribute for jar
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.example.MainKt"
}
}

Building pgModeler in MacOS with Homebrew

The official installation instructions for pgModeler recommends installing Xcode and the Enterprise DB distribution of Postgres to fulfill its build requirements. Luckily, Homebrew's got us covered!

  1. Checkout the source

    git clone https://github.com/pgmodeler/pgmodeler.git
    
@linasm
linasm / unapply.scala
Last active March 15, 2021 06:17
Output of live coding session "Scala pattern matching: apply the unapply"
import java.time.{LocalDate, LocalDateTime, LocalTime}
/*case */class FullName(val first: String, val last: String)
object FullName {
def apply(first: String, last: String): FullName =
new FullName(first, last)
def unapply(full: FullName): Some[(String, String)] =
Some((full.first, full.last))
@smarter
smarter / gadt.md
Last active March 6, 2024 23:33
GADTs in Scala

Generalized Algebraic Data Types in Scala

Basic GADTs

Here's an ADT which is not a GADT, in Haskell:

data Expr = IntExpr Int | BoolExpr Bool
@ursuad
ursuad / kafka-cheat-sheet.md
Last active June 25, 2024 13:23
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...