Skip to content

Instantly share code, notes, and snippets.

View luketn's full-sized avatar

Luke Thompson luketn

View GitHub Profile
@luketn
luketn / .zshrc
Last active June 7, 2021 04:28
Bash switch Java versions (my own little dumb jenv)
# Java List Utility - type jl or javalist at the command line to switch java versions
JAVALIST_FILE="/tmp/javalist.sh"
function loadjavalist {
if [ -f "$JAVALIST_FILE" ]; then
source ${JAVALIST_FILE}
echo "Current Java set to ${JAVA_NAME}!"
fi
}
function javalist {
@luketn
luketn / kinesis-cfn-template.yml
Last active June 8, 2023 06:33
A cloud formation template (and CDK stack) to create a Kinesis stream and Firehose delivering to S3
Resources:
Stream:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 2
Name: request-logging
RetentionPeriodHours: 24
StreamEncryption:
Fn::If:
- AwsCdkKinesisEncryptedStreamsUnsupportedRegions
@luketn
luketn / base-stack-props.ts
Created November 24, 2020 02:23
Customising Name Tags in CDK
import {StackProps} from "@aws-cdk/core";
export interface BaseStackProps extends StackProps {
product: string;
environment: "development" | "production";
}
@luketn
luketn / TLSv1Test.java
Created November 9, 2020 01:42
This code makes an SSL/TLS connection to a domain and writes the results to a file. Used to check issues with older TLS / SNI protocols by passing flags to java to control these settings (see class comments).
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
/**
import http from 'k6/http';
import { check } from "k6";
export let options = {
stages: [
// Ramp-up from 1 to 5 VUs in 5s
{ duration: "5s", target: 5 },
// Stay at rest on 5 VUs for 10s
{ duration: "10s", target: 5 },
// Ramp-down from 5 to 0 VUs for 5s
{ duration: "5s", target: 0 }
apiVersion: 1
providers:
- name: 'default'
org_id: 1
folder: ''
type: 'file'
options:
path: /var/lib/grafana/dashboards
apiVersion: 1
datasources:
- name: k6influxdb
type: influxdb
access: proxy
database: k6
url: http://influxdb:8086
isDefault: true
@luketn
luketn / docker-compose.yml
Created August 31, 2020 01:30
The docker-compose configuration file defines three servers and two networks, combining them together into a solution comprising a visualisation web server, database and load test client.
version: '3.4'
networks:
k6:
grafana:
services:
influxdb:
image: influxdb:latest
networks:
- k6
- grafana
@luketn
luketn / Docker.k6node
Created August 8, 2020 02:07
Docker file to install K6 and set up a NodeJS app to run.
FROM node:14.7.0
#Install K6
WORKDIR /tmp
ADD https://github.com/loadimpact/k6/releases/download/v0.27.1/k6-v0.27.1-linux64.tar.gz /tmp/k6-v0.27.1-linux64.tar.gz
RUN tar -xzf k6-v0.27.1-linux64.tar.gz
RUN mv k6-v0.27.1-linux64/k6 /usr/bin/k6
#Install NPM dependencies
COPY loadtest-home /loadtest-home
const child_process = require('child_process')
function run_script(command, args, realtimeCallback = (log, type) => {console.log(log)}) {
return new Promise((resolve) => {
let child = child_process.spawn(command, args)
let scriptOutput = ""
child.stdout.setEncoding('utf8')
child.stdout.on('data', function (data) {