Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
@Baccata
Baccata / Apple.scala
Last active April 16, 2021 08:57
Generic macros to get async/await UX for anything that has a cats' Apply associated to it
package baccata
import cats.Apply
import scala.annotation.compileTimeOnly
import scala.language.higherKinds
import scala.reflect.macros.blackbox
// format: off
// mostly stolen from mill's applicative macro
@Baccata
Baccata / Convert .mov or .MP4 to .gif.md
Created September 20, 2020 09:18 — forked from SheldonWangRJT/Convert .mov or .MP4 to .gif.md
Convert Movie(.mov) file to Gif(.gif) file in one command line in Mac Terminal

This notes is written by Sheldon. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

Need

Convert .mov/.MP4 to .gif

Reason

As a developer, I feel better to upload a short video when I create the pull request to show other viewers what I did in this PR. I tried .mov format directly got after finishing recording screen using Quicktime, however, gif offers preview in most web pages, and has smaller file size.

This is not limited to developer, anyone has this need can use this method to convert the files.

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