Skip to content

Instantly share code, notes, and snippets.

@lazyvalue
lazyvalue / Tokens.scala
Last active February 20, 2023 14:14
Typeclasses in Scala3
// A quick tutorial on typeclasses in Scala 3.
// We declare a typeclass for universal IDs, called tokens, for domain objects
// in our system, like users, transaction records, shopping cart items,
// text messages, whatever.
// The typeclass gives us some type safety, some handy methods (well, one so far),
// and the set of tokens are open-ended (you can add more domain objects time).
// You know the drill ...
import java.util.UUID
@lazyvalue
lazyvalue / init.el
Created August 19, 2020 22:03
Scott's Emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'package)
(setq package-archives '(("org" . "http://orgmode.org/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")))
(package-initialize)
@lazyvalue
lazyvalue / keybase.md
Created November 5, 2018 19:45
keybase.md

Keybase proof

I hereby claim:

  • I am lazyvalue on github.
  • I am lazyvalue (https://keybase.io/lazyvalue) on keybase.
  • I have a public key whose fingerprint is 456B 8F8D E399 E4DA AD71 49D6 04AC EB53 DBD4 BBB3

To claim this, I am signing this object:

form for PortalCrane:
capabilities <- [
form for Capability:
type <- "OUTBOUND_MESSAGING"
remoteInterface <- form for RestRemoteInterface:
httpMethod <- "POST"
urlTemplate <- "https://graph.facebook.com/v2.6/me/messages?access_token={{credentials.pageAccessToken}}"
headers <- [ httpHeader "Content-Type" "application/json", httpHeader "X-Twilio" "true" ]
requestProductions <- [
@lazyvalue
lazyvalue / gist:906c981e0ac3df470981
Created July 10, 2015 01:12
argonaut json support for akka-http
import akka.http.scaladsl.marshalling.{ ToEntityMarshaller, Marshaller }
import akka.http.scaladsl.model.{ContentTypes, HttpCharsets}
import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshaller }
import akka.stream.FlowMaterializer
import akka.http.scaladsl.model.MediaTypes.`application/json`
import argonaut.{Parse, DecodeJson, EncodeJson, Json}
object ArgonautJsonSupport {
implicit def argonautJsonUnmarshallerConverter[T](decode: DecodeJson[T])(implicit mat: FlowMaterializer): FromEntityUnmarshaller[T] =
class CanBuild21[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21](m1: M[A1 ~ A2 ~ A3 ~ A4 ~ A5 ~ A6 ~ A7 ~ A8 ~ A9 ~ A10 ~ A11 ~ A12 ~ A13 ~ A14 ~ A15 ~ A16 ~ A17 ~ A18 ~ A19 ~ A20], m2: M[A21]) {
def ~[A22](m3: M[A22]) = new CanBuild22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22](canBuild(m1, m2), m3)
def and[A22](m3: M[A22]) = this.~(m3)
def apply[B](f: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21) => B)(implicit fu: Functor[M]): M[B] =
fu.fmap[A1 ~ A2 ~ A3 ~ A4 ~ A5 ~ A6 ~ A7 ~ A8 ~ A9 ~ A10 ~ A11 ~ A12 ~ A13 ~ A14 ~ A15 ~ A16 ~ A17 ~ A18 ~ A19 ~ A20 ~ A21, B](canBuild(m1, m2), { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 ~ a17 ~ a18 ~ a19 ~ a20 ~ a21 => f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21) })
def apply[B](f: B => (A1, A2,
package com.sport195.api.models
import play.api.libs.json._
import com.sport195.api.common._
trait Mapped[T,X] {
def render(target: T, renderMode: RenderMode): X
}
class JsonMapped {
" http://yannesposito.com/Scratch/en/blog/Vim-as-IDE/
call plug#begin('~/.vim/plugged')
Plug 'altercation/vim-colors-solarized'
Plug 'bronson/vim-trailing-whitespace'
Plug 'Shougo/vimproc.vim'
Plug 'Shougo/unite.vim'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
// COMPILES, generates invalid SQL
def fetchProfileInfo(userId: Int) =
(for {
(profile, hometown) <- MemberProfiles leftJoin Geographies on (_.hometown_id === _.id)
(_, highSchool) <- profiles leftJoin Schools on (_.highschool_id === _.id)
(_, college) <- profiles leftJoin Schools on (_.college_id === _.id)
} yield {
(profile, hometown.name.?, highSchool.name.?, college.name.?)
}).filter(_._1.user_id === userId)
case class OptionValidator[T](maybe: Option[T], innerF: T => Validator) {
val inner = maybe.map(v => innerF(v))
def isGood = inner.map(v => v.isGood).getOrElse(true)
def error: Option[String] = inner.flatMap(v => v.error)
val errorMsg = ""
}
// EXAMPLE
trait Athlete { self =>