Skip to content

Instantly share code, notes, and snippets.

// comparing to kotlin version: https://proandroiddev.com/extension-classes-f9dcf5878b71
sealed trait Feature
object SomeFeature extends Feature
trait AppFeatures {
def isEnabled(feature: Feature): Boolean
}
extension (appFeatures: AppFeatures)
@mushtaq
mushtaq / LoggingMailbox.scala
Created June 14, 2019 04:06 — 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 }
https://conferences.oreilly.com/velocity/vl-ca-2018/user/proposal/status/66492
Proposal: "Actor based architecture for world's largest optical telescope"
Status
Although accepted, you were unable to present this proposal.
Proposal details
Proposer
Nishant Vishwakarma (nishantv12@gmail.com)
package com.thoughtworks
import java.util.concurrent.Executors
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
trait Tap {
def apply[A](future: Future[A]): Future[A]
}
@mushtaq
mushtaq / FlowControlSample.scala
Created May 6, 2018 02:37 — forked from patriknw/FlowControlSample.scala
Illustrates Actor message flow control with "work pulling pattern". This code is licensed under the Apache 2 license.
package flowcontrol
import scala.concurrent.duration._
import akka.actor.typed.ActorRef
import akka.actor.typed.ActorSystem
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
/**
@mushtaq
mushtaq / Osc.scala
Created April 14, 2018 14:13 — forked from ochrons/Osc.scala
ScalaFiddle gist
import math._
val (h, w) = (Page.canvas.height, Page.canvas.width)
var x = 0.0
// $FiddleStart
val graphs = Seq[(String, Double => Double)](
("red", sin),
("green", x => 2 - abs(x % 8 - 4)),
("blue", x => 3 * pow(sin(x / 12), 2) * sin(x))
)
// $FiddleEnd
def foldLeft[Elm, Res](xs: List[Elm], seed: Res)(combine: (Res, Elm) => Res): Res = xs match {
case Nil => seed
case head :: tail => foldLeft(tail, combine(seed, head))(combine)
}
sealed trait Fn[Res] {
def invoke(x: Res): Res
}
case class Identity[Res]() extends Fn[Res] {
override def invoke(x: Res): Res = x

Principled Meta Programming for Scala

This note outlines a principled way to meta-programming in Scala. It tries to combine the best ideas from LMS and Scala macros in a minimalistic design.

  • LMS: Types matter. Inputs, outputs and transformations should all be statically typed.

  • Macros: Quotations are ultimately more easy to deal with than implicit-based type-lifting

  • LMS: Some of the most interesting and powerful applications of meta-programming

@mushtaq
mushtaq / demo.scala
Created July 20, 2017 05:02
akka-typed-mutable
package csw.sample
import akka.NotUsed
import akka.typed.scaladsl.Actor.MutableBehavior
import akka.typed.scaladsl.{Actor, ActorContext}
import akka.typed.{ActorRef, ActorSystem, Behavior}
import csw.sample.Messages.Command.IdleCommand.Initialize
import csw.sample.Messages.Command.InitializedCommand.{Add, Reset}
import csw.sample.Messages.Command.{GetMode, IdleCommand, InitializedCommand, Stop}
import csw.sample.Messages.Mode.{Idle, Initialized}