Skip to content

Instantly share code, notes, and snippets.

View jelinski's full-sized avatar

Krzysztof Jeliński jelinski

View GitHub Profile
@johnhungerford
johnhungerford / dependency-injection.md
Last active September 8, 2024 00:46
ZIO-like dependency injection using implicit resolution

ZIO-like dependency injection using implicit resolution

Daniel Ciocîrlan recently published a video showcasing a dependency-injection (DI) approach developed by Martin Odersky that uses Scala's implicit resolution to wire dependencies automatically. (See also his reddit post.)

The basic pattern for defining services in Odersky's approach is as follows:

class Service(using Provider[(Dep1, Dep2, Dep3)])
@joewalnes
joewalnes / jar-launcher.md
Last active December 10, 2023 11:58
Make a single file Java jar launcher

This is a little trick to turn an executable Java jar.

It works on all unixy like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.

Step 1 Start with an all-in-one jar (with entry point and all deps within)

$ ls 
hello.jar
@milessabin
milessabin / gist:6451859
Created September 5, 2013 15:37
Using pattern matching to destructure shapeless records.
scala> import shapeless._, syntax.singleton._, record._
import shapeless._
import syntax.singleton._
import record._
scala> object ->> {
| def unapply[K, V](f: FieldType[K, V])(implicit k: Witness.Aux[K]) = Option((k.value, f: V))
| }
defined module $minus$greater$greater