Skip to content

Instantly share code, notes, and snippets.

View phdoerfler's full-sized avatar

Philipp Dörfler phdoerfler

View GitHub Profile
{
"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 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}))",
" )",
@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 / 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 / python.md
Last active April 23, 2021 09:36
Python Cheat Sheet

#!/usr/bin/env python

3 please

import sys
if sys.version_info < (3, 0):
    sys.stdout.write("Sorry, written for Python 3\n")
    sys.exit(1)
#!/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
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
}
"""
@phdoerfler
phdoerfler / PomDependenciesToSbt.scala
Last active June 24, 2020 21:37 — forked from dportabella/PomDependenciesToSbt
Script to convert Maven dependencies (and exclusions) from a pom.xml to sbt dependencies. Or run it online on http://goo.gl/wnHCjE
#!/usr/bin/env amm
// This script converts Maven dependencies from a pom.xml to sbt dependencies.
// It is based on the answers of George Pligor and Mike Slinn on http://stackoverflow.com/questions/15430346/
// - install https://github.com/lihaoyi/Ammonite
// - make this script executable: chmod +x PomDependenciesToSbt
// - run it with from your shell (e.g bash):
// $ ./PomDependenciesToSbt /path/to/pom.xml
import scala.xml._
@phdoerfler
phdoerfler / main.rs
Created July 30, 2019 13:48
update-all
use std::io::{self, Write};
use std::process::{exit, Command, Stdio};
fn main() {
main_guarded().unwrap_or_else(|e| {
eprintln!("{}", e);
exit(1);
})
}
@phdoerfler
phdoerfler / thermonitor.nix
Created June 24, 2019 11:06
NixOS systemd service with python
{ config, pkgs, lib, ... }:
let
python = pkgs.python3Packages.python;
in
{
systemd.services.thermonitor = {
description = "Thermonitor Daemon";
serviceConfig = {
ExecStart = "/home/phi/thermonitor.py";