Skip to content

Instantly share code, notes, and snippets.

View novakov-alexey-zz's full-sized avatar
🎸
FP user

Alexey Novakov novakov-alexey-zz

🎸
FP user
View GitHub Profile
@Daenyth
Daenyth / StreamRetry.scala
Last active December 11, 2022 21:31
fs2 Stream 1.x / Simple example of retry with logging
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] = ???
@antonfisher
antonfisher / allow-privileged-for-microk8s.md
Last active September 24, 2021 09:53
MicroK8s add --allow-privileged=true flag

Add --allow-privileged=true to:

# kubelet config
sudo vim /var/snap/microk8s/current/args/kubelet

#kube-apiserver config
sudo vim /var/snap/microk8s/current/args/kube-apiserver

Restart services:

@frgomes
frgomes / pattern_matching_on_runtimeClass.scala
Last active May 16, 2023 18:12
Scala - Pattern matching on a runtime class employing ClassTag and stable identifiers
import com.typesafe.config.Config
implicit class ImplicitConfigHelper(val c: Option[Config]) extends AnyVal {
import scala.reflect.ClassTag
import scala.util.control.NonFatal
import ImplicitConfigHelper._
implicit def valueOf[T : ClassTag](prop: String)(implicit ev: ClassTag[T]) : T =
ev.runtimeClass match { // you need stable identifiers here
case String_ => c.get.getString(prop).asInstanceOf[T]
case Int_ => c.get.getInt(prop).asInstanceOf[T]
@anair-it
anair-it / Spring Chained Tx Management.md
Last active June 7, 2024 06:38
Best efforts 1Phase Commit using Spring chained transaction managemer and Apache Camel

Best efforts 1 Phase commit

This is a non-XA pattern that involves a synchronized single-phase commit of a number of resources. Because the 2PC is not used, it can never be as safe as an XA transaction, but is often good enough if the participants are aware of the compromises. The basic idea is to delay the commit of all resources as late as possible in a transaction so that the only thing that can go wrong is an infrastructure failure (not a business-processing error). Systems that rely on Best Efforts 1PC reason that infrastructure failures are rare enough that they can afford to take the risk in return for higher throughput. If business-processing services are also designed to be idempotent, then little can go wrong in practice.

Scenarios

Consider a jms based service, where there is an inbound Queue manager (QM1), an outbound queue manager (QM2) and a database (DB). Here are the scenarios that I would like to cover using Best efforts 1 PC commit process:

Happy path

  1. Start MQ transaction on QM1 2
@johanandren
johanandren / SimplePartitionSample.scala
Created July 26, 2016 08:25
Sample of using partition to split up incoming elements over multiple outgoing streams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import scala.io.StdIn
import scala.util.Random
object SimplePartitionSample extends App {
implicit val system = ActorSystem()
@brunogaspar
brunogaspar / README.md
Last active October 7, 2022 09:08
Install wkhtmltopdf on Ubuntu (14.04 64-bit) or (16.04 64-bit)

Install wkhtmltopdf on Ubuntu

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64

Installation

@tobilg
tobilg / custom_s3_endpoint_in_spark.md
Last active July 31, 2024 10:22
Description on how to use a custom S3 endpoint (like Rados Gateway for Ceph)

Custom S3 endpoints with Spark

To be able to use custom endpoints with the latest Spark distribution, one needs to add an external package (hadoop-aws). Then, custum endpoints can be configured according to docs.

Use the hadoop-aws package

bin/spark-shell --packages org.apache.hadoop:hadoop-aws:2.7.2

SparkContext configuration

@mnn
mnn / install.sh
Last active May 17, 2017 14:01
Ammonite REPL installation with MinGW
mkdir -p ~/.ammonite && wget -O ~/.ammonite/predef.scala --no-check-certificate https://git.io/v6r5y
wget -O amm --no-check-certificate https://git.io/vioDM && chmod u+x amm && ./amm
@gigiigig
gigiigig / auxpattern.scala
Last active January 8, 2025 00:31
Aux Pattern
import shapeless._
import scalaz._
import Scalaz._
object console extends App {
trait Foo[A] {
type B
def value: B
import java.security.MessageDigest
import java.util
import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec
import org.apache.commons.codec.binary.Base64
/**
* Sample:
* {{{
* scala> val key = "My very own, very private key here!"