Skip to content

Instantly share code, notes, and snippets.

View afsalthaj's full-sized avatar
💭
Every day is learning. Every day is the pursuit to perfectness.

Afsal Thaj afsalthaj

💭
Every day is learning. Every day is the pursuit to perfectness.
View GitHub Profile
@ val path = java.nio.file.FileSystems.getDefault().getPath("/Users/afsalthaj/telstra/cij-orchestration/target/cij-orchestration-1.0.0-GA.jar")
path: java.nio.file.Path = /Users/afsalthaj/telstra/cij-orchestration/target/cij-orchestration-1.0.0-GA.jar
@ val x = ammonite.ops.Path(path)
x: os.Path = root/'Users/'afsalthaj/'telstra/"cij-orchestration"/'target/"cij-orchestration-1.0.0-GA.jar"
@ interp.load.cp(x)
{ pkgs ? import <nixpkgs> {} }:
with import (builtins.fetchTarball {
# Descriptive name to make the store path easier to identify
name = "nixos-unstable-2019-10-04";
# Commit hash for nixos-unstable as of Mon Sep 2 01:17:20 2019 -0400
url = https://github.com/nixos/nixpkgs/archive/85b7d89892a4ea088d541a694addb2e363758e44.tar.gz;
# Hash obtained using `nix-prefetch-url --unpack <url>`
sha256 = "0wxv4jvv9gri8kjzijrxdd1ijprwbsgsnzmjk2n4yxi0j41jk2f6";
}) {};
/** Usage:
{{{
val expr = CronExpr.mk("15 9 * * *")
expr flatMap (_.durationToNextExecution(ZonedDateTime.now()))
expr flatMap (_.durationFromPreviousExecution(ZonedDateTime.now())
expr flatMap (_.nextExecutionTimeFrom(ZonedDateTime.now())
trait Equal[-A] extends EqualLaws[A] {
def equal(a: A, b: A): Boolean
}
object Equal {
implicit val equalInt: Equal[Int] = new Equal[Int] {
def equal(a: Int, b: Int) = a == b
}
}
bloop server
- build.sbt
- src/main/scala
- project/build.properties
import json
import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
class ZeroClustersAvailable(Exception): pass
class MoreThanOneClusterAvailable(Exception): pass
def lambda_handler(event, context):
client = boto3.client('emr')
logger.info("Trying to list the clusters that are in either waiting or running state")
import json
import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
class ZeroClustersAvailable(Exception): pass
class MoreThanOneClusterAvailable(Exception): pass
def lambda_handler(event, context):
client = boto3.client('emr')
logger.info("Trying to list the clusters that are in either waiting or running state")
// I don't know why I keep forgetting this, and having to go to API docs everytime, hence a gist for all those who are like me.
import java.time._
import java.time.format.DateTimeFormatter
import java.util._
val instant = Instant.now()
// Best thing to to get the current time at this zone
val localTime= ZonedDateTime.now(ZoneId.of("Australia/Sydney"))
println("local time " + localTime)
import scalaz.State
import scalaz._, Scalaz._
import StateInfo._
// A nice functional way to produce a simple table from a tree (minimal code, in real life tree can be further nested and state becomes super important)
// Nowhere it can go wrong, it traverses back and forth the table keys and values and pads empty spaces to match the maximum size of keys and values that's encountered
// up until then.
sealed trait Tree
case class Leaf(key: String, value: String) extends Tree
case class Both(left: Tree, right: Tree) extends Tree