Skip to content

Instantly share code, notes, and snippets.

View CounterConcurrentHashMap.java
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Test {
public static class MutableInteger {
private int val;
public MutableInteger() {
View Car.java
package ioc;
public class Car {
private final Engine engine;
private int fuel;
public Car(Engine engine) {
this.engine = engine;
}
public void addFuel(int fuel) {
@nielsutrecht
nielsutrecht / Car.java
Created Apr 26, 2017
Simple mockito example
View Car.java
public class Car {
private Engine engine;
private FuelTank fuelTank;
public Car(Engine engine, FuelTank fuelTank) {
this.engine = engine;
this.fuelTank = fuelTank;
}
public void start() {
View ReflectExample.java
import java.lang.reflect.Method;
public class ReflectExample {
public static void main(String... argv) throws Exception {
Animal a = new Dog("Max");
for (Method m : a.getClass().getMethods()) {
if (m.getName().startsWith("get") && m.getName().length() > 3 && !m.getName().equals("getClass")) {
String property = m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4);
View docker-compose.yml
version: '2'
services:
proxy:
image: traefik
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
networks:
- webgateway
ports:
- "80:80"
@nielsutrecht
nielsutrecht / RsaExample.java
Created Dec 28, 2016
Example of RSA generation, sign, verify, encryption, decryption and keystores in Java
View RsaExample.java
import javax.crypto.Cipher;
import java.io.InputStream;
import java.security.*;
import java.util.Base64;
import static java.nio.charset.StandardCharsets.UTF_8;
public class RsaExample {
public static KeyPair generateKeyPair() throws Exception {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
View Enemy.java
public class Enemy {
private int health;
public Enemy(int health) {
this.health = health;
}
public void hit(int damage) {
health -= damage;
}
@nielsutrecht
nielsutrecht / RsaExample.java
Created Dec 21, 2016
Example of using RSA in Java to sign/verify and encrypt/decryt
View RsaExample.java
import javax.crypto.Cipher;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
public class RsaExample {
public static void main(String... argv) throws Exception {
//First generate a public/private key pair
View Factorial.java
package test;
import shape.*;
public class Factorial {
public void testRound() {
Round round = new Round();
}
}
View UnitTestExample.java
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