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
@graydon
graydon / country-bounding-boxes.py
Created April 23, 2014 00:03
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
@dannypule
dannypule / json_to_csv.js
Created February 8, 2017 18:40
Export JSON to CSV file using Javascript
function convertToCSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if (line != '') line += ','
line += array[i][index];

Compile for Windows (64bit)

Pull the VideoLAN Docker container and run it in interactive mode with bash:

(The -v ~/docker:/root/shared maps /root/shared in the container to ~/docker on your machine to easily obtain the build results, so make sure ~/docker exists.)

docker pull registry.videolan.org:5000/vlc-debian-win64
docker run -v ~/docker:/root/shared -it registry.videolan.org:5000/vlc-debian-win64 /bin/bash
@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;
@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
@babldev
babldev / README.md
Last active December 29, 2023 20:54
NextJS Background Task

NextJS Background Task Example

An example of how to add a background task (e.g. a queue consumer) to an existing NextJS project.

Setup

  • Add your background task file
  • Add a new worker-tsconfig.json, specifically specifying "module": "commonjs" and targeting only the worker source files.
  • Add convenience functions for building & running to package.json

Then to build once: