Skip to content

Instantly share code, notes, and snippets.

View stijnvanbael's full-sized avatar

Stijn Van Bael stijnvanbael

  • Enprove
  • Belgium
View GitHub Profile
@stijnvanbael
stijnvanbael / TransactionDemo.java
Last active March 30, 2017 18:51
Transaction demo
import org.mariadb.jdbc.MariaDbDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Scanner;
public class TransactionDemo {
private static final String[] GENERIC_TLDS = new String[] {
// Taken from Version 2016042500, Last Updated Mon Apr 25 07:07:01 2016 UTC
"aaa", // aaa American Automobile Association, Inc.
"aarp", // aarp AARP
"abb", // abb ABB Ltd
"abbott", // abbott Abbott Laboratories, Inc.
"abbvie", // abbvie AbbVie Inc.
"abogado", // abogado Top Level Domain Holdings Limited
"abudhabi", // abudhabi Abu Dhabi Systems and Information Centre
"academy", // academy Half Oaks, LLC
@stijnvanbael
stijnvanbael / StringTemplate.java
Last active August 29, 2015 14:13
Simple String formatting and parsing template with named parameters
/*
Copyright (c) 2014 Stijn Van Bael
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
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
@stijnvanbael
stijnvanbael / designer.html
Last active August 29, 2015 14:09
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@stijnvanbael
stijnvanbael / designer.html
Created November 14, 2014 15:41
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@stijnvanbael
stijnvanbael / LazyList.java
Created November 25, 2013 11:34
Java List implementation that lazily initializes its contents when any method is called.
import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public abstract class LazyList<E> implements List<E> {
private LazyInitializer<List<E>> initializer = new LazyInitializer<List<E>>() {
@stijnvanbael
stijnvanbael / data-visualization.html
Last active December 21, 2015 12:28
Data visualization
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Month", "Carbon emissions"],
@stijnvanbael
stijnvanbael / TypeBuilder.java
Created July 10, 2013 11:52
TypeBuilder builds parameterized Java Class references.
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* <p>TypeBuilder builds parameterized {@code Class<?>} references. Example:</p>
* <pre>
* {@code
* Class<List<String>> type = new TypeBuilder<List<String>>() { }.build();
* }
* </pre>
@stijnvanbael
stijnvanbael / OngoingStubbingAdapter.java
Created July 10, 2013 11:50
Provides a way to obtain an OngoingStubbing for Mockito spies or void methods. This allows you to write highly readable code in your tests.
import org.mockito.Mockito;
import org.mockito.internal.stubbing.answers.ThrowsException;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.OngoingStubbing;
import org.mockito.stubbing.Stubber;
/**
* <p>
* Provides a way to obtain an OngoingStubbing for spies or void methods. This allows you to write highly readable code in your tests.
@stijnvanbael
stijnvanbael / Lazy.java
Last active December 19, 2015 13:59
A thread-safe Java object reference that will only initialize its value when get() is called
/*
Copyright (c) 2014 Stijn Van Bael
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
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following