Skip to content

Instantly share code, notes, and snippets.

View darekmydlarz's full-sized avatar
👨‍💻
Senior Software Engineer

Dariusz Mydlarz darekmydlarz

👨‍💻
Senior Software Engineer
View GitHub Profile
@darekmydlarz
darekmydlarz / BenchmarksFrequentReads.java
Last active February 13, 2019 08:39
LongAdder Benchmarks
public class Benchmarks {
private static int LOOPS = 1_000;
@Benchmark
@Fork(value = 1, warmups = 2)
@GroupThreads(100)
public void atomicLong(Counters counters, Blackhole blackhole) {
for (int i = 0; i < LOOPS; ++i) {
blackhole.consume(counters.atomicCounter.incrementAndGet());
}
@darekmydlarz
darekmydlarz / kafka-tools.md
Last active November 7, 2018 09:17
Kafka Tools

How to read Kafka Consumer Group Offset

  • Install Kafka Tools in a specific version - e.g. Scala 2.12, Version 1.1.0 - link
  • List consumer groups, Kafka address: localhost:9092:
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
  • List topic offsets for group console-consumer-96905:
@darekmydlarz
darekmydlarz / roop.scala
Created August 13, 2018 07:53
ROOP - radical object oriented programming - fetching data from jdbc
// before
case class Query(table: String, orderKey: String, whereClause: Option[String] = None) {
def fetchQuery(): String = {
Seq(
s"SELECT * FROM $table",
whereClause.map(w => s"WHERE $w").getOrElse(""),
s"ORDER BY $orderKey ASC"
).mkString
}
@darekmydlarz
darekmydlarz / mysql.md
Last active August 8, 2018 07:43
Docker Commands

Start MySQL in a docker with volume mounted on the host and initial scripts

${PWD}/docker-entrypoint-initdb.d - contains initial scripts to be loaded on MySql startup

docker run --name mysql-1 \
    -itd -e MYSQL_ROOT_PASSWORD=password  \
    -e MYSQL_DATABASE:affiliate_dev \
    -p 127.0.0.1:3306:3306  \
 -v /Users/darek/docker/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d mysql:5.7.19
@darekmydlarz
darekmydlarz / dbunit-jsonb.md
Last active May 14, 2021 16:08
DbUnit - handle postgres JSONB in tests

Problem

I have entity with jsonb column type.

public class Copy {
    private Long id;

    @Column(columnDefinition = "jsonb")
 private String content;
@darekmydlarz
darekmydlarz / decorator-vs-imperative.java
Created January 3, 2018 14:33
Decorator vs Imperative
Image image = new RotatedImage( // just a regular declaration
CLOCKWISE,
90,
new GrayScaledImage(
new CachedImage(
"//cdn.google.com/logos/apple.png",
new RemoteImage("//cdn.google.com/logos/apple.png")
)
)
);
@darekmydlarz
darekmydlarz / sole-oop.java
Created December 14, 2017 10:20
What the OOP is about?
// procedular programming
@Value
class IdProvider {
private final String id;
private final String email;
// getters
}
package com.getbase.services.reach.api.dtos.request;
/**
* Put quotes around the given String if necessary.
* <p>
* If the argument doesn't include spaces or quotes, return it as is. If it
* contains double quotes, use single quotes - else surround the argument by
* double quotes.
* </p>
* <p>
@darekmydlarz
darekmydlarz / TicTacToe.java
Last active October 20, 2017 07:37
OOP Tic Tac Toe Draft - based on Elegant Objects by @yegor256
interface Board {
Board movement(Movement movement);
Player winner();
}
public static void main() {
Player black = new Player("Black");
Player white = new Player("White");
Board board = new Board(black, white);
Movement movement = new Movement(black, board).position();
@darekmydlarz
darekmydlarz / server.py
Created September 21, 2017 12:48 — forked from raelmax/server.py
Python SimpleHTTPServer com sleep
import SimpleHTTPServer
import SocketServer
from time import sleep
PORT = 5000
SLEEP_TIME = 6
class SlowHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):