Skip to content

Instantly share code, notes, and snippets.

View caprica's full-sized avatar
🇬🇧
In the Lands Between

Mark Lee caprica

🇬🇧
In the Lands Between
View GitHub Profile
@caprica
caprica / SwtBrowserCanvas.java
Created October 8, 2013 19:57
Embed an SWT Webkit Browser component inside a Swing JPanel, with non-crashing clean-up.
/*
* This class is made available under the Apache License, Version 2.0.
*
* See http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Author: Mark Lee
*
* (C)2013 Caprica Software (http://www.capricasoftware.co.uk)
*/
@caprica
caprica / equalizer.c
Created January 12, 2015 17:11
How to use the audio equalizer in LibVLC
/**
* A simple program to test the audio equalizer API in LibVLC.
*
* An example build command:
*
* $gcc -std=c99 -I/home/linux/vlc/vlc/include -o equalizer equalizer.c `pkg-config --cflags --libs libvlc`
*
* You may also need to set PKG_CONFIG_PATH first, for example:
*
* $export PKG_CONFIG_PATH=/home/linux/vlc/install/lib/pkgconfig
@caprica
caprica / FluxDataBufferParseExperiments.java
Last active October 15, 2021 21:02
Some experiments using Reactor to parse XML/JSON from a Flux of DataBuffer instances
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.io.BufferedWriter;
import java.io.FileWriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler;
import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@caprica
caprica / GlobalExceptionHandler.java
Created November 5, 2020 19:45
A way to globally map application exceptions to particular response codes in a Spring Boot WebFlux application.
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
@caprica
caprica / jq.sh
Last active October 6, 2021 18:26
Example using "jq" to pretty print JSON, displayed in "less", preserving colour codes
# Example using "jq" to pretty print JSON, displayed in less, preserving colour codes
curl -s http://localhost:8080/api/transfer/export | jq -C . | less -R
# Example using "gunzip", using "-c" with gunzip to keep the original file
gunzip -c filename.json/gz | jq -C . | less -R
@caprica
caprica / rename-mongodb-collection.json
Created September 10, 2021 18:21
MongoDB rename collection
db.currentCollectionName.renameCollection("newCollectionName")
@caprica
caprica / mongo-regex.js
Created September 16, 2021 06:37
Simple MongoDB regex
// Sequence number begins zero
db.collectionName.find({
"sequenceNumber": { $regex: /^0/ }
})
// Sequence number ends zero
db.collectionName.find({
"sequenceNumber": { $regex: /0$/ }
})
@caprica
caprica / mogno-dates.js
Created October 6, 2021 18:18
MongoDB query between two dates
db.collectionName.find(
{
$and: [
{"timestamp": {$gte: ISODate('2021-10-05T00:00:00.000Z')}},
{"timestamp": {$lt: ISODate('2021-10-06T00:00:00.000Z')}}
]
}
)
db.collectionName.count(
@caprica
caprica / application-properties.yaml
Last active September 7, 2023 20:46
Spring Boot YAML configuration for lists (or arrays) of strings
# For a property in a Spring component like this:
#
# @Value("${property.name}")
# private List<String> values;
#
# Spring will fail to start up with a vague error saying something like
# "Could not resolve placeholder 'property.name' in value "${property.name}"
# even though the property definition is right there in the yaml file
# For example, ordinarily in a yaml file something like this: