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
@afsalthaj
afsalthaj / standardised_rust_conversion.rs
Created April 25, 2024 03:03
AssociatedTypes In Rust
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::cmp::PartialOrd;
use crate::internal_types::AI;
trait Conversion: Debug + Clone {
type WitType: Clone + Debug;
fn from_wit_type(input: Self::WitType) -> Result<Self, String>;
fn to_wit_type(&self) -> Result<Self::WitType, String>;
sealed trait Tree
case class Bin(x: Tree, y: Tree) extends Tree
case class Lt(in: Int) extends Tree
/**
* Infinite recursion - duplicate all binary values
*/
def topddown_duplicate_bins(tree: Tree): Tree = tree match {
case Bin(x, y) =>
package metrics
import java.sql.ResultSet
/**
* A highly simplified functional jdbc with no dependencies.
* Serves the purpose for the time being. Currently returns scala.Stream.
*/
object myjdbc {
trait Primitive[A] {
trait OptionSyntax {
implicit class OptionOps[A](s: Option[A]) {
def ifExists[F[_], B](f: A => F[B]): PartialOption[F, B] =
s match {
case Some(value) => new PartialOption(Some(f(value)))
case None => new PartialOption(None)
}
}
}
package com..s3paths
import cats.free.Cofree
import com.s3paths.nonfree.Component.Version
import com.s3paths.nonfree.Component.RunTime
import com.s3paths.nonfree.Component.Adhoc
import cats.Traverse
import cats.Eval
// Well we need name and pos
import cats.Id
// MANAGING/COMBINING MULTIPLE SOURCES, DIFFERENT KEYS IN EACH SOURCES etc IN ZIO-CONFIG
// .. A follow up on the questions during FS2020
final case class Config(username: String, age: Int)
// Same as val configSpec = magnolia.descriptor[Config]
val configSpec: ConfigDescriptor[Config] =
(string("username") |@| int("age"))(Config.apply, Config.unapply)
val configPgm1: ConfigDescriptor[Config] =
package zio.config.examples
import java.lang.{ Boolean => JBoolean }
import scala.util.{ Failure, Success, Try }
import com.typesafe.config._
import zio.config.typesafe._
import zio.{ IO }
import zio.config._, ConfigDescriptor._
/**
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
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)
)
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]