Skip to content

Instantly share code, notes, and snippets.

View dmlloyd's full-sized avatar
🪐

David M. Lloyd dmlloyd

🪐
  • Red Hat, Inc.
  • Planet X
View GitHub Profile
package io.quarkus.runtime.configuration;
import java.io.Serial;
import java.util.Iterator;
import java.util.Map;
import java.util.stream.Collectors;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.RelocateConfigSourceInterceptor;
@dmlloyd
dmlloyd / output.javap
Created December 21, 2022 15:17
The Naughty Class
Classfile /Users/david/tmp/bad-jar/org/eclipse/microprofile/config/inject/ConfigProperty.class
Last modified Dec 21, 2022; size 1290 bytes
SHA-256 checksum cfa585cf1e9b0107170de337edfd3e0805bac046d033693d14eecce51dea17a3
Compiled from "ConfigProperty.java"
public interface org.eclipse.microprofile.config.inject.ConfigProperty extends java.lang.annotation.Annotation
minor version: 0
major version: 52
flags: (0x2601) ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION
this_class: #1 // org/eclipse/microprofile/config/inject/ConfigProperty
super_class: #2 // java/lang/Object
@dmlloyd
dmlloyd / Scratch.java
Last active December 18, 2022 16:06
Git shortlog
import java.io.IOException;
import java.nio.charset.StandardCharsets;
class Scratch {
public static void main(String[] args) throws IOException {
ProcessBuilder pb = new ProcessBuilder("/usr/bin/git", "shortlog", "dhaskjfhdasjkdfhaskl");
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
pb.redirectError(ProcessBuilder.Redirect.PIPE);
pb.redirectInput(ProcessBuilder.Redirect.DISCARD.file());
Process process = pb.start();
@dmlloyd
dmlloyd / Scratch.java
Created December 2, 2022 17:24
Using a pager from Java
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
class Scratch {
// Pager example
public static void main(String[] args) {
Live value info layout; switch on # of leading zeros
┏━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┯━┓
┃F┊E┊D┊C┊B┊A┊9┊8┊7┊6┊5┊4┊3┊2┊1┊0┃ Bit#
┡━┿━┷━┷━┷━┷━┿━┿━┷━┷━┷━┷━┷━┷━┷━┷━┩
│1│ BaseReg │±┊ Signed offset │ Locate in memory
├─┴─┬───────┴─┴─────────────────┤
│0 1│ Bits, 1 per word │ References in memory
├───┴─┬─┬───────────────────────┤
│0 0 1│±┊ Signed offset │ Add to in-memory offset
@dmlloyd
dmlloyd / Transform.java
Created October 1, 2022 15:13
No good way to transform an immutable map
private static <K1, K2, V1, V2> Map<K2, V2> transform(Map<K1, V1> map, Function<K1, K2> keyTransform, Function<V1, V2> valueTransform) {
Iterator<Map.Entry<K1, V1>> iterator = map.entrySet().iterator();
if (! iterator.hasNext()) {
return Map.of();
}
Map.Entry<K1, V1> entry = iterator.next();
K2 k1 = keyTransform.apply(entry.getKey());
V2 v1 = valueTransform.apply(entry.getValue());
if (! iterator.hasNext()) {
return Map.of(k1, v1);
@dmlloyd
dmlloyd / output.javap
Created October 19, 2021 20:22
Why does javac do this?
public <T extends java.lang.Object> T[] toArray(T[]);
descriptor: ([Ljava/lang/Object;)[Ljava/lang/Object;
flags: (0x0001) ACC_PUBLIC
Code:
stack=2, locals=4, args_size=2
0: aload_0
1: getfield #21 // Field mutex:Ljava/lang/Object;
4: dup
5: astore_2
6: monitorenter
atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty
<...>
"The instruction can take an optional align attribute. The alignment must be a power of two greater or equal to the size of the <value> type. If unspecified, the alignment is assumed to be equal to the size of the ‘<value>’ type. Note that this default alignment assumption is different from the alignment used for the load/store instructions when align isn’t specified."
[
{
"name": "New Atari",
"author": "DML",
"switchMount": "cherry",
"switchBrand": "cherry",
"switchType": "MX1A-G1xx",
"pcb": true,
"css": ""
},
./build/linux-x86_64-normal-server-release/buildtools/gensrc/java.compiler.interim/module-info.java
./build/linux-x86_64-normal-server-release/buildtools/gensrc/jdk.compiler.interim/module-info.java
./build/linux-x86_64-normal-server-release/buildtools/gensrc/jdk.javadoc.interim/module-info.java
./build/linux-x86_64-normal-server-release/buildtools/gensrc/jdk.rmic.interim/module-info.java
./build/linux-x86_64-normal-server-release/support/gensrc/java.logging/sun/util/logging/resources/logging.java
./build/linux-x86_64-normal-server-release/support/gensrc/java.logging/sun/util/logging/resources/logging_it.java
./build/linux-x86_64-normal-server-release/support/gensrc/java.logging/sun/util/logging/resources/logging_pt_BR.java
./build/linux-x86_64-normal-server-release/support/gensrc/java.logging/sun/util/logging/resources/logging_zh_CN.java
./build/linux-x86_64-normal-server-release/support/gensrc/java.logging/sun/util/logging/resources/logging_fr.java
./build/linux-x86_64-normal-server-release/support/gensrc/j