Skip to content

Instantly share code, notes, and snippets.

View gvolpe's full-sized avatar
🤓
https://leanpub.com/u/gvolpe

Gabriel Volpe gvolpe

🤓
https://leanpub.com/u/gvolpe
View GitHub Profile
{
appimagePackage = { binName, version, url, sha256 ? fakeSha256
, meta ? { platforms = [ "x86_64-linux" ]; } }:
let
pname = "${binName}-appimage";
name = "${pname}-${version}";
src = fetchurl {
inherit url sha256;
name = "${name}.AppImage";
@gvolpe
gvolpe / raceN.scala
Created December 13, 2019 13:54 — forked from ChristopherDavenport/raceN.scala
An Implementation of a Safe Multi-value Race
object RaceN {
import cats.implicits._
import cats.effect._
import cats.effect.concurrent._
import cats.data.NonEmptyList
// Use with atleast 3, otherwise you should prefer Concurrent.race
def raceN[F[_]: Concurrent, A](x1: F[A], x2: F[A], x3: F[A], xs: F[A]*): F[Either[NonEmptyList[Throwable], A]] = {
for {
deferred <- Deferred[F, A]
@gvolpe
gvolpe / RefMap.scala
Created November 22, 2019 15:49 — forked from johnynek/RefMap.scala
A wrapper on ConcurrentHashMap to use with cats.effect.Ref
package org.bykn.refmap
import cats.data.State
import cats.effect.Sync
import cats.effect.concurrent.Ref
import java.util.concurrent.ConcurrentHashMap
import cats.implicits._
/**
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.string.MatchesRegex
object refinements {
type EmailPred = MatchesRegex[W.`"""(?=[^\\s]+)(?=(\\w+)@([\\w\\.]+))"""`.T]
type Email = String Refined EmailPred
}
set directory=~/.vim/backup
set backupdir=~/.vim/backup " keep swap files here
filetype off " required
call plug#begin('~/.local/share/nvim/plugged') " you need to create this directory first (or change it)
Plug 'vim-airline/vim-airline' " bottom status bar
Plug 'vim-airline/vim-airline-themes'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " fuzzy finder conf
Plug 'junegunn/fzf.vim' " fuzzy finder
@gvolpe
gvolpe / OpClasses.idr
Created August 21, 2019 23:52 — forked from sellout/OpClasses.idr
Defining ad-hoc polymorphism using dependently-typed implicits.
-- This illustrates (most of) a new(?) encoding of ad-hoc polymorphism using
-- dependent types and implicits.
--
-- Benefits of this approach:
-- • can have multiple “ambiguous” instances without requiring things like
-- Haskell’s newtypes to distinguish them;
-- • can disambiguate instances with minimal information, rather than having to
-- know some arbitrary instance name as you would with a system like Scala’s
-- implicits;
-- • implementers don’t need to know/provide the full family of instances – they
@gvolpe
gvolpe / sharding-fs2.scala
Last active May 24, 2019 01:34
Sharding values using Fs2
import cats.effect._
import cats.effect.concurrent.Ref
import cats.implicits._
import fs2._
import fs2.concurrent.Queue
import scala.util.control.NoStackTrace
object ShardingDemo extends IOApp {
def putStrLn[A](a: A): IO[Unit] = IO(println(a))
@gvolpe
gvolpe / CachedResource-Blog.md
Created April 16, 2019 00:45 — forked from Daenyth/CachedResource-Blog.md
CachedResource for cats-effect

Motivation

cats-effect Resource is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:

trait Resource[F[_], A] {
  /** - Acquire resource
    * - Run f
    * - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails
    */
 def use[B](f: A =&gt; F[B]): F[B]
flip' :: (a -> b -> c) -> b -> a -> c
flip' f b a = f a b
andThen :: (a -> b) -> (b -> c) -> a -> c
andThen = flip' (.)
// (.) :: (b -> c) -> (a -> b) -> a -> c
implicit class FancyComposition[A, B, C](f: B => C) {
def `.`(g: A => B): A => C = f.compose(g)
}
val f: Int => String = _.toString
val g: String => Boolean = _.contains("1")
val h: Int => Boolean = g `.` f