Skip to content

Instantly share code, notes, and snippets.

@claudemartin
claudemartin / SomeClass.java
Last active August 29, 2015 14:25 — forked from anonymous/SomeClass.java
game loop that can bepaused / stopped, now using a Lock.
package com.example.foo;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class SomeClass {
public static void main(final String[] args) {
final Thread thread = new Thread(SomeClass::gameLoop);
@claudemartin
claudemartin / AnimationLoop.java
Last active August 29, 2015 14:25
A very simple animation loop that can be paused and stopped.
/****************************
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Claude Martin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#include <stdio.h>
#define MSGSIZE 16
char *msg1 = “hello, world #1”;
char *msg2 =“ hello, world #2”;
char *msg3 =“ hello, world #3”;
main () {
char inbuf[MSGSIZE];
int p[2], j, pid;
package ch.claude_martin.playground;
import java.io.IOException;
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
public final class Child {
private final Object token;
private final SomeClass parent;
Child(SomeClass parent, Object token) {
this.parent = parent;
this.token = token;
}
public void doStuff() {
@claudemartin
claudemartin / .java
Last active February 8, 2018 22:49 — forked from kaecy/.java
public static void main(String args[]) {
String str = "abc";
byte[] cstr = str.getBytes();
cstr[0] = 'b';
System.out.println(new String(cstr));
System.out.println(str); // still "abc" -> it has not changed
}
@claudemartin
claudemartin / Main.java
Created April 24, 2018 21:54
Configurable bit position per enum [Example]
package ch.claude_martin.enumbitset;
import static java.util.Arrays.asList;
import java.util.stream.Collectors;
public class Main {
enum Bla implements EnumBitSetHelper<Bla> {
A(-1), B(42), C(108);
@claudemartin
claudemartin / YComb.java
Created October 13, 2017 22:33
Y combinator in Java 8
package ch.claude_martin;
import java.util.function.Function;
import java.util.function.UnaryOperator;
public class YComb {
interface Fn2Op<T> extends Function<Fn2Op<T>, UnaryOperator<T>> {
@Override
UnaryOperator<T> apply(Fn2Op<T> x);
@claudemartin
claudemartin / WeakAssQueue.java
Last active October 10, 2019 15:20
WeakAssQueue allows you to let the GC remove the tail (ass) of this queue automatically.
/*
* Licence:
*
* Feel free to use this however you want with the following limitations.
* Don't change this licence here and don't remove it either.
*
* You can add it to your own namespace and alter the code as you wish.
* Please share the changes if you think they might be useful to others.
*
@claudemartin
claudemartin / SomeClass.java
Created December 8, 2023 14:13
Solution: replaceAll(T oldValue, T newValue, T... data)
package ch.claude_martin;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Supplier;
class SomeClass {
/**