Skip to content

Instantly share code, notes, and snippets.

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

Mateusz Maciaszek speedcom

🏠
Working from home
View GitHub Profile
@speedcom
speedcom / onp.scala
Created February 21, 2017 16:05
Exemplary ONP implementation in Scala
import scala.collection.mutable.Stack
val equation = "12 2 3 4 * 10 5 / + * +"
val ops = equation.split(" ")
val stack = new Stack[Int]()
def *(a: Int, b: Int) = a * b
def /(a: Int, b: Int) = a / b
def +(a: Int, b: Int) = a + b
@speedcom
speedcom / keybase.md
Created January 20, 2017 08:32
keybase.io verification

Keybase proof

I hereby claim:

  • I am speedcom on github.
  • I am mmaciaszek (https://keybase.io/mmaciaszek) on keybase.
  • I have a public key whose fingerprint is 5869 5C6A 1B54 8356 6273 CFDF 8CC5 3EDC 0017 5187

To claim this, I am signing this object:

@speedcom
speedcom / scalastm.scala
Last active May 12, 2016 08:34
Making asynchronous IO operation from within atomic ScalaSTM block
val cache = Ref[List[Int]](Nil)
val needUpdate = Ref[Boolean](true)
def getOrUpdate = atomic { implicit txn =>
if(needUpdate()) {
asyncCallingToWebservice().map { data =>
cache() = data
needUpdate() = false
data
@speedcom
speedcom / ErrorFailure.scala
Created April 26, 2016 18:29 — forked from atamborrino/ErrorFailure.scala
Monad transformer for Future[A Or Every[Error]]
package models.error
import org.scalactic._
import scala.concurrent.{ExecutionContext, Future}
import org.scalactic.Accumulation._
trait Error
object FutureOr {
type Errors = Every[Error]
sealed trait Mark
case object Circle extends Mark
case object Cross extends Mark
case class Board(array: Array[Array[Mark]]) {
lazy val cols: Array[Array[Mark]] = {
val col1 = Array(array(0)(0), array(1)(0), array(2)(0))
val col2 = Array(array(0)(1), array(1)(1), array(2)(1))
@speedcom
speedcom / ScheduledExecutor.scala
Created January 11, 2016 22:29 — forked from platy/ScheduledExecutor.scala
Scala wrapper around java's ScheduledExecutorService
import java.util.concurrent.ThreadPoolExecutor.AbortPolicy
import java.util.concurrent._
import scala.concurrent.{ Promise, Future }
import scala.concurrent.duration.FiniteDuration
import scala.language.implicitConversions
import scala.util.Try
object ScheduledExecutor {
private val defaultHandler: RejectedExecutionHandler = new AbortPolicy
@speedcom
speedcom / monad.scala
Created October 17, 2015 19:45
Scala Monad For-Comprehension
/** A for comprehension ready Monad */
case class Focomo[A](value: A) {
self =>
/** satisfies monadic binding of a function f that returns B */
def map[B](f: A => B): Focomo[B] = {
println("map!");
Focomo(f(value))
}
/** satisfies monadic binding of a function f that returns Focomo[B] */
def flatMap[B](f: A => Focomo[B]): Focomo[B] = {
object ReadSample extends App {
/**
* The readable trait defines how objects can be converted from a string
* representation to the objects instance. For most of the standard types
* we can simply use the toType function of String.
*/
trait Readable[T] {
def read(x: String): T
}
package Boot
import akka.actor.{Cancellable, Actor, ActorSystem, Props}
import akka.stream.{OverflowStrategy, ActorFlowMaterializer}
import akka.stream.actor.ActorSubscriberMessage.{OnComplete, OnNext}
import akka.stream.actor.{ActorSubscriber, OneByOneRequestStrategy, RequestStrategy}
import akka.stream.scaladsl._
import org.akkamon.core.exporters.StatsdExporter
import org.akkamon.core.instruments.{CounterTrait, LoggingTrait, TimingTrait}
@speedcom
speedcom / View Bound
Last active September 30, 2015 13:38
implicit conversion from one type to another one
// implicit conversion from one type to another one
// 1 way
object ViewBound {
trait Show {
def show: String
}
object Show {