Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
import com.fasterxml.jackson.core.Base64Variants
import com.google.protobuf.ByteString
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType
import com.google.protobuf.Descriptors.{ EnumDescriptor, EnumValueDescriptor, FieldDescriptor }
import com.trueaccord.scalapb.{ GeneratedMessage, GeneratedMessageCompanion, Message }
import play.api.data.validation.ValidationError
import play.api.libs.json._
import scala.util.{ Failure, Success, Try }
@Baccata
Baccata / vpnconnect.sh
Last active March 25, 2020 00:35
Script to query pwd from lastpass and feed it to the vpn
#!/usr/bin/env bash
HOST="???" # address of the vpn
LASTPASS_ENTRY="???" # entry under which the password is saved in last pass
USERNAME=$(lpass show --sync=auto --username $LASTPASS_ENTRY)
PASSWORD=$(lpass show --sync=auto --password $LASTPASS_ENTRY)
# escaping the special chars in the password to allow sed-ing it
ESC_PWD=$(echo $PASSWORD | sed -e 's/[]\/$*.^[]/\\&/g')
@Baccata
Baccata / JavaFuture.scala
Created July 5, 2018 15:24 — forked from Daenyth/JavaFuture.scala
Convert Java futures to cats-effect IO
package teikametrics
import cats.effect.{Sync, Timer}
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.blocking
import cats.syntax.all._
object JavaFuture {
// Alias for more friendly imports
@Baccata
Baccata / FoldableFromTraverse.scala
Last active September 11, 2018 12:56
Attempt at implementing foldLeft/foldRight from traverse
abstract class FoldableFromTraverse[F[_]] extends Traverse[F] {
override def foldMap[A, B: Monoid](fa: F[A])(f: A => B): B =
traverse[Const[B, ?], A, B](fa)(a => Const(f(a))).getConst
private def andThenMonoid[A]: Monoid[A => A] = new Monoid[A => A] {
def combine(f: A => A, g: A => A) = f andThen g
def empty: A => A = (a: A) => a
}
@Baccata
Baccata / ValueDiscard.scala
Created April 19, 2018 12:31
An option that forces the developer to ascribe the type to discard it
/**
* Function that allows values to be discarded in a visible way
*
* Thanks https://github.com/tabdulradi for the Trick
*/
object ValueDiscard {
/**
@Baccata
Baccata / after.scala
Last active March 18, 2018 15:01
ammonite wrapping code
package ammonite
package $file
import _root_.ammonite.interp.InterpBridge.{
value => interp
}
import _root_.ammonite.interp.InterpBridge.value.{
exit
}
import _root_.ammonite.main.Router.{
doc,
@Baccata
Baccata / pipo.sc
Last active March 15, 2018 13:11
ammonite | semanticdb experiments
import $ivy.`org.typelevel::cats-core:1.0.1`
import cats.data.NonEmptyList
case class ABC(a : Int, b : Long, c : String)
case class NelWrapper(nel: NonEmptyList[Int])
val w = NelWrapper(NonEmptyList.of(1,2,3,4))
@Baccata
Baccata / mill_completion.bash
Created March 2, 2018 08:07
Very basic bash autocompletion support for mill
# See https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2
__mill()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="$(echo $(mill resolve __ 2>/dev/null ) | sed 's/ / /g')"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
@Baccata
Baccata / Presentation.scala
Created November 20, 2017 10:03
Some toy examples of matryoshka use
package presentation
import matryoshka.data.Fix
import scalaz.Functor
object Presentation extends App {
// 1 : abstract recursion away
@Baccata
Baccata / hylo.sc
Last active October 14, 2017 22:12
Stack safe hylomorphism using cats' lazy eval
// Look up ammonite if you're wondering what this syntax is
import $ivy.`org.typelevel::cats-core:1.0.0-MF`
import cats._
import cats.syntax.functor._
import cats.syntax.traverse._
sealed trait Nat[+A]
case object Zero extends Nat[Nothing]
case class Succ[A](a : A) extends Nat[A]