Skip to content

Instantly share code, notes, and snippets.

View odenzo's full-sized avatar

odenzo odenzo

  • 01:57 (UTC -04:00)
View GitHub Profile
@odenzo
odenzo / Scala 3 Tuple: Case Class Params -> FnN
Last active May 28, 2022 12:29
Scala 3: Extrating case class params for use as Function Arguments Tuple.fromProductTyped
cass class MyCmd(a:Int, b:String, c:D)
def myFunction(a:Int, b:X, c:D)
val a = MyCmd(12, "Y", D.default)
val tupledCmd = Tuple.fromtProductTyped(a) // Will keep length and type data
myFunction.tupled(typledCmd)
To deal with mismatch of arge can add things to the tuple or partially apply the function before tupling
trait CirceUtils {
val unCaptialize: String => String = s =>
if s == null then null
else
s.headOption match {
case Some(v) if v.isUpper => s.drop(1).prepended(v.toLower)
case _ => s
}
val get = quote {
query[Region].filter(_.code == lift(region))
}
def insert(code: String) = quote {
query[Region].insert(lift(Region(code = code))).returning(_.id)
}
// HELP:: Better way?
val prog = for {
r <- run(get).map(_.head).recoverWith {
@odenzo
odenzo / Circe Nested Lists of wrapped objects.md
Last active September 9, 2019 02:08
When a list of items is encoded and decoded as a List of single value JsonObjects

Given a case class like:

case class SignerListNode(
    flags: Long,
    ownerNode: Option[String],
    previousTxnId: Option[TxnHash],
    previousTxnLgrSeq: Option[LedgerSequence],
    signerEntries: List[SignerEntry],
    signerListID: Long,
    signerQuorum: Long,
@odenzo
odenzo / CirceDecodorWithPrepare.scala
Last active April 4, 2019 03:42
Simple example of using Circe Decoder with prepare to preprocesses Json (JSonObjects in this case)
import io.circe._
// Generalized in real-life
def fieldNameChangeEx(in: JsonObject): JsonObject = {
val fieldName = "type"
val newName = "tipe"
// Not sure what happens on missing fieldName or fieldName = null
val updated: Option[JsonObject] = in(fieldName)
.map(oldVal ⇒ in.add(newName, oldVal))
Verifying that "odenzo.id" is my Blockstack ID. https://explorer.blockstack.org/name/odenzo.id
@odenzo
odenzo / PostgresDsl.scala
Created November 29, 2016 15:22
Quill 1.0.1-SNAPSHOT Postgres Operator adding
import io.getquill.context.sql.SqlContext
trait PostgresDsl { this: SqlContext[_, _] =>
/**
* @shortDescription A DSL extension to allow bitwise or operator on Int columns
* Tested with integer columns in postgres
*/
implicit class BitwiseOR(s1: Int) {
@odenzo
odenzo / RippleWebSocketFlow.scala
Created July 3, 2016 14:40
akka-http flow handling of non-strict and strict inbound websocket messages
trait InboundTransforms extends StrictLogging {
protected def message2text(msg: Message): Future[String] = {
msg match {
case message: TextMessage.Strict ⇒ Future.successful(message.text)
case message: TextMessage.Streamed ⇒ message.textStream.runFold("")(_ + _)
case default ⇒ Future.successful("Default: " + default)
}
}
@odenzo
odenzo / keybase.md
Created April 15, 2015 05:21
KeyBase Public Gist

Keybase proof

I hereby claim:

  • I am odenzo on github.
  • I am odenzo (https://keybase.io/odenzo) on keybase.
  • I have a public key whose fingerprint is 20E2 B77B A872 6A1A 4E70 2525 F42A C6A5 09F9 8CC0

To claim this, I am signing this object:

@odenzo
odenzo / README
Last active August 29, 2015 14:13 — forked from rwest/README
These two files should help you to import passwords from mac OS X keychains to 1password.
Assumptions:
1) You have some experience with scripting/are a power-user. These scripts worked for me
but they haven't been extensively tested and if they don't work, you're on your own!
Please read this whole document before starting this process. If any of it seems
incomprehensible/frightening/over your head please do not use these scripts. You will
probably do something Very Bad and I wouldn't want that.
2) You have ruby 1.9.2 installed on your machine. This comes as standard with Lion, previous
versions of OS X may have earlier versions of ruby, which *may* work, but then again, they