Skip to content

Instantly share code, notes, and snippets.

View ivanopagano's full-sized avatar

Ivano Pagano ivanopagano

View GitHub Profile
@ivanopagano
ivanopagano / prompt.sbt
Last active May 15, 2020 08:04
Custom sbt prompt
//configure custom sbt prompt
ThisBuild / shellPrompt := { state =>
val extracted = Project.extract(state)
import extracted._
/* COLOR DEFS
* for ansi color codes refer to http://www.calmar.ws/vim/color-output.png
* and to https://misc.flogisoft.com/bash/tip_colors_and_formatting
*/
type Color = Byte
@ivanopagano
ivanopagano / README.md
Created March 10, 2020 17:25 — forked from anonymoussprocket/README.md
Tezos Token Tantrum
@ivanopagano
ivanopagano / README.md
Created March 10, 2020 17:25 — forked from anonymoussprocket/README.md
Tezos Token Tantrum
@ivanopagano
ivanopagano / tuple-flatten.scala
Created February 19, 2019 15:51 — forked from travisbrown/tuple-flatten.scala
Flattening deeply nested tuples with Shapeless
import shapeless._
trait Flatten[I, O <: HList] {
def apply(i: I): O
}
trait FlattenLow {
implicit def otherFlatten[I] = new Flatten[I, I :: HNil] {
def apply(i: I) = i :: HNil
}
@ivanopagano
ivanopagano / grep.hs
Created January 11, 2019 10:28
pseudo-grep with -A -B
window n ls = filter ((n == ) . length) $ transpose . take n . tails $ ls
match_on_element _ _ [] = false
match_on_element 0 p x :: xs = p x
match_on_element i p x :: xs = match_on_elmement (i-1) p xs
@ivanopagano
ivanopagano / metals-sublime.md
Last active February 8, 2019 09:17
Using Metals LSP with Sublime 3

Using with Sublime

I successfully enabled the metals lsp server to work with sublime text 3

I didn't actually need to write any lsp client, since I'm using the standard LSP Package

Setup

My working setup is specific:

  • macOS HIgh Sierra
  • Sublime 3 on Dev channel build 3160

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA

@ivanopagano
ivanopagano / nested-for.scala
Created December 4, 2017 09:44
desugaring of a for comprehension for the herding-cats either example
//refers to http://eed3si9n.com/herding-cats/stacking-future-and-either.html
def isFriends1(user1: Long, user2: Long)
(implicit ec: ExecutionContext): Future[Either[Error, Boolean]] =
for {
a <- followers(user1)
b <- followers(user2)
} yield for {
x <- a.right
y <- b.right
@ivanopagano
ivanopagano / majority-split-brain+redeploy.md
Last active March 29, 2017 09:14
redeploy scenario on 3-instance cluster and split-brain happens. keep-majority strategy

Base scenario

The policy is keep-majority, new instances are started one by one, on redeploy newest instances are downed first (YOUNGEST_FIRST)

  • 3 nodes up: N1, N2, N3

Redeploy

  1. a redeploy is started, so a new node is spun (N+)
  2. N+ is acked by all the nodes, so the Leader (L) is about to set the node to UP

Keybase proof

I hereby claim:

  • I am ivanopagano on github.
  • I am ivanopagano (https://keybase.io/ivanopagano) on keybase.
  • I have a public key whose fingerprint is B69F 549F 2B42 DB94 2BD3 4749 0754 4458 C605 E71A

To claim this, I am signing this object: