Skip to content

Instantly share code, notes, and snippets.

View phdoerfler's full-sized avatar

Philipp Dörfler phdoerfler

View GitHub Profile
val allSvgElements: SortedSet[String] = svg11Elements ++ svg12TinyElementsWithAttributes.keySet
val svgFactories = for {
elementName <- allSvgElements.toSeq.sorted // <-
} yield q"""
object ${Term.Name(elementName)} extends ElementFactory[${Type.Name("SVGElement")}] {
@inline protected def tagName = $elementName
}
"""
#!/usr/bin/env ruby
# encoding: utf-8
$stdout.sync = true
print "Scanning for FIXMEs. Generating diff…"
diff_bad = `HGRCPATH="" hg diff -r "default:$HG_NODE" --exclude 'glob:**.xml' --ignore-space-change --nodates --noprefix`
print "\rParsing and preparing output… "
diff = diff_bad.encode('utf-8', 'binary', :invalid => :replace, :undef => :replace) # because .properties files
@phdoerfler
phdoerfler / httpjson.md
Last active April 3, 2021 18:29
Scala HTTP & JSON
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._
@phdoerfler
phdoerfler / scala.json
Created April 13, 2021 06:55
VS Code snippet for dealing with tuples in Circe
"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}))",
" )",
{
"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 / README.md
Last active April 13, 2021 07:08
VS Code Snippet to promote tuples to case classes in Circe

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)
  )
@phdoerfler
phdoerfler / javatime.md
Last active April 13, 2021 10:42
Java Time

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

instant.truncatedTo(ChronoUnit.SECONDS)

Custom formatter?

.withZone!

@phdoerfler
phdoerfler / nixos.md
Last active April 20, 2021 07:15
nixos

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
@phdoerfler
phdoerfler / scala.md
Last active April 20, 2021 20:29
Scala

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 / hg.md
Last active April 22, 2021 16:19
HG

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: