Skip to content

Instantly share code, notes, and snippets.

View thinkharderdev's full-sized avatar

Dan Harris thinkharderdev

View GitHub Profile
@thinkharderdev
thinkharderdev / API.scala
Last active November 6, 2018 13:21
Write raw byte array to File #scala
val bytes = Base64.decodeBase64(dataString.getBytes("UTF-8"))
val tempFile = new File(UUID.randomUUID().toString)
FileUtils.copy(new ByteArrayInputStream(bytes),new FileOutputStream(tempFile))
TemporaryFile(tempFile)
@thinkharderdev
thinkharderdev / caseclasses.scala
Last active November 6, 2018 13:21
Sharpen The Saw #scala
sealed trait UserRole
case object BasicUser extends UserRole
case object Admin extends UserRole
// I can very easily define basic data types using case classes
case class User(id: String, name: String, email: String, role: UserRole)
//Defining User as a case class has a couple of implications
// You don't need to use the "new" key word when instantiating an instance
val user = User("id","Dan","foo@bar.com", Admin)

Keybase proof

I hereby claim:

  • I am thinkharderdev on github.
  • I am thinkharder (https://keybase.io/thinkharder) on keybase.
  • I have a public key whose fingerprint is 575D 2A4A DC1D 72AB 1347 3260 904E 8177 8153 F43D

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am dshva on github.
  • I am thinkharder (https://keybase.io/thinkharder) on keybase.
  • I have a public key ASCcEX2YnRsUb_swODeGs_DPR4gH3gVjJw7Xl_bACt_VXgo

To claim this, I am signing this object:

import java.sql.Types
import io.circe._
import io.getquill.context.jdbc.JdbcContextBase
import org.postgresql.util.PGobject
import doobie._
import doobie.implicits._
import doobie.postgres.implicits._
sealed trait IdentifierType
def encode[A](schema: Schema[A], value: A): Chunk[Byte] = schema match {
case Schema.Sequence(element, _, g) => encodeSequence(element, g(value))
case Schema.Transform(codec, _, g) => g(value).map(encode(codec, _)).getOrElse(Chunk.empty)
case Schema.Primitive(standardType) => encodePrimitive(standardType, value)
case Schema.Optional(codec) =>
value match {
case v: Option[_] => encodeOptional(codec, v)
case _ => Chunk.empty
}
case Schema.Tuple(left, right) =>