Skip to content

Instantly share code, notes, and snippets.

@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 March 9, 2024 07:54
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
@NicolaeNMV
NicolaeNMV / akka-intellij-worksheet-work-arround.md
Last active February 17, 2021 15:35
How to run akka actors in Intelij Worksheet

Missing resource

Scala code run from Intellij Worksheet doesn't seem to be able to find the akka actor resources.

The error is:

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'

There is an opened ticket on Intellij bugtracker https://youtrack.jetbrains.com/issue/SCL-9229 with a work arround