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 TemporaryLocalFile.scala
import java.io.FileInputStream
import java.nio.file.{ Files, Path }
import cats.Applicative
import cats.implicits._
import cats.effect.{ IO, Resource }
import com.amazonaws.services.s3.model.S3Object
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.FileUtils
View download_S3_files.scala
import cats.effect.{ IO, Resource }
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.model.ListObjectsV2Request
import org.apache.commons.lang.StringUtils
def getKeys(client: AmazonS3, path: S3Path): IO[List[String]] = IO {
client
.listObjectsV2(
new ListObjectsV2Request().withBucketName(path.parentBucket).withPrefix(path.prefix)
)
View blog_scala.scala
import cats.data.StateT
import cats.effect.{ IO, Resource }
import cats.syntax.traverse._
import cats.instances.list._
import Resources.StateInfo
final case class Resources[A](resources: List[Resource[IO, A]]) {
def executeAll: Resource[IO, List[A]] =
resources.sequence[Resource[IO, *], A]
View resource_handles_and_duplicate_processing.scala
import cats.data.StateT
import cats.effect.{ IO, Resource }
import cats.syntax.traverse._
import cats.instances.list._
import Resources.StateInfo
/**
* Resources is a light weight stuff on top of `cats.Resource`
* to guarantee strong semantics of acquisitions and release for a collection of resources,
* while allowing you to maintain some state.
View load_jar_to_ammonite.scala
@ 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)
View my_nix.nix
{ 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";
}) {};
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
You can’t perform that action at this time.