Skip to content

Instantly share code, notes, and snippets.

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
View cron_scala.scala
/** Usage:
{{{
val expr = CronExpr.mk("15 9 * * *")
expr flatMap (_.durationToNextExecution(ZonedDateTime.now()))
expr flatMap (_.durationFromPreviousExecution(ZonedDateTime.now())
expr flatMap (_.nextExecutionTimeFrom(ZonedDateTime.now())
View EqualAndMonoid.scala
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
}
}
View simple_scala_template.scala
- build.sbt
- src/main/scala
- project/build.properties
View s3_lambda
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")
View s3_lambda
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")
View java_scala_time.scala
// 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)
View tree_to_table.scala
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
View .zshrc_file
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/afsalthaj/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
View ok_recursion_schemes.scala
object RecursionSchemes extends App {
import PropertyTreeX._
sealed trait PropertyTreeX[+K, +V, +A]
object PropertyTreeX {
final case object EmptyX extends PropertyTreeX[Nothing, Nothing, Nothing]
You can’t perform that action at this time.