Skip to content

Instantly share code, notes, and snippets.

View teigen's full-sized avatar

Jon-Anders Teigen teigen

  • Arktekk
  • Oslo, Norway
View GitHub Profile
@teigen
teigen / scala-cli.md
Created December 17, 2021 16:29
scala-cli resourceDir does not work with package

A little project demonstrating problems with resourceDir.

16:28 λ tree
.
├── Test.scala
└── resources
    └── data.txt

1 directory, 2 files

Keybase proof

I hereby claim:

  • I am teigen on github.
  • I am jteigen (https://keybase.io/jteigen) on keybase.
  • I have a public key ASA7_hpukhZRksaKXCE39RmhQ-BA6Jm-vpkOHyvw_kCHdQo

To claim this, I am signing this object:

@teigen
teigen / Foo.scala
Last active September 28, 2017 17:07
SAM returning value class crashes compiler
package sam
// scala 2.12.3
object SonOfSAM {
val long:SonOfSAM[Long] = i => new Foo(i)
}
trait SonOfSAM[A]{
def foo(a:A):Foo
}
@teigen
teigen / Main.scala
Created December 11, 2016 22:59
influx.db data types and decoders for json query results
package influxdb
import argonaut.Argonaut._
import shapeless._
object Main {
def main(args: Array[String]): Unit = {
val one =
"""
@teigen
teigen / Argonautype.scala
Created December 5, 2016 19:25
auto derive codecs for new types from underlying type codecs
import argonaut.{EncodeJson, DecodeJson}
import shapeless._
object Argonautype {
implicit def EncodeHList[A](implicit encode:EncodeJson[A]):EncodeJson[A :: HNil] =
encode.contramap(_.head)
implicit def DecodeHList[A](implicit decode:DecodeJson[A]):DecodeJson[A :: HNil] =
decode.map(a => a :: HNil)
@teigen
teigen / uri.scala
Last active December 19, 2015 00:00
uri string interpolator
scala> import UriString._
import UriString._
scala> val a = "world"
a: String = world
scala> uri"hello/$a"
res3: String = hello/world
scala> val b = "http://"
@teigen
teigen / auth.scala
Created July 19, 2012 14:33
Unfiltered authentication example
package auth
import unfiltered.Cycle
import unfiltered.request.{HttpRequest, BasicAuth, Path}
import unfiltered.response._
import unfiltered.jetty.Http
import unfiltered.filter.Plan
object Req {
def apply[Req, Res](f:PartialFunction[HttpRequest[Req], HttpRequest[Req] => ResponseFunction[Res]]):Cycle.Intent[Req, Res] = {
import validation._
object Demo extends App {
object validateMaps extends FormValidations[Map[String, String]](_.get)
import validateMaps._
def int(s:String) = try{ Right(s.toInt) } catch { case _ => Left("required.int") }
def positiveInt(i:Int) = if(i > 0) Right(i) else Left("required.positive")
case class Data(a:Int, b:Int)
package com.mongodb.casbah
package commons
object Syntax extends Syntax
trait Syntax {
implicit def name(name: String) = Name(name)
}
case class Name(name: String) {
@teigen
teigen / gist:1653535
Created January 21, 2012 18:37
Java Lens api I just made up
Lens<Person, Address> personAddressLens = new LensApiThatIJustMadeUp<Person, Address>(){
@Override
public Address get(@Nullable Person person) {
return person.getAddress();
}
@Override
public Person set(Person person, Address address) {
return new Person(person.getFirstName(), person.getLastName(), address);
}