Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp Dörfler phdoerfler

View GitHub Profile
View IteratorThatKeepsOnGiving.scala
package io.doerfler
/**
* As an alternative consider flatMapConcat and mapConcat of Akka Streams.
*/
abstract class IteratorThatKeepsOnGiving[T] extends Iterator[T] {
private var currentIter: Iterator[T] = Iterator.empty[T]
private var currentElement: Option[T] = None
def nextIterator(lastElement: Option[T]): Iterator[T]
View tmux.md
View hg.md

Reorder commits

hg convert --datesort

Try this first. However, in my case I saw no difference and moved on.

Lots of small pulls

That said, if you want to try you just need to use a series of hg pull -r REV commands into a new clone. Something like this:

View nixos.md

NixOS

Path to $binary/$derivation

$derivation/bin gets linked into PATH only when explicitely installing it. If, e.g., sieve-filter is only in /nix/store because something else dependet on dovecot_pigeonhole, it won't be in PATH.

Path to $derivation Part 2

$ nix repl
View javatime.md

2021-04-06T10:03:57.249000072Z too precise?

instant.truncatedTo(ChronoUnit.SECONDS)

Custom formatter?

.withZone!

@phdoerfler
phdoerfler / README.md
Last active Apr 13, 2021
VS Code Snippet to promote tuples to case classes in Circe
View README.md

What does it look like

import io.circe._
case class Fnord(thing: Int, otherThing: Double)
object Fnord {
  implicit val codec: Codec[Fnord] = Codec.from(
    implicitly[Decoder[(Int, Double)]].map((Fnord.apply _).tupled),
    implicitly[Encoder[(Int, Double)]].contramap(r => Fnord.unapply(r).get)
  )
View scala.json
{
"Case class tuple codec": {
"prefix": "scircetuple",
"body": [
"import io.circe._",
"case class ${1:MyCaseClass}(${2:_1}: ${3:Double}, ${4:_2}: ${5:String})",
"object ${1} {",
" implicit val codec: Codec[${1}] = Codec.from(",
" implicitly[Decoder[(${3}, ${5})]].map((${1}.apply _).tupled),",
" implicitly[Encoder[(${3}, ${5})]].contramap(r => (r.${2}, r.${4}))",
@phdoerfler
phdoerfler / scala.json
Created Apr 13, 2021
VS Code snippet for dealing with tuples in Circe
View scala.json
"Case class tuple codec": {
"prefix": "scircetuple",
"body": [
"import io.circe._",
"case class ${1:MyCaseClass}(${2:_1}: ${3:Double}, ${4:_2}: ${5:String})",
"object ${1} {",
" implicit val codec: Codec[${1}] = Codec.from(",
" implicitly[Decoder[(${3}, ${5})]].map((${1}.apply _).tupled),",
" implicitly[Encoder[(${3}, ${5})]].contramap(r => (r.${2}, r.${4}))",
" )",
View scala.md

PartialFunction

import scala.{PartialFunction => =/>}
val mapper: String =/> String = {
  case Header(s) => s
}
val totalMapper = mapper orElse (identity[String] _): String =/> String
val totalMapper2 = mapper orElse PartialFunction.fromFunction(identity[String] _)
@phdoerfler
phdoerfler / httpjson.md
Last active Apr 3, 2021
Scala HTTP & JSON
View httpjson.md
import io.circe.generic.extras.JsonKey
import sttp.client3._

import sttp.client3.circe._
import shapeless._
import io.circe._
import io.circe.generic.semiauto._
import io.circe.generic.auto._
import io.circe.generic.extras._, io.circe.syntax._