Skip to content

Instantly share code, notes, and snippets.

View ahjohannessen's full-sized avatar

Alex Henning Johannessen ahjohannessen

View GitHub Profile
@ahjohannessen
ahjohannessen / update-oem-vmware.sh
Last active July 15, 2021 15:46 — forked from neilmayhew/update-oem-vmware.sh
Update a Flatcar installation on VMWare to use the latest OEM content
#!/usr/bin/env bash
# Update a Flatcar installation on VMWare to use the latest OEM content
#
# Copyright 2020, Neil Mayhew <neil@kerith.ca>
# LICENSE: MIT
set -ex
shopt -s extglob nullglob
{"ignition":{"config":{},"security":{"tls":{}},"timeouts":{},"version":"2.2.0"},"networkd":{"units":[{"contents":"[Match]\nName=en[s,o]*\n\n[Network]\nAddress=192.168.103.201/24\nGateway=192.168.103.102\nDNS=8.8.8.8\n","name":"00-static.network"}]},"passwd":{"users":[{"name":"core","sshAuthorizedKeys":["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArKvwajIJWpB4UPpQLqOCn/Y/g+xsmQa5Z8UFX/QZUpI/xeHgn64Zv+z3UJGKBpMXY33cwIi+1R/Vv1+CrEdZitqWlaBIlDfw+fClBgzqe/0QxaEEwQqX3bfxHZnNryy3YR7aOKiRNv1BnmuYiSyb87GHq+5x5mqw0pvyTqVANjEGJpbivHxTjiE7vJKG83IyzjE+c5ja8wE7HdfwiZ1YzLlD/t1uKz96IV3x1wC+Ku/xijkRHMmI8lCjFXgxCXdsm9hueFBxeH3hFaaFjU3shYzcBcZFRYVOCqbFRsYYtThoENg46j5pziYgPzALE0SSUOdK+nG8dTHk+qirkXgEyw== ahjohannessen@gmail.com","ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAliYIxuFOUwffcRBjk4reYkMyv0247f6GhnmnQMePrG9I8xr3l5bCIEeMLuiJJSKZXGwPx/HXFnaex9OMLREu235+6EcaybgjhYJlBx65BsTYoDm/RF8lXzwmHQer/ABzM2o+2i2pAbPK/LsLxmxUnQzfWBG7HZABJnNoMvUfrsqBOIjI/SA6+sIMsv2AQ9rIUzt4gmFTFfIGdNZsZ0LppEbaUTsB6sp4+UqxWomrgA4dpRw4ZGsiTjmbBe1maIsJrRI1ZWPuRSUKhAxQKBqz
pull_request_rules:
- name: Assign and label scala-steward's PRs
conditions:
- author=scala-steward
actions:
assign:
users: [ahjohannessen]
label:
add: [dependency-update]
- name: Approve scala-steward patches
@ahjohannessen
ahjohannessen / Ex.scala
Created October 29, 2018 16:23 — forked from SystemFw/Ex.scala
Get instances of a typeclass `TC[_]` for all cases of a Coproduct [shapeless]
import shapeless._
@annotation.implicitNotFound("Make sure all cases of ${C} have an instance of ${TC}")
trait CopTCs[C <: Coproduct, TC[_]] {
type Out <: HList
def result: Out
}
object CopTCs {
type Aux[C <: Coproduct, TC[_], O <: HList] = CopTCs[C, TC] { type Out = O }
def apply[C <: Coproduct, TC[_]](implicit ev: CopTCs[C, TC]) = ev
import cats.{ ApplicativeError, MonadError }
import cats.data.{ Kleisli, OptionT }
import cats.effect.Sync
import cats.effect.concurrent.Ref
import cats.syntax.all._
import io.circe.generic.auto._
import io.circe.syntax._
import org.http4s._
import org.http4s.circe.CirceEntityDecoder._
import org.http4s.circe._
@ahjohannessen
ahjohannessen / amm.sc
Created September 21, 2018 15:33 — forked from MarkRBM/amm.sc
Dynamic Transactors
interp.configureCompiler(_.settings.YpartialUnification.value = true)
import $ivy.`org.tpolecat::doobie-core:0.5.3`
import cats._
import cats.effect._
import cats.implicits._
import doobie._
import doobie.implicits._
@ahjohannessen
ahjohannessen / Foo.scala
Created September 21, 2018 15:30 — forked from ChristopherDavenport/Foo.scala
ConnectionIO Final Tagless Example
import doobie._
import doobie.implicits._
// Something for FunctionK ~>
trait Foo[F[_]]{
def getFoo: F[Bar]
}
@ahjohannessen
ahjohannessen / RequiredFields.scala
Created August 22, 2018 19:21 — forked from afiore/RequiredFields.scala
Filtering non-optional fields using shapeless
import shapeless._
import shapeless.labelled._
trait Required[A] {
def isRequired: Boolean
}
object Required {
implicit def optIsRequired[A]: Required[Option[A]] = new Required[Option[A]] {
override def isRequired = false
}
@ahjohannessen
ahjohannessen / Example.scala
Created February 23, 2018 17:55
Semigroup sum of disjunction
/**
* Sums up values inside disjunction, if both are left or right. Returns first left otherwise.
* {{{
* \/-(v1) +++ \/-(v2) → \/-(v1 + v2)
* \/-(v1) +++ -\/(v2) → -\/(v2)
* -\/(v1) +++ \/-(v2) → -\/(v1)
* -\/(v1) +++ -\/(v2) → -\/(v1 + v2)
* }}}
*/
def +++(x: => A \/ B)(implicit M1: Semigroup[B], M2: Semigroup[A]): A \/ B =

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x