Skip to content

Instantly share code, notes, and snippets.

@johnhungerford
johnhungerford / getEither.scala
Last active October 15, 2024 07:21
Kotlin/TypeScript -like syntax for accessing nested optional types
//> using scala 3.3
import scala.util.{Failure, NotGiven, Success, Try, boundary}
import boundary.{Label, break}
import scala.annotation.targetName
/**
* Proof of concept implementation of a syntax similar to Kotlin and
* typescript. Within the context provided by [[getEither]], you can call
* `?` on any optional/failable type (currently supports [[Option]],
@erdeszt
erdeszt / RichNewtypeScala3.scala
Last active November 14, 2022 21:31
Scala 3 zio rich newtype improvements
import zio.prelude.Newtype
import cats.Contravariant
import cats.Functor
import cats.syntax.contravariant.*
import cats.syntax.functor.*
import io.circe.*
import io.circe.syntax.*
import io.circe.parser.decode
@littlenag
littlenag / expressive_metaprogramming.md
Last active April 23, 2023 04:37
Expressive Metaprogramming for Scala 3

Expressive Metaprogramming for Scala 3

Overview

Scala 3 introduces a new macro system that replaces the experimental Scala 2 system with one that should avoid unsoundness, be simpler to use, and simpler for the compiler team to evolve and maintain.

Perhaps the most significant feature missing from Scala 3 today is the lack of support

@calvinlfer
calvinlfer / CustomDiff.scala
Last active March 13, 2022 15:42
This shows how to do a Diff + Merge for any datatype provided you have the appropriate Diff and Merge all the primitive instances used by the datatype. This is done using Shapeless 2.3.3. Diff and Merge go hand-in-hand
// Unhappy with the default behavior of a particular datatype?
// You can override it as you wish, you must write a Diff and merge for the datatype you wish to override
final case class Address(
streetNumber: Int,
streetName: String,
city: String,
country: String
)
@chiller
chiller / README.md
Last active October 1, 2018 13:17
Typeclass Scala

Ad-hoc polymorphism with the typeclass pattern

from Wikipedia: "Ad hoc polymorphism is a dispatch mechanism: control moving through one named function is dispatched to various other functions without having to specify the exact function being called. Overloading allows multiple functions taking different types to be defined with the same name; the compiler or interpreter automatically ensures that the right function is called. This way, functions appending lists of integers, lists of strings, lists of real numbers, and so on could be written, and all be called append—and the right append function would be called based on the type of lists being appended. This differs from parametric polymorphism, in which the function would need to be written

@yingy4
yingy4 / Scala Case class, Companion object, Apply method and more.md
Last active February 10, 2020 08:29
Scala: Case class, Companion object, Apply method and more

Scala Case class, Companion object, Apply method and more

Let’s take a look at some examples:

Example1:

object Tests extends App {
  println(Rating("PG",13))
  println(Rating.apply("PG",13)) //This is equivalent, so you don't need to explicitly call apply
}
@iamtmrobinson
iamtmrobinson / custom-props.tsx
Created January 8, 2018 14:49
Using custom props with a Redux form in Typescript
import * as React from 'react';
import {
Field as FormField,
InjectedFormProps,
reduxForm,
} from 'redux-form';
interface CustomProps {
customText: string;
}
@umidjons
umidjons / youtube-dl-download-audio-only-on-best-quality.md
Last active November 14, 2024 21:20
Download Audio from YouTube with youtube-dl

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@mariotacke
mariotacke / README.md
Created March 7, 2017 04:36
Default nginx log format (combined) and grok pattern