Skip to content

Instantly share code, notes, and snippets.

@nieldw
nieldw / Gson toString() template
Created October 16, 2015 07:48
Java toString() generator for IntelliJ IDEA that generates JSON using Gson
public java.lang.String toString() {
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(this);
}
@nieldw
nieldw / spring-batch_item-readers.md
Last active October 17, 2021 07:23
Challenges with built-in item readers in Spring Batch

Challenges with built-in item readers in Spring Batch

Lately I have done a lot of work with spring-batch. The learning curve is quite steep because there are a lot concepts and principles to master before you can start using it effectively. By now I've read every page of documentation and a number of blogs. Once you get going you think you know what you are doing, but there are still a lot of pitfalls that can trip you up. Here are three.

Any paging item reader

When using a paging item reader and performing processing on the returned items, beware that you could be changing the results of your query between chunks, which means that page 2 might contain different records before processing page 1 and after processing page 1. This can result either in certain records not being returned by your item reader, or others being

@nieldw
nieldw / setting-competency-based-goals.md
Last active February 10, 2016 06:13
Setting competency based goals

Setting competency-based goals

For my current performance review cycle, I decided to experiment with goals worded in terms of competencies, rather than tasks. The purpose of which is to focus on developing competencies, instead of just measuring tasks completed.

Performance management at BSG

At BSG, we take professional development seriously and set goals around contribution areas related to individual roles every six months. The key is regular, incremental feedback from peers and regular progress conversations with Career Facilitators. This encourages continuous improvement, and once you have demonstrated the competencies needed to move to the next job grade, a promotion is on the cards.

Wording goals

@nieldw
nieldw / RandomiseNames.sql
Created July 26, 2016 06:38
A MySQL script to shuffle around the names in an employee table. Effectively it replaces the first and last names on each row with names randomly chosen from other rows.
SET SQL_SAFE_UPDATES = 0;
drop table if exists scramble;
create temporary table scramble (SELECT
employee_id.id,
first_name.first_name,
last_name.last_name
FROM
(
-- randomise employee id
@nieldw
nieldw / install_azurefile_dockervolumedriver.sh
Created October 10, 2016 16:07
Install azurefile docker volume driver on ubuntu with upstart
#!/bin/bash
# Run with `sudo`
STORAGEACCOUNT_NAME=$1
STORAGEACCOUNT_KEY=$2
if [ -z "$1" ]; then echo "Storage Account Name not set..." && exit 2 ; fi
if [ -z "$2" ]; then echo "Storage Account Key not set..." && exit 2 ; fi
echo "# Install CIFS"
@nieldw
nieldw / delete-images-before.sh
Last active June 19, 2024 05:36
Bash script to remove old images in continuous integration (jenkins,teamcity,bamboo,etc) environment. It keeps the provided image (therefore making it available for caching), but removes all older versions of that image.
#!/usr/bin/env bash
usage(){
# ============================================================
echo This script removes all images of the same repository and
echo older than the provided image from the docker instance.
echo
echo This cleans up older images, but retains layers from the
echo provided image, which makes them available for caching.
echo
@nieldw
nieldw / teamcity-backup-cronjob.yaml
Last active June 1, 2018 13:08
Kubernetes CronJob that runs a Team City backup
kind: CronJob
apiVersion: batch/v1beta1
metadata:
name: teamcity-server-backup
labels:
app: teamcity
type: cron
spec:
schedule: "30 10,20 * * 1-5" # Every weekday at 10:30, and 20:30 UTC
@nieldw
nieldw / teamcity-server-backup-restorer-job.yaml
Created June 6, 2018 09:29
Kubernetes Job that restores a Team City backup from a persistent volume
kind: Job
apiVersion: batch/v1
metadata:
name: teamcity-server-backup-restorer
spec:
template:
metadata:
labels:
app: teamcity
@nieldw
nieldw / TopLevelLoggerTest.kt
Last active October 25, 2018 11:41
Kotlin Top Level Function loggers
package com.example.nieldw
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.junit.jupiter.api.Test
fun logger(lambda: () -> Unit): Lazy<Logger> = lazy { LogManager.getLogger(getClassName(lambda.javaClass)) }
private fun <T : Any> getClassName(clazz: Class<T>): String = clazz.name.replace(Regex("""\$.*$"""), "")
val topLog by logger { }
@nieldw
nieldw / ClassLoggerWithLambda.kt
Created October 25, 2018 11:35
Get a logger in Kotlin using the class name of a lambda
package com.example.nieldw
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.junit.jupiter.api.Test
fun logger(lambda: () -> Unit): Lazy<Logger> = lazy { LogManager.getLogger(getClassName(lambda.javaClass)) }
private fun <T : Any> getClassName(clazz: Class<T>): String = clazz.name.replace(Regex("""\$.*$"""), "")
class TopLevelLoggingTest {