Skip to content

Instantly share code, notes, and snippets.

View lenguyenthanh's full-sized avatar
👻

Thanh Le lenguyenthanh

👻
View GitHub Profile

Understanding Comparative Benchmarks

I'm going to do something that I don't normally do, which is to say I'm going to talk about comparative benchmarks. In general, I try to confine performance discussion to absolute metrics as much as possible, or comparisons to other well-defined neutral reference points. This is precisely why Cats Effect's readme mentions a comparison to a fixed thread pool, rather doing comparisons with other asynchronous runtimes like Akka or ZIO. Comparisons in general devolve very quickly into emotional marketing.

But, just once, today we're going to talk about the emotional marketing. In particular, we're going to look at Cats Effect 3 and ZIO 2. Now, for context, as of this writing ZIO 2 has released their first milestone; they have not released a final 2.0 version. This implies straight off the bat that we're comparing apples to oranges a bit, since Cats Effect 3 has been out and in production for months. However, there has been a post going around which cites various compar

@nomisRev
nomisRev / transactionEither.kt
Last active August 10, 2022 08:41
Either-Syntax for SqlDelight transactions
import arrow.continuations.Effect
import arrow.continuations.generic.DelimitedScope
import arrow.core.Either
import arrow.core.right
import com.squareup.sqldelight.TransactionWithReturn
import kotlin.coroutines.RestrictsSuspension
/**
* Either-Syntax for SqlDelight transactions.
*

A Study in Multi-Point Deadlocks

Deadlocks are extremely difficult to reason about sometimes. We are used to thinking about them in terms of contention over shared resources, with the pair of exclusive locks being a good and relatively canonical example of this phenomenon. However, sometimes you can find yourself in deadlock scenarios which are caused not so much by an improper sequencing of exclusivity, but rather by insufficient buffer capacity!

These kinds of scenarios are a lot rarer and much more difficult to diagnose and describe, which is why I found this particular puzzle so incredibly fascinating. The following is a screenshot from Cities Skylines (I added textual markers and arrows to make things easier to follow). All vehicles pictured are stationary and unable to move, indefinitely:

Do you see the deadlock? It took me a bit to understand it, but this situation can and does arise in software resource contention where it is dramatically harder to conc

@nomisRev
nomisRev / Example.kt
Last active September 13, 2021 22:48
Kotlin DI with receivers & interface delegation
import arrow.core.*
import memeid.UUID
data class User(val email: String, val name: String) {
companion object
}
data class ProcessedUser(val id: UUID, val email: String, val name: String) {
companion object
}

Greasing the Skids: Building Remote Teams

In the wake of the virus that-must-not-be-named (which most people misname anyway), it seems like everyone and their cat has posted some sort of opinion or how-to on making remote work, work. This is a good thing! Working remotely, particularly full-time, is hard! I've done it for my entire career (aside from an odd 14 month office period in the middle that we shall not speak of), but more relevantly, for the past two years I've been responsible for building, managing, and enabling an entirely remote team, distributed across nine timezones. Remote teams don't just happen by installing Slack and telling everyone to work on their couch: they require a lot of effort to do correctly and efficiently. But, done right, it can be a massive multiplier on your team efficiency and flexibility.

Here's how we do it. I'm going to attempt to structure this post more towards management than engineering, and so I apologize in advance if I assume terminology or knowledge which

@i-am-tom
i-am-tom / Read.hs
Created December 23, 2019 13:39
Replacing function arguments with `MonadReader` calls.
-----------------------------------------------------------
-- HOW TO ASK FOR HELP AND AVOID ARGUMENTS.
--
-- When we want to use an externally-provided package (such as logging,
-- database connections, etc) in our work code, it might require some initial
-- config that we traditionally store in our environment.
--
-- We might even require something like a database connection or file handler
-- /throughout/ the lifetime of the code, in order to make queries or similar.
--
@pedrovgs
pedrovgs / ScreenshotTest.kt
Last active November 22, 2019 12:50
Interface you can import from your tests to be able to use screenshot testing for Android with different resolutions easily
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
final case class ZIO[-R, +E, +A](run: R => Either[E, A]) {
final def map[B](f: A => B): ZIO[R, E, B] =
ZIO(r => run(r).map(f))
final def flatMap[R1 <: R, E1 >: E, B](f: A => ZIO[R1, E1, B]): ZIO[R1, E1, B] =
ZIO(r => run(r).flatMap(a => f(a).run(r)))
final def provide(r: R): ZIO[Any, E, A] =
ZIO(_ => run(r))
@MattPD
MattPD / analysis.draft.md
Last active April 12, 2025 10:15
Program Analysis Resources (WIP draft)

Haskell in Production: Adventures in Blockchain Building