Skip to content

Instantly share code, notes, and snippets.

View bnyeggen's full-sized avatar

Bryce Nyeggen bnyeggen

View GitHub Profile
@bnyeggen
bnyeggen / MMapper.java
Last active May 31, 2021 12:06
Mmap more than 2GB of a file in Java
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
import sun.misc.Unsafe;
@SuppressWarnings("restriction")
public class MMapper {
@bnyeggen
bnyeggen / shade.xml
Created August 28, 2014 17:01
Maven uberjar via maven-shade-plugin
<plugin>
<!-- uberjar via "mvn package shade:shade" -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
@bnyeggen
bnyeggen / TombstoneBinarySearch.java
Created October 20, 2015 02:00
Binary search that considers magic value as not present
public class TombstoneBinarySearch {
public static int binarySearch(long[] a, int fromIndex, int toIndex, long key, long tombstone) {
int low = fromIndex;
int high = toIndex - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
final int origMid = mid;
long midVal = a[mid];
@bnyeggen
bnyeggen / Crypt.java
Created November 29, 2015 22:04
Stream based en/decryption in Java 7
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;