Skip to content

Instantly share code, notes, and snippets.

View etorreborre's full-sized avatar
🏠
Working from home

Eric Torreborre etorreborre

🏠
Working from home
View GitHub Profile
@etorreborre
etorreborre / traverse.scala
Created March 23, 2017 16:38 — forked from pchiusano/traverse.scala
Another encoding of `Traverse` in terms of `mapAccumulate`
/**
* In this version of `Traverse`, sequencing always goes through `List` (or some other canonical sequence type),
* which can be done in a stack-safe manner using a balanced fold as in https://gist.github.com/pchiusano/7667597.
* It's quite nice that `sequence` and `traverse` are now derived functions.
*/
trait Traverse[F[_]] extends Functor[F] {
/** Inefficient but correct implementation of `toList` in terms of `mapAccumulate`. */
def toList[A](f: F[A]): List[A] = mapAccumulate(f, List())((a, rbuf) => (a, a :: rbuf))._2.reverse
/** The only function that must be implemented. Must be consistent with `map`. */

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@etorreborre
etorreborre / failures
Created August 12, 2016 06:43 — forked from paulp/failures
testing coursier as a drop-in replacement
origin https://github.com/gitbucket/gitbucket (fetch)
origin https://github.com/gitbucket/gitbucket (push)
Aug 08 18:50:38 Downloaded https://repo1.maven.org/maven2/com/sun/mail/javax.mail/1.5.2/javax.mail-1.5.2.jar
Aug 08 18:50:38 Downloaded https://repo1.maven.org/maven2/com/typesafe/slick/slick_2.11/2.1.0/slick_2.11-2.1.0.jar
Aug 08 18:50:38 [info] Fetched artifacts of io.github.gitbucket:gitbucket_2.11:4.3.0
Aug 08 18:50:40 coursier.ResolutionException: 1 not found https://repo1.maven.org/maven2/org/apache/sshd/apache-sshd/1.2.0/apache-sshd-1.2.0.jar
Aug 08 18:50:40 [error] (*:update) coursier.ResolutionException: 1 not found https://repo1.maven.org/maven2/org/apache/sshd/apache-sshd/1.2.0/apache-sshd-1.2.0.jar
Aug 08 18:50:40 [error] Total time: 10 s, completed Aug 8, 2016 6:50:40 PM
@etorreborre
etorreborre / RevState.ml
Created June 23, 2016 06:06 — forked from lambdageek/RevState.ml
Reverse State Monad in OCaml.
(* technically this is the lazy state monad. In particular, note the return type of get *)
module type STATE_MONAD =
sig
type ('a,'s) st
val return : 'a -> ('a,'s) st
val bind : ('a,'s) st -> ('a -> ('b, 's) st) -> ('b, 's) st
val get : ('s Lazy.t, 's) st
val modify : ('s -> 's) -> (unit, 's) st
val put : 's -> (unit, 's) st
@etorreborre
etorreborre / shapeless-session.txt
Created April 13, 2016 08:09 — forked from milessabin/shapeless-session.txt
shapeless on the Ammonite REPL with no dependencies other than an installed JDK. Many thanks to @przemekpokrywka for the idea, @alxarchambault for Coursier and @li_haoyi for Ammonite.
miles@frege:~$ ./shapeless.sh
Loading...
Welcome to the Ammonite Repl 0.5.2
(Scala 2.11.7 Java 1.8.0_51)
@ val l = 23 :: "foo" :: true :: HNil
l: Int :: String :: Boolean :: HNil = ::(23, ::("foo", ::(true, HNil)))
@
@etorreborre
etorreborre / hello-coursier-ammonite-play.sh
Created April 13, 2016 08:09 — forked from przemek-pokrywka/hello-coursier-ammonite-play.sh
Serve a webpage using Play framework with a simple script. Nothing more, than Linux and Java required. Thanks to brilliant work of Alexandre Archambault, @li_haoyi and Play developers.
#!/bin/bash
test -e ~/.coursier/cr || (mkdir -p ~/.coursier && wget -q -O ~/.coursier/cr https://git.io/vgvpD && chmod +x ~/.coursier/cr)
CLASSPATH="$(~/.coursier/cr fetch -q -p \
\
com.typesafe.play:play-netty-server_2.11:2.5.0 \
com.typesafe.play:play_2.11:2.5.0 \
com.lihaoyi:ammonite-repl_2.11.7:0.5.2 \
\
)" java \
-Dplay.crypto.secret=foo.bar.baz \
@etorreborre
etorreborre / argonaut.scala
Last active January 30, 2018 14:48 — forked from markhibberd/argonaut.scala
Argonaut union type / inheritance example
package argonaut.example
import argonaut._, Argonaut._
import scalaz._, Scalaz._
object UnionExample extends {
sealed trait Thing
final case class One(n: String, i: Int) extends Thing
final case class Two(n: String) extends Thing
@etorreborre
etorreborre / Err.hs
Last active August 29, 2015 14:22 — forked from nkpart/Err.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fwarn-missing-methods #-}
module Err where
import Control.Lens
import Control.Monad.Error
import Control.Monad.Error.Lens
-- Here is a fairly typical situation, where we have low level errors in certain

Configuring SBT to use 1Password

  1. Install swig-python
  2. Use pip to install 1pass
  3. Install py-levenshtein to avoid annoying warnings
  4. Locate the nearest 1pass script (note: it may be behind you)
  5. Test 1pass on a random password

Create ~/.sbt/0.13/plugins/build.sbt with the following contents:

@etorreborre
etorreborre / gadt.md
Last active August 29, 2015 14:07 — forked from markhibberd/gadt.md

A Basic GADT Challenge

  • I have a bag of stuff.
  • My bag is awesome it can hold different types of things allocated by a name.
  • My bag is kind of ok, in that it can only hold certain types of things. Specifically it can hold Int's, String's and Bool's. But this also makes it convenient to access those things.
  • Conveniently the key tells me what type to expect.

In my haskell2010 world, I implement this as a simple data type: