Skip to content

Instantly share code, notes, and snippets.

View Amerousful's full-sized avatar

Pavel Bairov Amerousful

View GitHub Profile
@Amerousful
Amerousful / MultipleLevelFilter.scala
Created October 12, 2022 14:09
Scala, Logback Multiply Level Filter
class MultipleLevelFilter extends AbstractMatcherFilter[ILoggingEvent] {
private var levels: Set[Level] = _
def setLevels(levels: String): Unit = {
this.levels = levels.split('|').map(Level.toLevel(_, Level.OFF)).toSet
}
def getLevels = levels
@Amerousful
Amerousful / gatling-pass-scenario-variables.md
Last active October 20, 2025 14:47
Gatling: How to pass the session variables between two scenarios?

Gatling: How to pass the session variables between two scenarios?

I have a general solution which can easy to use. There are several steps how to do it.

Create methods which get all session variable from one scenario and another method which sets this variables:

import scala.collection.concurrent.{Map => ConcurrentMap}

def passAnotherSession(implicit transferVariable: ConcurrentMap[String, Any]): Expression[Session] =
@Amerousful
Amerousful / randomIPv6.scala
Created June 9, 2022 14:41
Scala, generate random IPv6
import java.util.concurrent.ThreadLocalRandom
val scope = (0 to 9) ++ ('a' to 'f')
def randomElement[T](seq: T*): T = {
seq(ThreadLocalRandom.current.nextInt(seq.size))
}
def generateIp: String = (1 to 32).foldLeft("") { (acc, _) =>
acc + randomElement(scope: _*)
@BigOokie
BigOokie / pgrep-regex-example.txt
Last active October 15, 2025 15:41
Use pgrep with regex patterns to identify specific processes and command line flags
Use the following pattern for `pgrep` to identify a running process that contains specific commandline parameters
Note the following pgrep options are needed:
-a, --list-full list PID and full command line
-f, --full use full process name to match
-c, --count count of matching processes
To find a specific process with a specific commandline parameter use the following:
pgrep -a -f "{processname}.*{commandline param}"
@tyb
tyb / print_map.java
Created July 22, 2019 09:47
Pretty-print a Map in Java
//as json
new Gson().toJson(map)
//as json
ObjectMapper mapper = new ObjectMapper();
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
//as json
Map<String, Object> stats = ...;
System.out.println(new JSONObject(stats).toString(2));
@dasgoll
dasgoll / gist:7b1a796d6e42cb66508bc504bb518f82
Created October 19, 2017 19:41
timeout command on MacOS
brew install coreutils
sudo ln -s /usr/local/bin/gtimeout /usr/local/bin/timeout
@frgomes
frgomes / scala_base64_encode_decode.scala
Created July 28, 2017 12:39
Scala - Base64 encode/decode
// Base64 encode
val text = "This is plaintext."
val bytesEncoded = java.util.Base64.getEncoder.encode(text.getBytes())
// Base64 decode
val textDecoded = new String(java.util.Base64.getDecoder.decode(bytesEncoded))
println(textDecoded)
@nikhita
nikhita / update-golang.md
Last active October 13, 2025 08:48
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@fancellu
fancellu / TryFlatten.scala
Created April 11, 2017 00:44
A few ways to flatten down a Seq[Try] to only Success values
import scala.util.{Success, Failure}
val seq=Seq(Success(1), Failure(new Exception("bang")), Success(2))
// all emit List(1, 2)
seq.map(_.toOption).flatten
seq.flatMap(_.toOption)
seq.filter(_.isSuccess).map(_.get)
seq.collect{case Success(x) => x}
@petitviolet
petitviolet / thread_local_random.md
Last active February 11, 2021 15:51
[Scala]ThreadLocalRandom is fast.

ThreadLocalRandom is faster than Random

val n = 100
Random.nextInt(n)
ThreadLocalRandom.current().nextInt(n)

why ThreadLocalRandom is faster