Skip to content

Instantly share code, notes, and snippets.

View programaker's full-sized avatar

Marcelo da Silva Gomes programaker

View GitHub Profile
sealed trait Expr
case class Const(d: Double) extends Expr
case class Var(a: String) extends Expr
case class Times(l: Expr, r: Expr) extends Expr
case class Plus(l: Expr, r: Expr) extends Expr
@johnynek
johnynek / dotty_list.scala
Last active January 12, 2020 13:43
Implementation of linked list using dotty features (opaque type, union types, extension methods, type lambda).
// unfortunately
// opaque type Fix[F[_]] = F[Fix[F]]
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf
object FixImpl {
type Fix[F[_]]
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]]
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]]
}
@alexandredantas
alexandredantas / tf_monad.scala
Created July 29, 2019 17:17
custom monads for tagless final
import scalaz.std.list._
import zio.IO
import scalaz.{ Applicative, Monad }
import scala.util.Try
package object types{
type ThrowableSafeResult[+T] = IO[Throwable, T]
implicit val ioMonadInstance: Monad[ThrowableSafeResult] = new Monad[ThrowableSafeResult] {
@douglascayers
douglascayers / github-copy-labels.sh
Last active December 22, 2023 08:16
Export and import GitHub labels between projects by running bash script with jq and curl. Uses GitHub REST API. Requires personal access token.
# This script uses the GitHub Labels REST API
# https://developer.github.com/v3/issues/labels/
# Provide a personal access token that can
# access the source and target repositories.
# This is how you authorize with the GitHub API.
# https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line
GH_TOKEN="YOUR_TOKEN"
# If you use GitHub Enterprise, change this to "https://<your_domain>/api/v3"
@douglascayers
douglascayers / github-export-labels.js
Last active September 14, 2023 15:30
Export and import GitHub labels between projects by running JavaScript in the browser console to automate clicks.
/**
* Inspired by @MoOx original script: https://gist.github.com/MoOx/93c2853fee760f42d97f
* Adds file download per @micalevisk https://gist.github.com/MoOx/93c2853fee760f42d97f#gistcomment-2660220
*
* Changes include:
* - Get the description from the `title` attribute instead of `aria-label` (doesn't exist anymore)
* - Use style.backgroundColor and parse the rgb(...) to hex (rather than regex parsing of 'style' string)
* - Downloads labels to a JSON file named after the webpage to know which GitHub repo they came from.
*
* Last tested 2019-July-27:
@alexandredantas
alexandredantas / zio-environment-setup.scala
Last active July 22, 2019 21:10
Setting up ZIO environment with custom traits
import zio.clock.Clock
import zio.console.Console
import zio.system.System
import zio.random.Random
import zio.blocking.Blocking
import com.typesafe.config.Config
import zio.Task
import com.typesafe.config.ConfigFactory
import scala.collection.JavaConverters
@adrianobrito
adrianobrito / magnofy.js
Created February 20, 2019 13:33
Magnofy caraio
const charMap = {
'á' : "'a",
'Á' : 'A',
'ã' : 'a] ',
'Ã' : 'A]',
'â' : '^a',
'Â' : '^A',
'à' : '`a',
'À' : "`A",
'é' : "'e",
@gustavompo
gustavompo / atividadenovacilo.js
Created August 22, 2018 21:56
atividadenovacilo.js
[{url: "https://emoji.slack-edge.com/T6CU2169Z/100sual/b3a1531ff45f2acd.jpg", name: ":100sual:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1_don%2527t_pick_up_the_phone/8dd1f635352780e8.png", name: ":1_don't_pick_up_the_phone:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1hokage/9e66cda3a2ecf310.jpg", name: ":1hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2_don%2527t_let_him_in/eb898e174fa62821.png", name: ":2_don't_let_him_in:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2hokage/63f4935ed5608b8c.gif", name: ":2hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3_don%2527t_be_his_friend/68b9721a15ed8aeb.png", name: ":3_don't_be_his_friend:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3hokage/765b9b0f9d994981.jpg", name: ":3hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/4hokage/39a0745cfb994d6c.jpg", name: ":4hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/5hokage/0e9dcea089de5b8b.jpg", name: ":5hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/6hokag
@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 =