Skip to content

Instantly share code, notes, and snippets.

{
"kind": "Listing",
"data": {
"modhash": "ktve0h61g983ea8a06d93d647897c6b1091b00331882f45a35",
"children": [
{
"kind": "t3",
"data": {
"domain": "i.imgur.com",
"banned_by": null,
@nielsutrecht
nielsutrecht / Helper.java
Created June 18, 2014 09:36
Sieve implementation in Java
public class Helper {
public static BitSet generatePrimes(final int maxNum) {
final BitSet set = new BitSet(maxNum+1);
set.clear(0, 1);
set.set(2, maxNum, true);
for (int i = 2; i < maxNum; i++) {
boolean isPrime = true;
for (int j = 0; j < (int) Math.sqrt(i); j++) {
if (!set.get(j)) {
continue;
@nielsutrecht
nielsutrecht / DataReaderWriter.java
Created August 29, 2014 08:04
Reading / writing JSON example
package monster;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
@nielsutrecht
nielsutrecht / FreqCount.java
Created September 23, 2015 08:27
Gutenberg frequency count
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static java.lang.Integer.compare;
@nielsutrecht
nielsutrecht / IfVsArray.java
Created September 29, 2015 11:23
isVowel performance
package misc;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.Arrays;
import java.util.HashSet;
package droptable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class DropTable {
private List<DropChance> table;
private boolean sorted;
package thread;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/**
* Example that shows communications between threads through blocking queues. There are 4 worker threads and one printer
import java.util.BitSet;
public class EratosthenesSieve {
private BitSet primes = null;
public void init(int maxNum) {
final long start = System.currentTimeMillis();
primes = new BitSet(maxNum+1);
primes.clear(0, 1);
package crypt;
import javax.xml.bind.DatatypeConverter;
import java.util.*;
public class SubstCrypto {
private static char[] createKey(long seed) {
char[] key = new char[256];
for(int i = 0;i < key.length;i++) {
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
public class UnitTestExample {
private UnitUnderTest unit;
@Before