This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with scala-cli httpserver.scala | |
// Save logback.xml file into ./resources dir | |
// Before generating native image binary, run first as above and make a real access to the URL | |
// so the native-image-agent can generate the metadata in ./resources dir. | |
// Then generate native image binary with: scala-cli package --native-image httpserver.scala | |
//> using scala "3.3.0" | |
//> using lib "dev.zio::zio:2.0.15" | |
//> using lib "dev.zio::zio-http:3.0.0-RC2" | |
//> using lib "dev.zio::zio-logging-slf4j2::2.1.13" | |
//> using lib "ch.qos.logback:logback-classic:1.4.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sillio | |
import cats.syntax.all._ | |
import scala.annotation.tailrec | |
import scala.concurrent.ExecutionContext | |
import scala.util.control.NonFatal | |
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.OutputStream; | |
import java.util.ArrayList; | |
import java.util.List; | |
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.model.AbortMultipartUploadRequest; | |
import com.amazonaws.services.s3.model.CannedAccessControlList; | |
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest; | |
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** An effect for infinitely repeating an action, use with care | |
* as there is no way to kill the process w/o shutting down the | |
* server in this implementation */ | |
trait RepeatEval[F[_]] { | |
def repeat[A](fa: F[A], duration: FiniteDuration): F[Unit] | |
} | |
object RepeatEval { | |
def apply[F[_]](implicit ev: RepeatEval[F]): RepeatEval[F] = ev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Eq | |
import cats.effect.{ContextShift, IO, Timer} | |
import org.scalactic.Prettifier | |
import org.scalactic.source.Position | |
import org.scalatest.exceptions.TestFailedException | |
import org.scalatest.{Assertion, AsyncTestSuite} | |
import scala.concurrent.Future | |
import scala.concurrent.duration._ | |
import scala.reflect.ClassTag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Alternative to sealed abstract case class pattern for Scala 2.12.2+ | |
// Benefits: | |
// - 1 final class instead of 1 sealed class + anonymous subclass | |
// - portable to Scala 3 regardless of opaque types | |
// - less boilerplate | |
final case class Angle private (toDegrees: Int) { | |
// Define our own `copy` method to suppress synthetic one | |
// Add private to prevent it from being used | |
def copy(degrees: Int = toDegrees): Angle = Angle.fromDegrees(degrees) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.Sync | |
import io.chrisdavenport.log4cats.Logger | |
import cats._ | |
import cats.implicits._ | |
import scala.concurrent.duration._ | |
class RetryExample[F[_]](implicit F: Sync[F], log: Logger[F]) { | |
case class ApiError(msg: String) extends Exception(msg) | |
private def getTempFromInternet: EitherT[F, ApiError, Float] = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.OutputStream | |
import java.util.concurrent.Executors | |
import cats.effect.{Async, Effect, IO, Timer} | |
import cats.implicits._ | |
import fs2.async.mutable.Queue | |
import fs2.{Chunk, Stream} | |
import scala.annotation.tailrec | |
import scala.concurrent.{ExecutionContext, SyncVar} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prerequisite : Public Key Setup is required for using this setup | |
1. First open ~/.ssh/config file and add these lines filling the appropriate details. | |
This will setup a netcat tunnel through jump server which will forward all your traffic to mail machine. | |
``` | |
Host <HOSTNAME> | |
User <USERNAME> | |
HostName <HOSTNAME> | |
ProxyCommand ssh <JUMPSERVER-USER>@<JUMPSERVER-ADDR> nc %h %p 2> /dev/null | |
``` | |
2. ssh -v -D :port: :username:@:hostname: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
import shapeless.labelled.FieldType | |
import shapeless.record._ | |
trait GenericDiff[H <: HList] { | |
// syntactic sugar | |
type HI = H | |
// compares field values and returns the field name with values if they differ |
NewerOlder