Skip to content

Instantly share code, notes, and snippets.

View a2mz's full-sized avatar

Oleksandr Morozov a2mz

View GitHub Profile
@a2mz
a2mz / gist:cd1ea209d70771663a20665a0a868a79
Last active June 28, 2017 13:18 — forked from jpbougie/gist:1827065
[SOAPFinagle] #soap #finagle #scala
import java.net.InetSocketAddress
import scala.xml.{Elem, XML}
import org.jboss.netty.buffer.ChannelBuffers
import org.jboss.netty.util.CharsetUtil.UTF_8
import com.twitter.finagle.Service;
import com.twitter.finagle.builder.ClientBuilder;
import com.twitter.finagle.http.{Http, RequestBuilder};
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer
import java.net.URL

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
@a2mz
a2mz / RobotCommands.scala
Last active June 28, 2017 13:18 — forked from pfcoperez/RobotCommands.scala
[Parsers] Parsers combinators example #scala #parsers
import scala.util.parsing.combinator._
object RobotCommands extends App {
object Entities {
trait MovementDirection
case object Up extends MovementDirection
case object Down extends MovementDirection
case object Left extends MovementDirection
@a2mz
a2mz / freemonads.scala
Created August 12, 2017 05:29 — forked from kciesielski/freemonads.scala
Free Monads example
package com.softwaremill.freemonads
import cats.free.Free
import cats.~>
import cats._, cats.std.all._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
sealed trait External[A]
case class Tickets(count: Int) extends AnyVal
import cats.{Id, Monad, Traverse, ~>}
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
object TagLess extends App {
case class PurchaseOrderId(value: String)
case class ProductId(value: String)
case class LocationId(value: String)
@a2mz
a2mz / AkkaHttpMicroService.scala
Created October 27, 2017 04:43 — forked from jeroenr/AkkaHttpMicroService.scala
Akka HTTP API with CORS headers and custom Media types
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
object Boot extends App with Service with CorsSupport {
override implicit val system = ActorSystem()
override implicit val executor = system.dispatcher
override implicit val materializer = ActorMaterializer()
Http().bindAndHandle(corsHandler(routes), "0.0.0.0", 1337)
@a2mz
a2mz / TestMultipartFileUpload.scala
Created November 13, 2017 13:41 — forked from jrudolph/TestMultipartFileUpload.scala
akka-http Multipart file-upload client + server example
package akka.http.scaladsl
import java.io.File
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.util.ByteString
import scala.concurrent.duration._
import akka.actor.ActorSystem
case class Person1(name: String, age: Int, other: Option[String])
case class Person2(name: String, age: Int, other: String)
import play.api.libs.functional.syntax._
import play.api.libs.json._
implicit val person1Format = (
(JsPath \ "name").format[String] and
(JsPath \ "age").format[Int] and
(JsPath \ "other").formatNullable[String].inmap[Option[String]](x => Some(x.getOrElse("default")), y => y)
@a2mz
a2mz / LoggingMailbox.scala
Created November 10, 2018 05:08 — forked from patriknw/LoggingMailbox.scala
Logs the mailbox size when exceeding the configured limit. Implemented in Scala and Java. Copy one of them to your project and define the configuration. This code is licensed under the Apache 2 license.
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.mailbox
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import com.typesafe.config.Config
import akka.actor.{ ActorContext, ActorRef, ActorSystem, ExtendedActorSystem }
@a2mz
a2mz / DependencyInjection.scala
Created March 23, 2020 06:05 — forked from fanf/DependencyInjection.scala
Simple, Static Scala dependency injection with Shapeless
package test_shapeless
object DI {
import shapeless._
trait Injecter[L <: HList, A] {
def apply(l: L) : A
}
trait InjecterAux[L <: HList, A] {