Skip to content

Instantly share code, notes, and snippets.

View stevebakh's full-sized avatar

Steven Bakhtiari stevebakh

  • Substrate Software Ltd
  • Manchester, UK
View GitHub Profile
@stevebakh
stevebakh / dontfeedthebeast.md
Created April 4, 2022 09:16 — forked from CumpsD/dontfeedthebeast.md
Don’t Feed the Beast – the Great Recruitment Agency Infestation

Don’t Feed the Beast – the Great Recruitment Agency Infestation

“Don’t move to that London” warned my northern grandfather once. “It’s full of spivs”.

The Oxford Dictionary (somewhat chauvinistically) defines a spiv as:

A man, typically a flashy dresser, who makes a living by disreputable dealings

“But I work in IT” I told him. “engineers aren’t like that”.

@stevebakh
stevebakh / zio-stream-sink-example.scala
Last active March 1, 2020 21:47
Example usage of zio-streams showing lazy evaluation and transformation.
import zio.console.{putStrLn, Console}
import zio.stream.{Stream, ZSink, ZStream}
import zio.{App, IO, ZIO}
object Main extends App {
val stream: ZStream[Console, Nothing, Int] = ZStream.unfoldM(1) { count =>
for {
_ <- putStrLn(s"create stream item: $count")
} yield if (count <= 10) Some(count -> (count + 1)) else None
@stevebakh
stevebakh / location-of-jar.scala
Created May 4, 2018 12:34
Find the filepath of the jar containing a particular class
// without instance:
classOf[SomeClass].getProtectionDomain.getCodeSource.getLocation.toURI.getPath
// with instance:
someClassInstance.getClass.getProtectionDomain.getCodeSource.getLocation.toURI.getPath
@stevebakh
stevebakh / module-dependency.sbt
Created May 1, 2018 09:43
Make one sbt module depend on a task in another module (example: one module depends on assembly in another)
lazy val firstmodule = ...
.settings(
assemblyJarName in assembly := "some.fat.jar",
assemblyOutputPath in assembly := file("secondmodule/lib") / (assemblyJarName in assembly).value)
lazy val secondmodule = ...
.settings(
test in IntegrationTest := (test in IntegrationTest).dependsOn(assembly in firstmodule).value)
@stevebakh
stevebakh / docker-ps-clean.sh
Created April 20, 2018 09:21
Formatting of `docker ps` output to strip ports - useful to set as an alias if mapping many ports produces large, wrapped output
docker ps --format "table{{.ID}}\t{{.Names}}\t{{.Image}}\t{{.RunningFor}}\t{{.Status}}"
@stevebakh
stevebakh / gcloud-datastore-emulator-in-docker.sh
Created April 19, 2018 14:04
Run Google Cloud Datastore emulator via the official docker image
docker run \
--rm \
-it \
-p 8099:8099 \
google/cloud-sdk \
gcloud beta emulators datastore start --project foobar --host-port 0.0.0.0:8099
@stevebakh
stevebakh / context-bound-example.scala
Created March 20, 2018 16:23
Just playing around with context bounds and implicit type classes. Shows the two forms that can be used to access the implicit typeclass.
trait A {
val name = "Aaaaay"
}
class B extends A
trait C[T <: A] {
def gofuckyourself(t: T): String
}
@stevebakh
stevebakh / CircuitBreaker.scala
Created March 7, 2018 09:49
Basic Monix example of a circuit-breaker used on a task.
import monix.eval.{Task, TaskCircuitBreaker}
import monix.execution.Scheduler.Implicits.global
import scala.concurrent.duration.DurationDouble
import scala.util.{Failure, Success}
object Main extends App {
private val task = Task {
val nr = util.Random.nextInt()
@stevebakh
stevebakh / generate-uuid.sh
Created March 6, 2018 09:10
Generate a UUID and convert to lower case
uuidgen | tr '[:upper:]' '[:lower:]'
@stevebakh
stevebakh / run-apache-bench.sh
Created March 6, 2018 09:05
Example command to run Apache Bench for a fixed period of time, emulating a browser.
ab \
-t 240 \
-n 100000 \
-k \
-c 5 \
-g ~/Desktop/ab.out \
-H "Accept: application/json, text/plain, */*" \
-H "Authorization: bearer $TOKEN" \
-H "Cache-Control: no-cache" \
-H "Accept-Encoding: gzip, deflate" \