Skip to content

Instantly share code, notes, and snippets.

View peter-lawrey's full-sized avatar

Peter Lawrey peter-lawrey

View GitHub Profile
package when;
public class When {
static class when {
boolean when = true;
}
@interface whėn {
String value();
}
/*\u002a\u002f\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u004d\u0061\u0069\u006e\u0020\u007b\u0020\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u002e\u002e\u002e\u0020\u0061\u0029\u0020\u007b\u000a
String s= "*/public class Main { " +
"public static void main(String... a) {\n" +
"//\n" +
"} " +
"} /*";
for (char c : s.toCharArray()) {
System.out.printf("\\u%04x", (int) c);
}
//\u000a\u007d\u0020\u007d\u0020\u002f\u002a */
@peter-lawrey
peter-lawrey / Main.java
Created May 24, 2019 08:22
If the Predicate is defined inside Never, this program never completes.
import java.util.List;
import java.util.function.Predicate;
public class Main {
static final Predicate<String> test = s -> s.length() > 6;
static class Never {
// static final Predicate<String> test = s -> s.length() > 6;
static final List<String> fruit = List.of(
"Apples", "Bananas", "Pears",
public class MemoryCopy {
private static final Unsafe UNSAFE;
static {
Unsafe unsafe = null;
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
unsafe = (Unsafe) theUnsafe.get(null);
} catch (Exception ex) {
public class PingPongMain {
public static void main(String[] args) throws InterruptedException {
new Thread(() -> {
try {
synchronized ("bb") {
while (true) {
"bb".wait();
"bb".notifyAll();
System.out.println("b");
}
@peter-lawrey
peter-lawrey / A.java
Last active August 29, 2015 14:14
A program without class
/*
In Java 8 this program prints
java.lang.Throwable
at A.printStackTrace(A.java:8)
at A.<clinit>(A.java:5)
at java.lang.Class.forName0(Native Method)
Note: <clinit> is the static initializer method for interface A
*/
public static void main(String[] args) {
Stream.of(Boolean.class, Byte.class, Character.class, Short.class, Integer.class,
Long.class, Float.class, Double.class, Void.class).map(c -> {
try {
return c.getField("TYPE").get(null);
} catch (Exception e) {
throw new AssertionError(e);
}
}).forEach(System.out::println);
}
Index: src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f)
+++ src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java (revision )
@@ -118,7 +118,7 @@
for (l = 0; l < achunksection.length; ++l) {
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) {
package com.higherfrequencytrading.chronicle.example;
import com.higherfrequencytrading.chronicle.Chronicle;
import com.higherfrequencytrading.chronicle.Excerpt;
import com.higherfrequencytrading.chronicle.impl.IndexedChronicle;
import com.higherfrequencytrading.chronicle.tools.ChronicleTools;
/**
* @author Julien Eluard
* @author peter.lawrey
@peter-lawrey
peter-lawrey / gist:4442523
Created January 3, 2013 10:40
A horrible hack to change a String.
import java.lang.reflect.Field;
class MainClass {
// requires Java 7 update 5+
static {
try {
Field value = String.class.getDeclaredField("value");
value.setAccessible(true);
value.set("B", value.get("ABC"));
} catch (Throwable e) {