Skip to content

Instantly share code, notes, and snippets.

@danslapman
danslapman / kek
Created March 7, 2019 18:53
homebrew setup
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
@danslapman
danslapman / coalesce.sc
Created December 17, 2018 16:22
coalesce for Quill
def coalesce[T] = quote { column: Option[T] => default: T =>
infix"coalesce($column, $default)".as[T]
}
@danslapman
danslapman / quill_dynamic_query.sc
Created December 17, 2018 12:35
Dynamic querying in Quill
import $ivy.`io.getquill::quill:2.6.0`
import io.getquill._
val ctx = new SqlMirrorContext(MirrorSqlDialect, Literal)
import ctx._
case class Entity(field1: String, field2: Int)
def getEntity(field1: Option[String], field2: Option[Int]) = {
@danslapman
danslapman / hsequence.sc
Last active October 6, 2018 21:17
Auto-generating patches for fields
import $ivy.`org.typelevel::cats-core:1.4.0`
import $ivy.`org.typelevel::kittens:1.1.1`
import cats._
import cats.data.{Validated, ValidatedNel}
//import cats.instances.list._
import cats.sequence._
import shapeless._
import shapeless.labelled._
import shapeless.record._
@danslapman
danslapman / fields.sc
Created July 19, 2018 10:37
Get field names of case class using shapeless
import $ivy.`com.chuusai::shapeless:2.3.3`
import shapeless._
trait Fields[T] {
def fields: List[String]
override def toString: String = fields.mkString(", ")
}
object Fields extends LabelledProductTypeClassCompanion[Fields] {
def apply[T](fs: List[String]): Fields[T] = new Fields[T] {
override def fields: List[String] = fs
@danslapman
danslapman / ApplyOne.sc
Created July 10, 2018 20:15
Combine partial functions of different types
import scala.reflect.runtime.universe._
type ¬[A] = A => Nothing
type ∨[T, U] = ¬[¬[T] with ¬[U]]
type ¬¬[A] = ¬[¬[A]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) }
val intpf: PartialFunction[Int, Int] = { case i: Int => i }
val strpf: PartialFunction[String, String] = { case str: String => str }
@danslapman
danslapman / conf.sc
Created July 3, 2018 17:16
Kleisli demonstration
interp.configureCompiler(_.settings.YpartialUnification.value = true)
@danslapman
danslapman / conf.sc
Created July 3, 2018 17:15
Function combination
interp.configureCompiler(_.settings.YpartialUnification.value = true)
@danslapman
danslapman / consul.py
Created June 27, 2018 18:32
Simple python consul client
import requests
class ConsulClient:
def __init__(self, consul_host, consul_port=8500):
self._service_url_template = "http://{host}:{port}/v1/catalog/service/{name}"
self._host = consul_host
self._port = consul_port
def get_service(self, service_name):
@danslapman
danslapman / cookbook.sc
Created June 26, 2018 14:51
Scala scripting cookbook
import java.nio.file.{Files, Paths, StandardOpenOption => SOO}
import scala.io.Source
import collection.JavaConverters._
val sep = System.lineSeparator
val file = Source.fromFile(..)
val data = file.getLines
...