Skip to content

Instantly share code, notes, and snippets.

@SingingBush
SingingBush / dlang_version_check.md
Last active January 6, 2023 18:32
a collection of D version checks for compatibility
// https://dlang.org/changelog/2.101.0.html#logger
static if(__traits(compiles, (){ import std.logger; } )) {
    import std.logger;
} else {
    // logger was in 'std.experimental' for a long time but you could optionally check that too
    import std.experimental.logger;
}
@SingingBush
SingingBush / post-images-to-api.ps1
Created September 12, 2019 12:05
Iterate images in a directory and make a POST request for each one to an API
$baseUrl = 'http://api.domain.com/some-service/'
Get-ChildItem -Path ".\*.jpg" | Sort-Object Name | % {
$response = try {
Invoke-RestMethod -uri "$baseUrl/image" -Method Post -Infile $_.Name -ContentType 'image/jpeg' -ErrorAction Stop
} catch [System.Net.WebException] {
Write-Error "Media Service returned $($_.Exception.Response.StatusCode.Value__) : $($_.Exception.Message)"
Exit 1;
}
@SingingBush
SingingBush / Dockerfile
Created November 27, 2020 16:26
docker image of Amazon Linux with the aws-cli tools and Corretto installed with UK locale
# Amazon Linux with Amazon Corretto and the aws-cli tools for use in the UK (Amazon Linux uses yum)
FROM amazon/aws-cli:latest
# Set the default region for aws-cli
RUN mkdir /root/.aws && echo -e "[default]\nregion = eu-west-1" >> /root/.aws/config
# Set the locale to UK
ENV LANG en_GB.UTF-8
ENV LANGUAGE en_GB:en
ENV LC_ALL en_GB.UTF-8
@SingingBush
SingingBush / CloudWatch examples.md
Last active October 26, 2022 16:14
Advanced CloudWatch queries for aggregating and visualising application logs

CloudWatch is really powerful. As well as just searching your logs you can quickly aggregate and visualise data from your logs.

Visualising warnings and errors in a line chart

In this example we use a regex make a capture group for loglevel based on lines such as 2022-10-26T16:00:00.000Z ERROR something bad happened! then count how many times the logs contained a WARN or ERROR in the log file in a 30 minute interval. This query can be used in conjunction with the Visualization tab in CloudWatch (select Line from the dropdown).

With a little editing based on your use case, this query wiil help build an overview of your error rate

@SingingBush
SingingBush / TestUtils.java
Created May 8, 2023 10:38
Matching json with mockito
import org.mockito.ArgumentMatcher;
// javax.json:javax.json-api
//import javax.json.Json;
//import javax.json.JsonStructure;
//import javax.json.stream.JsonGenerator;
// jakarta.json:jakarta.json-api
import jakarta.json.Json;
import jakarta.json.JsonStructure;
@SingingBush
SingingBush / maven gpg instructions.md
Last active May 8, 2023 17:57
Maven: signing artifacts for release to maven central

These instructions cover the following topics

  • Generating/updating GPG keys
  • Publishing GPG keys
  • Adding GPG keys to GitHub
  • Using GPG keys to sign git commits
  • Using GPG keys to sign maven artifacts
  • Publishing maven artifacts to OSSRH (Open Source Software Repository Hosting)

It's recommended to also read the following documentation

@SingingBush
SingingBush / Doom 3 modding.md
Last active May 28, 2023 18:20
Developing mods and maps for Doom 3 (dhewm3)

Developing mods and maps for Doom 3 (dhewm3)

Getting Doom 3

It's worth getting Doom 3 from the Steam store as it includes:

  • The original DOOM 3
  • Resurrection of Evil Expansion
  • DOOM 3: BFG Edition
@SingingBush
SingingBush / aws-quick-setup-guide.md
Last active January 20, 2024 20:28
Quick setup guide for configuring a fresh AWS account

AWS quickstart guide

This guide assumes you are setting up AWS for the first time either for personal use of for a small business (couple of users). The steps will also scale to a large organisation but it's likely that you will want to think through a more complex structure for grouping users into accounts and the permissions they have.

Part 1: Be careful not to spend too much (Optional / Recommended Step)

From the top-right drop-down, select Billing and Cost Management, then Budgets, then Create budget. Here you can define a budget or use a premade template. When starting out you may want to try sticking to the Zero spend budget for example.

Part 2: Let's begin by creating an organisation with a few accounts