Skip to content

Instantly share code, notes, and snippets.

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}

This cheat sheet originated from the forum, credits to Laurent Poulain. We copied it and changed or added a few things.

Evaluation Rules

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if need be
    def example = 2      // evaluated when called
    val example = 2      // evaluated immediately
@phucnh
phucnh / API.md
Created July 12, 2016 16:33 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@phucnh
phucnh / .ctags
Last active November 10, 2016 16:33 — forked from ScrapCodes/etags.sh
file for etags --regex@${file} to generate scala tags.
-e
--langdef=scala
--langmap=scala:.scala
--regex-scala=class\s+(\w+)/\1/c,classes/
--regex-scala=object\s+(\w+)/\1/c,objects/
--regex-scala=trait\s+(\w+)/\1/t,traits/
--regex-scala=type\s+(\w+)/\1/T,types/
--regex-scala=def\s+(\w+)/\1/m,methods/
--regex-scala=val\s+(\w+)/\1/l,constants/
--regex-scala=var\s+(\w+)/\1/l,variables/
@phucnh
phucnh / find-dead-executors.groovy
Created December 2, 2016 03:08 — forked from malonem/find-dead-executors.groovy
Jenkins script to find dead executors and remove them.
// get handle to build output
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
def out = config['out']
for (aSlave in hudson.model.Hudson.instance.slaves) {
// check if executor is dead
execList = aSlave.getComputer().getExecutors()
for( exec in execList ) {
@phucnh
phucnh / gist:2d89a1b8811e706ffbbe32aa48e6e9c1
Created December 14, 2016 00:20 — forked from cvogt/gist:9193220
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
import scala.slick.lifted.CanBeQueryCondition
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
import java.sql.Date
@phucnh
phucnh / 0_reuse_code.js
Created April 18, 2017 04:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@phucnh
phucnh / akka-persistence.md
Created July 24, 2017 12:14 — forked from okumin/akka-persistence.md
akka-persistenceのプラグインをつくろう
@phucnh
phucnh / LambdaConstants.java
Created April 18, 2018 01:39 — forked from seeebiii/LambdaConstants.java
Available default environment variables in AWS Lambda. Just copy&paste into your Node or Java project.
public class Constants {
/**
* Contains the path to your Lambda function code.
*/
public static final String LAMBDA_TASK_ROOT = System.getenv("LAMBDA_TASK_ROOT");
/**
* The environment variable is set to one of the following options, depending on the runtime of the Lambda function:
* AWS_Lambda_nodejs, AWS_Lambda_nodejs4.3, AWS_Lambda_nodejs6.10
@phucnh
phucnh / aws.sg.unused
Created June 6, 2019 15:09 — forked from thibautsacreste/aws.sg.unused
Bash: list unused AWS security groups
#!/usr/bin/env bash
# lists all unused AWS security groups.
# a group is considered unused if it's not attached to any network interface.
# requires aws-cli and jq.
# all groups
aws ec2 describe-security-groups \
| jq --raw-output '.SecurityGroups[] | [.GroupName, .GroupId] | @tsv' \
| sort > /tmp/sg.all