Skip to content

Instantly share code, notes, and snippets.

@dmikurube
dmikurube / LoadedClassFinder.java
Last active September 13, 2024 06:54
ClassLoader.findLoadedClass
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
class LoadedClassFinder extends ClassLoader {
static synchronized Class<?> findFrom(final ClassLoader classLoader, final String name) {
final Method findLoadedClass;
try {
findLoadedClass = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
} catch (final NoSuchMethodException ex) {
throw new RuntimeException(ex);
@dmikurube
dmikurube / DayOfQuarter.java
Last active April 20, 2024 15:35
DateTimeFormatter
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.IsoFields;
import java.time.temporal.Temporal;
@dmikurube
dmikurube / convert_flac_m4a.py
Last active February 3, 2024 11:31
Convert FLAC to m4a (ALAC)
#!/usr/bin/env python3
from pathlib import Path
import os
import subprocess
import sys
def main(argv):
if len(argv) < 3:
@dmikurube
dmikurube / CoroutineExceptionHandlerLogging.kt
Last active February 13, 2023 07:59
Exception handling with logging in Kotlin coroutines
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.slf4j.MDCContext
import mu.KotlinLogging
@dmikurube
dmikurube / Main.kt
Last active February 11, 2023 06:28
fun main() {
println("Hello!")
}
@dmikurube
dmikurube / Main.java
Last active January 31, 2023 12:57
NoClassDefFoundError
public class Main {
public static void main(final String[] args) {
System.out.println("#1");
Sub.safe();
Sub.unsafe1(null);
Sub.unsafe2(null);
Sub.unsafe3(null);
Sub.unsafe4(null);
System.out.println("#2");
}
@dmikurube
dmikurube / TryGraalOnStockJvm.java
Last active September 13, 2022 08:58
Try Graal on Stock JVM
import org.graalvm.polyglot.Context;
public class TryGraalOnStockJvm {
public static void main(final String[] args) {
final Context context = Context.newBuilder().logHandler(System.err).build();
context.eval("js", "print('Hello, GraalJS!');");
}
}
import java.util.function.Consumer;
final class RuntimeExceptionStacker {
RuntimeExceptionStacker() {
this.exception = null;
}
synchronized RuntimeExceptionStacker add(final RuntimeException ex) {
if (this.exception == null) {
this.exception = ex;
#!/usr/bin/env python3
import subprocess
import sys
EMAIL_REPLACE = {
"[email protected]": "[email protected]"
}
#!/usr/bin/env python3
import subprocess
import sys
def git_author_date(commit):
return subprocess.check_output(['git', 'show', '--format=%aD', '--no-patch', commit]).decode("utf-8").strip()