Skip to content

Instantly share code, notes, and snippets.

Avatar

Jörn Horstmann jhorstmann

View GitHub Profile
View AsmExamplesTest.kt
package net.jhorstmann.queryengine
import org.junit.jupiter.api.Test
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes
import org.objectweb.asm.util.CheckClassAdapter
import java.io.FileOutputStream
import java.util.function.IntSupplier
import java.util.function.Supplier
View ReadLineBenchmark.java
import java.io.*;
public class ReadLineBenchmark {
long volume = 0;
static class StringSlice implements CharSequence {
private final String str;
private final int idx;
private final int end;
View DoubleDabble.java
// https://en.wikipedia.org/wiki/Double_dabble
public class DoubleDabble {
static int bcd(int value, int bits) {
int res = value << (16 - bits);
res <<= 3;
for (int i = 3; i < bits; i++) {
// find bcd digits > 4 and incremented them 3
// either bit 4 is set or bit 3 and at least on of bits 2 or 1 is set
// bit 1 in mask ist set if digit > 4
// to get the add operand or the mask with mask<<1
@jhorstmann
jhorstmann / CartesianProduct.java
Last active May 22, 2018
Lazy Cartesian Product
View CartesianProduct.java
package org.zuchini.examples.parallel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Spliterator;
@jhorstmann
jhorstmann / TestConversions.java
Created Oct 28, 2016
Investigating memory usage of exchange rate conversions in moneta
View TestConversions.java
import org.javamoney.moneta.Money;
import javax.money.MonetaryAmount;
import javax.money.convert.CurrencyConversion;
import javax.money.convert.MonetaryConversions;
import java.math.BigDecimal;
public class TestConversions {
public static void main(String[] args) throws InterruptedException {
@jhorstmann
jhorstmann / mio-fuse-ble-setup.txt
Created Feb 7, 2016
MIO Fuse Buetooth LE Protocol
View mio-fuse-ble-setup.txt
# alerts
0000 12 20 00 09 02 4a 00 5d 6f 82 94 a7 82 94 # 4a=5zone,2sec,novib ? end_rest end_zone1 end_zone2 end_zone3 end_zone4 end_zone2 end_zone3
0000 12 20 00 09 02 4b 00 5d 6f 82 94 a7 82 94 # 4b=1zone,2sec,novib
0000 12 20 00 09 02 8b 00 5d 6f 82 94 a7 82 94 # 8b=1zone,1sec,novib
0000 12 20 00 09 02 cb 00 5d 6f 82 94 a7 82 94 # cb=1zone,on,novib
0000 12 20 00 09 02 fb 00 5d 6f 82 94 a7 82 94 # fb=1zone,on,vib
0000 12 20 00 09 02 7b 00 5d 6f 82 94 a7 82 94 # 7b=1zone,2sec,vib
0000 12 20 00 09 02 bb 00 5d 6f 82 94 a7 82 94 # bb=1zone,1sec,vib
0000 12 20 00 09 02 ba 00 5d 6f 82 94 a7 82 94 # ba=5zone,1sec,vib
View fizzbuzz.sql
WITH n AS (SELECT 100 AS n)
SELECT COALESCE(fizz || buzz, fizz, buzz, i::text)
FROM n
CROSS JOIN LATERAL generate_series(1, n) AS i
LEFT JOIN LATERAL (SELECT i, 'fizz'::text AS fizz
FROM generate_series(0, n, 3) AS i) fizz USING(i)
LEFT JOIN LATERAL (SELECT i, 'buzz'::text AS buzz
FROM generate_series(0, n, 5) AS i) buzz USING(i);
@jhorstmann
jhorstmann / Main.java
Last active Oct 24, 2018
How to get the method name from a java 8 lambda using serialization hacks
View Main.java
package net.jhorstmann;
import java.io.*;
public class Main {
public static class SerializedLam implements Serializable {
private static final long serialVersionUID = 8025925345765570181L;
public Class<?> capturingClass;
public String functionalInterfaceClass;
View MappingEngineShouldCreateSeparateObjects.java
package org.modelmapper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.modelmapper.spi.MappingContext;
import org.modelmapper.spi.MappingEngine;
import org.testng.Assert;
@jhorstmann
jhorstmann / RecurseiveParsingWithCollections.java
Created Nov 12, 2012
Using java collections instead of JsonBuilder
View RecurseiveParsingWithCollections.java
package net.jhorstmann.jsonp;
import java.io.IOException;
import java.io.PushbackReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
You can’t perform that action at this time.