Skip to content

Instantly share code, notes, and snippets.

View ZviMints's full-sized avatar
🏄‍♂️

Zvi Mints ZviMints

🏄‍♂️
View GitHub Profile
sealed case class BrandSafetyFeatureStatus(override val value: Long) extends FlaggedEnum[BrandSafetyFeatureStatus]
object BrandSafetyFeatureStatus extends enumeratum.Enum[BrandSafetyFeatureStatus] {
object Inclusion extends BrandSafetyFeatureStatus(1L << 0)
object Exclusion extends BrandSafetyFeatureStatus(1L << 1)
object Exception extends BrandSafetyFeatureStatus(1L << 2)
override def values: IndexedSeq[BrandSafetyFeatureStatus] = findValues
}
@ZviMints
ZviMints / ! Scala 2 & 3 Enums Evaluation.md
Last active May 10, 2023 09:01
Scala 2 & 3 Enums Evaluation

Scala 2 & 3 Enums Evaluation

@ZviMints
ZviMints / NQueens-Solution.scala
Last active April 20, 2021 07:40
NQueens Counter Solution
// https://leetcode.com/problems/n-queens-ii/
object Solution extends App {
def totalNQueens(N: Int): Int = {
type Board = Array[Array[Boolean]]
def putQueen(board: Board, row: Int, col: Int): Unit = board(row)(col) = true
def removeQueen(board: Board, row: Int, col: Int): Unit = board(row)(col) = false
def isValid(board: Board, row: Int, col: Int): Boolean = {
val checkCol = (0 until row).forall(currRow => board(currRow)(col) == false )
val checkLeftDiagonal = ((row to 0 by -1) zip (col to 0 by -1)).forall { case (currRow, currCol) => board(currRow)(currCol) == false }
val checkRightDiagonal = ((row to 0 by -1) zip (col until N)).forall { case (currRow, currCol) => board(currRow)(currCol) == false }
@ZviMints
ZviMints / LevelOrderSideView.scala
Last active April 19, 2021 20:43
BST Side view
// https://leetcode.com/problems/binary-tree-right-side-view/
class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {
var value: Int = _value
var left: TreeNode = _left
var right: TreeNode = _right
}
object Solution {
def rightSideView(root: TreeNode): List[Int] = {
@ZviMints
ZviMints / isValidBST.scala
Created March 19, 2021 20:29
Checks if BST is valid
// https://leetcode.com/problems/validate-binary-search-tree/
class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {
var value: Int = _value
var left: TreeNode = _left
var right: TreeNode = _right
}
object Solution {
def isValidBST(root: TreeNode): Boolean = {
@ZviMints
ZviMints / Dependencies.sc
Last active March 18, 2021 19:12
Scala & Play - I/O Service with parquet writer/reader (parquet4s) and json writer/reader (play-js) and Array[Byte] writer/reader
val HadoopVersion = "2.5.2"
val hadoop = Seq(
"org.apache.hadoop" % "hadoop-client" % HadoopVersion exclude("org.slf4j", "*")
)
val parquet4s = Seq(
"com.github.mjakubowski84" %% "parquet4s-core" % "1.7.0" exclude("org.slf4j", "*")
)
@ZviMints
ZviMints / Retry.sc
Last active March 18, 2021 18:58
Asynchronous retry for Future in Scala
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.FiniteDuration
import scala.util.control.NonFatal
import scala.concurrent.ExecutionContext.Implicits.global
def foo(): Future[Unit] = if(Math.random() >= 1/3) Future.failed(new RuntimeException("")) else Future.successful(())
def retry[T](retries: Int, delay: FiniteDuration)(fn: => Future[T]): Future[T] = {
fn recoverWith {
@ZviMints
ZviMints / welcome.gif
Last active March 16, 2022 20:21
Welcome to my Github Page
welcome.gif