Skip to content

Instantly share code, notes, and snippets.

View nachinius's full-sized avatar
🐻
Working...

nachinius nachinius

🐻
Working...
  • Berlin, DE
View GitHub Profile
@nachinius
nachinius / build.sbt
Created August 8, 2024 08:23
Initial
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.14"
lazy val root = (project in file("."))
.settings(
name := "tools",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.5.0",
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "5.1.2",
// fs2: functional streams for Scala
@nachinius
nachinius / Dependencies.scala
Created May 12, 2020 06:48
Dependencies file for scala
import sbt._
object Dependencies {
object Versions {
val cats = "2.1.1"
val catsEffect = "2.1.2"
val catsMeowMtl = "0.4.0"
val catsRetry = "1.1.0"
val circe = "0.13.0"
@nachinius
nachinius / sleep5.sh
Created April 29, 2020 12:41 — forked from ignaciopeixoto/sleep5.sh
A shell one-liner for an infinite loop (sh/zsh/bash compatible)
while true; do date; sleep 5; done
import cats.{ ApplicativeError, MonadError }
import cats.data.{ Kleisli, OptionT }
import cats.effect.Sync
import cats.effect.concurrent.Ref
import cats.syntax.all._
import io.circe.generic.auto._
import io.circe.syntax._
import org.http4s._
import org.http4s.circe.CirceEntityDecoder._
import org.http4s.circe._
@nachinius
nachinius / binderBigDecimal.scala
Created October 11, 2019 20:19
play binder for BigDecimal
// in buid.sbt """routesImport ++= Seq("com.nachinius.controllers.Binders._" """
package com.nachinius.controllers
object Binders {
implicit def BigDecimalQueryStringBindable = new QueryStringBindable[BigDecimal] {
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, BigDecimal]] = {
params.get(key).flatMap(_.headOption).map { value =>
Try { BigDecimal(value) } match {
case Success(value) => Right(value)
case Failure(exception) => Left(exception.getMessage)
@nachinius
nachinius / nem_hex_to_base_32.sc
Last active April 15, 2019 15:54
scala hex to base32. Finding the prefix for addresses in NEM crypto
#!/usr/bin/env amm
import $ivy.`org.apache.hadoop:hadoop-common:3.2.0`, org.apache.commons.codec.binary.Base32
// HexBytesUtil from https://gist.githubusercontent.com/tmyymmt/3721117/raw/70af27f30df0ec0084e37e7fe3ff0a547bf8020b/HexBytesUtil.scala
object HexBytesUtil {
def hex2bytes(hex: String): Array[Byte] = {
if(hex.contains(" ")){
hex.split(" ").map(Integer.parseInt(_, 16).toByte)
} else if(hex.contains("-")){
@nachinius
nachinius / tempFlowSinkSource
Created April 10, 2019 01:31
// Utilities to temporarily have unimplemented parts of the program
from reactive programms edx course
// Utilities to temporarily have unimplemented parts of the program
private def unimplementedFlow[A, B, C]: Flow[A, B, C] =
Flow.fromFunction[A, B](_ => ???).mapMaterializedValue(_ => ??? : C)
private def unimplementedSink[A, B]: Sink[A, B] = Sink.ignore.mapMaterializedValue(_ => ??? : B)
@nachinius
nachinius / gist:bd361d465d726c2a350b5932a2138e76
Last active March 14, 2019 17:51
Execute a future in a seq, and recovered result (not stack safe)
type A[E,T] = (E, Try[T])
def seqOfFuturesRecovered[T, E](elems: Seq[E])(func: E => Future[T])(implicit executionContext: ExecutionContext): Future[Seq[A[E,T]]] = {
elems.foldLeft(Future(Seq.empty[A[E, T]])) { (acc, elem) =>
acc.flatMap { prevSeq: Seq[(E, Try[T])] =>
FutureOps(func(elem)).futureToTry.map( (elem, _)).map { prevSeq :+ _}
}
}
}
@nachinius
nachinius / FutureUtils
Last active February 21, 2019 14:03
Scala Futures: a) serialized (one after the other, and stop on failures), b) with timeout, c) retry with delay
import java.util.concurrent.TimeoutException
import java.util.{Timer, TimerTask}
import play.api.Logger
import scala.collection.generic.CanBuildFrom
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.{Failure, Random, Success}
object FutureUtils {
pragma solidity 0.5.2;
contract Contract_C {
address payable [5] public target = [address(0), address(0),address(0),address(0),address(0)];
uint8 public max = 5;
uint public amountToPaid = 1;
event Sent(address destination, uint amount);