Skip to content

Instantly share code, notes, and snippets.

claudemartin /
Last active Oct 10, 2019
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 /
Created Apr 24, 2018
Configurable bit position per enum [Example]
package ch.claude_martin.enumbitset;
import static java.util.Arrays.asList;
public class Main {
enum Bla implements EnumBitSetHelper<Bla> {
A(-1), B(42), C(108);
View .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 /
Created Oct 13, 2017
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>> {
UnaryOperator<T> apply(Fn2Op<T> x);
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() {
package ch.claude_martin.playground;
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
View pipe.c
#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;
claudemartin /
Last active Aug 29, 2015
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
claudemartin /
Last active Aug 29, 2015 — forked from anonymous/
game loop that can bepaused / stopped, now using a Lock.
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);