Skip to content

Instantly share code, notes, and snippets.

@danielflower
danielflower / PostgresInstance.java
Created February 28, 2020 02:46
Java code to launch postgres instances. Useful for testing etc.
package scaffolding;
import com.zaxxer.hikari.HikariDataSource;
import io.muserver.Mutils;
import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.Assumptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
@danielflower
danielflower / petstore.json
Created June 30, 2018 19:17
PetStore Open API v3
{
"openapi": "3.0.0",
"servers": [
{
"url": "https://petstore.swagger.io/v2"
},
{
"url": "http://petstore.swagger.io/v2"
}
],
@danielflower
danielflower / FileWatcher.java
Created April 22, 2017 08:54
Watching a single file in java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.*;
public class FileWatcher {
private static final Logger log = LoggerFactory.getLogger(FileWatcher.class);
private Thread thread;
@danielflower
danielflower / realtimeasciiart.html
Created September 22, 2012 08:27
HTML5 showing real time ASCII art. Takes video from your webcam and displays the ascii art version of it. Note: this cannot be run locally; it needs to be run from a web server.
<!DOCTYPE html>
<html>
<head>
<title>Real time ascii art</title>
<script>
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
@danielflower
danielflower / videocapture.html
Created September 21, 2012 16:20
An HTML5 page that takes a feed from a webcam and displays it multiple time using different effects. Note: running this as a local file won't work; it needs to be run from a webserver due to security restrictions.
<!DOCTYPE html>
<html>
<head>
<title>Video capture tests</title>
<script>
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
@danielflower
danielflower / gist:3656539
Created September 6, 2012 13:59
Javascript comparison function for Maven version strings, where a snapshot is older than a release version. Useful for sorting arrays of Maven versions. Disclaimer: only claims to support the patterns as described by the unit tests.
/**
* Compares two Maven version strings and returns value suitable for use in Array.sort.
* @param {String} v1
* @param {String} v2
* @return {Number} Negative number if v1 is older than v2; positive number if v1 is newer than v2; 0 if equal.
*/
exports.mavenVersionSortComparer = function (v1, v2) {
// Strategy: pad each part of the version with zeros so strings are same length, then do string compare.
// Snapshot version have an extra 0 put on the end, whereas release versions have a 1 on the end
// e.g. 1.5-SNAPSHOT vs. 1.10.0 => 1.05.0.a vs. 1.10.0.c