Skip to content

Instantly share code, notes, and snippets.

View OndraZizka's full-sized avatar
🍊

Ondrej Zizka OndraZizka

🍊
View GitHub Profile
@OndraZizka
OndraZizka / installMaven38.sh
Last active March 20, 2023 16:19
Linux: install Maven 3.8.6
#!/bin/bash
## Because Ubuntu 22.10 still has Maven 3.6.3, this fixes it:
wget -q https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz -P /tmp
mkdir ~/sw/
tar xf /tmp/apache-maven-*.tar.gz -C ~/sw/
rm /tmp/apache-maven-*.tar.gz
mv /sw/apache-maven-* -C ~/sw/maven
echo 'MAVEN_HOME=~/sw/maven' >> ~/.bashrc
@OndraZizka
OndraZizka / enumCliOptionParsing.kt
Created November 27, 2022 00:23
Kotlin: Parsing CLI options easily using ENUMs
private inline fun <reified T : OptionEnum> tryParseEnumOption(enumArgumentDefault: T, arg: String): T? {
val optionIntro = "--${enumArgumentDefault.optionName}"
if (!arg.startsWith(optionIntro))
return null
if (arg == optionIntro || arg == optionIntro + "=" + enumArgumentDefault.optionValue)
return enumArgumentDefault
val valueStr = arg.substringAfter(optionIntro).removePrefix("=")
@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 / apple-sceen-brightness-howto.sh
Created October 4, 2022 11:54
Apple screen brightness control script for Linux (Ubuntu)
##
## This is not a script, rather a sequence of commands to do.
## I have tested it and it works.
## Use at your own responsibility.
## Compiled from https://www.dionysopoulos.me/apple-display-brightness-controls-in-ubuntu-desktop.html
## See https://github.com/yhaenggi/acdcontrol.git for more info.
##
sudo apt-install g++ make
git clone https://github.com/yhaenggi/acdcontrol.git
@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 / 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 / find-duplicate-files.bash
Created May 17, 2016 00:56
Finds duplicate files. An alternative to `fdupes -r -S .`
find -type f -size +3M -print0 | while IFS= read -r -d '' i; do
#echo $i
echo -n '.'
if grep -q "$i" md5-partial.txt; then
echo -n ':'; #-e "\n$i ---- Already counted, skipping.";
continue;
fi
#md5sum "$i" >> md5.txt
MD5=`dd bs=1M count=1 if="$i" status=none | md5sum`
MD5=`echo $MD5 | cut -d' ' -f1`
@OndraZizka
OndraZizka / ClassUtils.ts
Created November 2, 2016 03:44
TypeScript class reflection tricks
class ClassUtils
{
/**
* This is intended to scan all TS classes that extend FrameModel.
* However there's no supported way to do it
* and the one used here may stop working in future TS versions.
* Therefore for now, let's rely on the generated DiscriminatorMappingData.ts.
*/
public static scanGlobalClasses() : { [key: string]: typeof FrameModel }
{
@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: