Skip to content

Instantly share code, notes, and snippets.

View OndraZizka's full-sized avatar
🍊

Ondrej Zizka OndraZizka

🍊
View GitHub Profile
@OndraZizka
OndraZizka / OptionsParsingUtils.kt
Last active November 22, 2022 14:11
Kotlin: Parsing of enum-based application linux-like arguments (--name[=value])
object OptionsParsingUtils {
private inline fun <reified T : OptionEnum> tryParseEnumOption(enumArgumentDefault: T, arg: String): T? {
val optionIntro = "--${enumArgumentDefault.optionName}"
if (!arg.startsWith(optionIntro))
return null
if (arg.endsWith(optionIntro) || arg.endsWith("=${enumArgumentDefault.optionValue}"))
return enumArgumentDefault
@OndraZizka
OndraZizka / FlexibleTemporalInputParser.kt
Last active October 30, 2021 09:05
Parse various date-time formats: Year only to full LocalDateTime, or relative from now (to the past). Kotlin.
package ch.zizka.time
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
import java.time.temporal.ChronoField.DAY_OF_MONTH
import java.time.temporal.ChronoField.HOUR_OF_DAY
import java.time.temporal.ChronoField.MINUTE_OF_HOUR
import java.time.temporal.ChronoField.MONTH_OF_YEAR
@OndraZizka
OndraZizka / git-moveBranch.sh
Last active September 8, 2023 10:41
Git: Rebase a (sub)branch from one base to another, leaving the other base's commits.
#!/bin/bash
## Places a branch to a new base.
## Useful when splitting a long branch to multiple pull requests.
##
## ---+--------master
## \
## --- A ---- B
##
## git-moveBranch.sh B from A to master
@OndraZizka
OndraZizka / parseCommaDelimitedMap.kt
Created July 8, 2020 11:49
Parser - Map from comma separated pairs, in Kotlin
fun parseCommaDelimitedMap(str: String): Map<String, String> {
if (str == null) return null
val pairs = str.split(',').map { it.trim() }.filter { it.contains(':') }
.map {
val parts = it.split(':', limit = 2)
Pair(parts[0], parts[1])
}
.associate { it }
return pairs
@OndraZizka
OndraZizka / switch.sh
Created April 10, 2020 20:17
Switch - simple linux alternative to Alternatives. Switches between versions of apps.
#####################################################################################################
#
# This script creates switches between the versions of various tools,
# found in /mnt/jqa/sw/tools/ (curently hard-coded).
#
# Usage:
# $ switch maven 2.1.0
# $ mvn ...
#
# Installation:
@OndraZizka
OndraZizka / LogTransformer.java
Last active October 18, 2019 01:04
LogTransformer (fixes the scrabled log)
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
<!--
Tutorial code for: http://www.binpress.com/tutorial/generating-nice-movie-previews-with-ffmpeg/138
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
</head>
<body>
<a href="https://www.youtube.com/watch?v=v1uyQZNg2vE" target="_blank" class="video-preview" data-frames="100" data-source="http://i.imgur.com/BX0pV4J.jpg"></a>
@OndraZizka
OndraZizka / CSI-2-picamera.py
Last active August 3, 2022 01:41
OpenCV, Python, camera, Raspberry Pi
# sudo apt-get install python-picamera
import picamera
from time import sleep
camera = picamera.PiCamera()
camera.capture('image.jpg')
camera.start_preview()
camera.vflip = True
camera.hflip = True
@OndraZizka
OndraZizka / GatlingMavenPluginDocs.md
Last active May 11, 2018 16:11
Gatling Maven plugin documentation (gatling-maven-plugin)

Gatling Maven plugin docs

Since the official Gatling Maven plugin page is missing more info than it contains, here's the output of $ mvn gatling:help -Ddetail=true -Dgoal=test:

gatling:test

Available parameters:

  • bodiesFolder (Default: ${project.basedir}/src/test/resources/bodies)
@OndraZizka
OndraZizka / MavenPomManagement.md
Last active April 16, 2018 12:09
Maven POM management guidelines

To keep the POMs (project object models) sane and maintainable, here's my suggestion of a few simple rules.
As with many other things in development - a bit more work for whoever does the changes that will save a lot of work to future maintainers.

  • Define dependency versions in <dependencyManagement>.
  • If there are multiple dependencies from one project, define the version in properties.
    • Version properties are named version.{artifactId}.
  • If you exclude a transitive dependency, write a comment why.
  • Group dependencies by their purpose and origin:
    • Test deps, platform deps (Dropwizard), In-house deps (CSL), project deps (that is, other modules of the same project).
  • Don't clutter the pom.xml with explicitely stating the defaults, e.g. jar or ../pom.xml.