Skip to content

Instantly share code, notes, and snippets.

View TimothyJones's full-sized avatar

Timothy Jones TimothyJones

  • Melbourne, Australia
View GitHub Profile
@TimothyJones
TimothyJones / alveohighlighting.js
Last active August 29, 2015 14:03
Alveo document annotations highlighting
// This gist provides an example of doing highlighting for
// Alveo annotations within a document displayed in a <pre> tag.
// It can be used at display time in the browser (with the right API calls).
// Although jQuery is used, it's not required except for the page update at the end
// Insert method for strings
String.prototype.insert = function (index, string) {
if (index > 0) {
if (index > this.length) {
@TimothyJones
TimothyJones / handy_commands.md
Last active August 21, 2021 05:56
Tim's awesome command cheatsheet

Prettier

Format all files in src:

prettier --config .prettierrc --write "src/**/*.js"

Or, more generally:

prettier --config --write "/**/*.js"

@TimothyJones
TimothyJones / gist:ff3fa2e5a04ab75743bc30a9425ae1d0
Last active August 25, 2017 02:25
Trying to get nice console formatting

With bash

git clone "<your-project-url>"
$ git clone "<your-project-url>"
Cloning into "'<your-project>'"...

With console

@TimothyJones
TimothyJones / pact-dsl-pitch.md
Last active May 9, 2022 16:00
Proposal to improve the Pact-JS DSL

Improving the Pact-JS DSL

(Thanks to Andras Bubics and Matt Fellows for many discussions leading to this proposal)

Test frameworks for Javascript are diverse - some run in parallel by default, some have different testing styles or expectations (eg BDD), and they all have different ways to configure and instrument the test framework.

The Pact workflow also includes a number of (necessary) assumptions and expectations - such as the need to keep

@TimothyJones
TimothyJones / safe_mode.sh
Last active August 13, 2019 01:38
Bash script safe mode
# start your script with
#!/bin/bash -eu
# Or
#!/usr/bin/env bash
set -o errexit
set -o nounset
@TimothyJones
TimothyJones / robust-bash.sh
Last active January 29, 2021 14:30
These are (currently) the only functions I recommend porting around when writing bash scripts
#!/bin/bash -eu
if [ -z "${LIB_ROBUST_BASH_SH:-}" ]; then
LIB_ROBUST_BASH_SH=included
function error {
echo "Error: ${1:-}"
}
# Check to see that we have a required binary on the path
function require_binary {
@TimothyJones
TimothyJones / getSsmConfig.js
Created August 28, 2019 04:44
Example showing a promisified SSM config reader for SecureString parameters
const AWS = require('aws-sdk');
const ssm = new AWS.SSM();
const configFeatures = {
'/path/to/your/config/option': 'someOption',
'/path/to/your/config/something_else': 'somethingElse'
};
const getConfig = () =>
@TimothyJones
TimothyJones / KMS-decrypt-example.js
Created August 30, 2019 04:47
Example showing a simple promisified decryption of a KMS encrypted string
const decrypt = data =>
new Promise((resolve, reject) =>
kms.decrypt(
{
CiphertextBlob: Buffer.from(data, 'base64')
},
(err, data) => {
if (err) {
reject(err);
} else {
@TimothyJones
TimothyJones / ssm-kms-put-parameter.sh
Created August 30, 2019 05:29
Example script for putting KMS-encrypted parameters into SSM as plain strings
#!/bin/bash -eu
# (C) Timothy Jones
# This function prints the usage
function usage {
{
echo "Usage:"
echo " ${BASH_SOURCE[0]} <NAME> <VALUE> <KEY_ID>"
echo " NAME - the name of the SSM variable"
@TimothyJones
TimothyJones / getDecryptedEnv.js
Last active September 4, 2022 04:38
A javascript module that demonstrates decrypting some KMS-encrypted environment variables
const AWS = require('aws-sdk');
const encryptedEnvironmentVariableNames = ['SOME_VARIABLE', 'SOME_OTHER_VARIABLE'];
// This module exports a function that returns a promise for obtaining
// a decrypted copy of the environnment.
//
// Configure it by putting the name of each environment variable you would like to
// decrypt above.
//