Skip to content

Instantly share code, notes, and snippets.

@baybatu
baybatu / run-kibana.sh
Last active June 12, 2019 08:28
Run Kibana for parameterized Elasticsearch. Kudos @mesut
#!/bin/bash
# USAGE: run-kibana.sh http://localhost:9200
echo "Running kibana for es host:$1"
docker run --name kibana -d -p 5601:5601 \
-e ELASTICSEARCH_HOSTS=$1 \
-e XPACK_GRAPH_ENABLED=false \
-e XPACK_ML_ENABLED=false \
@ufuk
ufuk / posgresql-lightspeed-alter-table.sql
Last active November 5, 2018 07:59
Increase performance of alter tables or any other expensive operations by increasing WORK_MEM parameter for current session in PostgreSQL
BEGIN;
LOCK TABLE ... IN SHARE MODE;
SET LOCAL WORK_MEM = '256MB';
ALTER TABLE ...;
COMMIT;
@ufuk
ufuk / TurkishNumberUtils.java
Last active November 13, 2020 07:55
Util for converting whole numbers to Turkish words
public final class TurkishNumberUtils {
private static final String SPACE = " ";
private static final String EMPTY = "";
private static final String[] PERIOD_NAMES = {EMPTY, "bin", "milyon", "milyar", "trilyon", "katrilyon", "kentilyon"};
private static final String[] UNITS_TEXTS = {EMPTY, "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"};
@baybatu
baybatu / mockito-deep-stubs.md
Last active September 21, 2020 07:48
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);
@baybatu
baybatu / MockFinalClass.java
Last active June 9, 2018 11:57
Mocking final class in Java with PowerMockito
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyFinalClass.class)
public class MyFinalClassTest {
@baybatu
baybatu / ZonedDateTimeAsUTC.java
Last active February 15, 2022 08:37
Setting zoned date time as UTC in a new java.util.Date object
/*
*
* Methods manipulate milliseconds field (fastTime) in java.util.Date object.
*
* UTC : 12/10/2017 11:15:00
* Local date time : 12/10/2017 14:15:00 +03:00
*
* @return new java.util.Date
* UTC : 12/10/2017 14:15:00
* Local date time : 12/10/2017 17:15:00 +03:00
@baybatu
baybatu / IsJVMOnDebugMode.java
Created October 12, 2017 05:33
getting info on whether JVM started in debug mode.
/**
*
* -----------------------------------------------------------------------------------
* From : org.junit.rules.DisableOnDebug#isDebugging(java.util.List<java.lang.String>)
* -----------------------------------------------------------------------------------
*
* Parses arguments passed to the runtime environment for debug flags
* <p>
* Options specified in:
* <ul>
@ufuk
ufuk / ComparingUtils.java
Last active September 2, 2020 13:41
Fluent API for comparing two Comparables.
public class ComparingUtils {
public static <T extends Comparable<T>> ComparisonBuilder<T> is(T comparable) {
return new ComparisonBuilder<>(comparable);
}
public static class ComparisonBuilder<T> {
private Comparable<T> subject;
@ufuk
ufuk / LazyDeveloper.java
Last active June 27, 2019 13:04
Just another reason to why you shouldn't use Lombok, in another saying another reason to why you should write unit tests: You have two fields in your class. Fields are in the same type. You use @AllArgsConstructor to auto-generate your all args constructor. It works for a moment, until you change the order of the field.
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class LazyDeveloper {
private String firstName;
private String lastName;
@staltz
staltz / introrx.md
Last active May 10, 2024 12:08
The introduction to Reactive Programming you've been missing