Skip to content

Instantly share code, notes, and snippets.


Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

phucnh /
Last active Sep 10, 2019
Find rate of empty value grouped by column in csv (or tsv) file
phucnh / gist:c4bc393ca654873cacb9ad829694ef92
Created Aug 25, 2019 — forked from ryanlecompte/gist:5210745
mutable.ArrayBuffer vs immutable.Vector
View gist:c4bc393ca654873cacb9ad829694ef92
import scala.collection._
import com.twitter.util._
scala> val buffer = mutable.ArrayBuffer.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer += _ } }.inMillis)
scala> var vector = immutable.Vector.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { vector :+= _ } }.inMillis)

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
phucnh /
Created Jun 6, 2019 — forked from thibautsacreste/
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
phucnh /
Created Apr 18, 2018 — forked from seeebiii/
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 /
Created Jul 24, 2017 — forked from okumin/
phucnh / 0_reuse_code.js
Created Apr 18, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
phucnh / gist:2d89a1b8811e706ffbbe32aa48e6e9c1
Created Dec 14, 2016 — forked from cvogt/gist:9193220
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
View gist:2d89a1b8811e706ffbbe32aa48e6e9c1
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) = { => MaybeFilter(query.filter(f(v)))).getOrElse(this)
// example use case
import java.sql.Date
phucnh / find-dead-executors.groovy
Created Dec 2, 2016 — forked from malonem/find-dead-executors.groovy
Jenkins script to find dead executors and remove them.
View find-dead-executors.groovy
// get handle to build output
def config = new HashMap()
def bindings = getBinding()
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 ) {