Skip to content

Instantly share code, notes, and snippets.

View programaker's full-sized avatar

Marcelo da Silva Gomes programaker

View GitHub Profile
@noelwelsh
noelwelsh / reader-monad.md
Last active October 23, 2020 14:27
Discovering the Reader Monad

The Reader Monad

The reader monad is one solution to "dependency injection". This document shows how we might discover the reader monad when we attempt to solve this problem.

Dependency Injection

Our working definition of the dependency injection problem will be this: we have a method or function that takes certain parameters that we don't want to specify every time we call it. For example, we might have a function that gets a user given an ID and also requires a database connection.

def getUser(db: DbConnection, id: Id): User =
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@paraseba
paraseba / folds.scala
Created May 30, 2018 14:04
Demonstration of implementing foldRight with by-name parameter
/*
This is a demonstration of foldLeft and foldRight in scala using
by-name parameters to process infinite streams and to short-circuit
computations that can finish early.
*/
import scala.annotation.tailrec
/*
foldLeft can be written in tail recursive form. The recursive call is not
@a7madgamal
a7madgamal / dark.md
Last active November 24, 2024 16:39
Dark mode for Slack on MacOS
@monaddle
monaddle / composableinterpreters.scala
Created September 9, 2017 03:00
free monads using scalaz. Example of composing interpreters.
package testfree
import testfree.Console._
import testfree.Authorization.{ Authorize}
import scalaz.{Inject, _}
import Scalaz._
import scala.io.StdIn
import scalaz.Inject._
// Example of using two separate ADTs with separate interpreters and composing the interpeters.
// See talk by Runar Bjarnason https://www.youtube.com/watch?v=M258zVn4m2M, or "onion architecture" description

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@ploeh
ploeh / ApiModel.hs
Last active December 24, 2022 22:54
Handling a reservation request in Haskell. Proof of concept
module ApiModel where
import Data.Time (ZonedTime(..), parseTimeM, defaultTimeLocale, iso8601DateFormat)
data ReservationRendition = ReservationRendition
{ rDate :: String
, rName :: String
, rEmail :: String
, rQuantity :: Int }
deriving (Eq, Show, Read)
@davegurnell
davegurnell / TypeclassDemo.scala
Created October 6, 2015 14:53
Example of the type class pattern in Scala
object TypeclasseDemo {
// The parts of the type class pattern are:
//
// 1. the "type class" itself -- a trait with a single type parameter;
//
// 2. type class "instances" for each type we care about,
// each marked with the `implicit` keyword;
//
// 3. an "interface" to the type class -- one or more methods
@gigiigig
gigiigig / auxpattern.scala
Last active November 3, 2025 12:17
Aux Pattern
import shapeless._
import scalaz._
import Scalaz._
object console extends App {
trait Foo[A] {
type B
def value: B
@MoOx
MoOx / index.js
Last active June 8, 2025 14:14
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),