Skip to content

Instantly share code, notes, and snippets.

View abelbryo's full-sized avatar

Abel Terefe abelbryo

View GitHub Profile
object UserEntityModule {
case class UserEntityF[F[_], G[_]](id: G[Option[Long]] = None, username: F[String], password: F[String])
type Id[A] = A
type Forget[A] = Unit
// You can also just use Option if you don't care
// for the domain-specific type
sealed trait Updatable[+A] {
def foreach(f : A => Unit): Unit = this match {
@brianshumate
brianshumate / docker-macos-terraform.md
Last active November 14, 2024 11:35
The Simplest Terraform with Docker on macOS

If you'd like to experiment with Terraform on macOS locally, a great provider for doing so is the Docker provider. You can get set up in a few simple steps, like so:

1. Install Docker

Install Docker for Mac if you have not already.

@bpholt
bpholt / CloudFormationStack.scala
Last active November 7, 2019 07:51
sbt InputTask chaining
package com.dwolla.sbt.cloudformation
import com.dwolla.awssdk.cloudformation.CloudFormationClient
import com.dwolla.sbt.cloudformation.CloudFormationStackParsers._
import sbt.IO.{read, utf8}
import sbt.Keys._
import sbt._
import scala.language.{implicitConversions, postfixOps}
@paulp
paulp / global.sbt
Last active October 16, 2018 19:09
continuous compilation of the sbt build
// These lines go in ~/.sbt/0.13/global.sbt
watchSources ++= (
(baseDirectory.value * "*.sbt").get
++ (baseDirectory.value / "project" * "*.scala").get
++ (baseDirectory.value / "project" * "*.sbt").get
)
addCommandAlias("rtu", "; reload ; test:update")
addCommandAlias("rtc", "; reload ; test:compile")
addCommandAlias("ru", "; reload ; update")

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 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
// allows converting one class to another by providing missing fields
object convert {
@annotation.implicitNotFound("""
You have not provided enough arguments to convert from ${In} to ${Out}.
${Args}
""")
trait Convertible[Args, In, Out] {
def apply(args: Args, in: In): Out
}
@d6y
d6y / flags.scala
Created May 15, 2015 15:56
Flags (for Slick 3.0)
import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
object EnrichExample extends App {
sealed case class Flag(val value: Boolean)
@tyrcho
tyrcho / Backtracking.scala
Last active November 28, 2017 00:21
Backtracking generic algorithm with demo on the problem of the 8 (or N) queens
import scala.annotation.tailrec
object Backtracking {
trait Problem {
type Node
trait Result
case object Rejected extends Result
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@lshoo
lshoo / gist:9785645
Created March 26, 2014 15:13
Slick2 generic dao
package slicks.docs.dao
import scala.slick.driver.PostgresDriver.simple._
import scala.slick.driver._
trait Profile {
val profile: JdbcProfile
}