Skip to content

Instantly share code, notes, and snippets.

@bilal-fazlani
bilal-fazlani / 0. config.md
Last active April 25, 2024 21:40
OTP generation and validation
Config name Section Type Description
secret Both string  
length Generation int 6,7,8 digits of OTP
expiry-duration Generation duration 1m, 30s
otp-buffer-window Validation int expiry period multiplier
generation-limit Generation int Consecutive generation limit. After a successful validation, this resets to zero
resend-interval Generation duration can re-send only after this duration of last send
validation-limit Validation int Consecutive validate limit when validate keeps failing. if a validates succeeds, this counter resets to zero
@bilal-fazlani
bilal-fazlani / build.sbt
Created November 27, 2023 04:34
set coursier bootstrap
import scala.sys.process._
lazy val bootstrap = taskKey[Unit]("Create a fat jar file")
bootstrap := {
// this first publishes the project to ivy local
publishLocal.value
val process = Process(
Seq(
"coursier",
@bilal-fazlani
bilal-fazlani / data.json
Created April 19, 2023 17:25
D3 chart for bi-directional connections
{
"types": [
"licensing",
"suit",
"resolved"
],
"nodes": [
{
"id": "Microsoft"
},
@bilal-fazlani
bilal-fazlani / zio-http.scala
Created December 20, 2022 16:13
zio-http-premetheus
import zio.http.*
import zio.http.service.*
import zio.metrics.connectors.prometheus.*
import zio.*
import zio.metrics.Metric
import zio.metrics.connectors.MetricsConfig
import zio.http.model.Method.GET
object Metrics extends ZIOAppDefault {
@bilal-fazlani
bilal-fazlani / -Main.scala
Created November 22, 2022 17:05
simple zio http server
import zio.http.*
import zio.http.service.*
import zio.*
object Main extends ZIOAppDefault {
private def portFromEnv: Option[Int] = sys.env.get("PORT").map(_.toInt)
val routes: Http[Any, Nothing, Request, Response] = Http.collectZIO[Request] { req =>
val delay = req.url.queryParams
@bilal-fazlani
bilal-fazlani / LeftRecursion.scala
Last active August 25, 2022 19:41
Eliminating left recursion using zio-parser
import zio.parser.Syntax._
import zio.Chunk
import zio.parser.Syntax
sealed trait IntegerExpression
case class IntegerValueExpression(value: Int) extends IntegerExpression {
override def toString: String = value.toString
}
@bilal-fazlani
bilal-fazlani / build.sbt
Created May 26, 2022 17:59
SBT - Reference local sbt project as dependency
lazy val other = ProjectRef(file("../../../my-other-project"), "otherSubProjectName")
lazy val myProject = project
.in(file("./my-project"))
.dependsOn(other)
@bilal-fazlani
bilal-fazlani / -zio-nio-streams-file-io.scala
Last active April 21, 2022 12:10
zio nio and streams file IO
object TestApp extends zio.ZIOAppDefault {
override def run = {
val filePath = "main.csv"
val program = for {
// read a csv file
lines <- ZStream
.fromFileName(filePath, 1024)
.via(ZPipeline.utfDecode)
.via(ZPipeline.splitLines)
@bilal-fazlani
bilal-fazlani / -ZIOConfigExamples.scala
Last active April 7, 2022 15:10
zio config examples with scala 3
import com.typesafe.config.Config
import zio.*
import zio.config.ConfigDescriptor.*
import zio.config.ConfigSource.*
import zio.config.*
import zio.config.magnolia.Descriptor
import zio.config.typesafe.TypesafeConfigSource
import zio.cli.Args
import java.time.ZonedDateTime
import java.time.LocalDate
@bilal-fazlani
bilal-fazlani / dashboard.js
Last active April 7, 2018 18:33
signalr-react-demo
import React from "react";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
import {loadEmployeesAsync} from "../reducers/employees";
import {Link} from "react-router-dom";
class Dashboard extends React.Component {
async componentWillMount(){
//loading data only first time