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
phucnh / README.md
Last active September 10, 2019 05:45
Find rate of empty value grouped by column in csv (or tsv) file
@phucnh
phucnh / gist:c4bc393ca654873cacb9ad829694ef92
Created August 25, 2019 02:16 — forked from ryanlecompte/gist:5210745
mutable.ArrayBuffer vs immutable.Vector
import scala.collection._
import com.twitter.util._
scala> val buffer = mutable.ArrayBuffer.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer += _ } }.inMillis)
17610
scala> var vector = immutable.Vector.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { vector :+= _ } }.inMillis)
7865

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
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
@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 / akka-persistence.md
Created July 24, 2017 12:14 — forked from okumin/akka-persistence.md
akka-persistenceのプラグインをつくろう
@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 / 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 / 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 ) {