This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(createResponse(event.request)) | |
}) | |
async function createResponse(req) { | |
let domain = new URL(req.url).hostname.toString(); | |
if (domain !== 'www.jamesridgway.co.uk') { | |
let redirectHeaders = new Headers() | |
redirectHeaders.set('Location', 'https://www.jamesridgway.co.uk') | |
return new Response('', { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Use the AWS Metadata API to extract the IAM Role credentials and generate a traditional AWS config file. | |
# | |
set -e | |
if [ -z "$1" ]; then | |
PROFILE_NAME="default" | |
else | |
PROFILE_NAME="$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This works on the assumption that the EC2 instance has an IAM role that allows it to call describe-addresse | |
# and associate-address on the EC2 API | |
set -e | |
AWS_DEFAULT_REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r ".region") | |
export AWS_DEFAULT_REGION | |
# TODO: Insert name in the filter argument | |
ADDRESS_DETAILS=$(aws ec2 describe-addresses --filters "Name=tag:Name,Values=INSERT_NAME_HERE" --query "Addresses[0]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jq 'def sum(f): reduce .[] as $row (0; . + ($row|f) );[.[] | {"errorCount": .errorCount, "warningCount": .warningCount}] | . as $in | reduce (.[0] | keys)[] as $key ( {}; . + {($key): ($in | sum(.[$key]))})' eslint.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.co.jamesridgway.java.scratchpad; | |
import com.amazonaws.services.ec2.AmazonEC2; | |
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; | |
import com.amazonaws.services.ec2.model.DescribeImagesRequest; | |
import com.amazonaws.services.ec2.model.DescribeImagesResult; | |
import com.amazonaws.services.ec2.model.Filter; | |
import com.amazonaws.services.ec2.model.Image; | |
public class LatestAmi { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
echo "The user is: $SUDO_USER" | |
# System Updates | |
apt-get update | |
DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -yq | |
apt-get update | |
DEBIAN_FRONTEND=noninteractive apt-get upgrade -yq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
salt-run manage.down removekeys=True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Can be used as follows to copy all files with a normal exposure to a 'normal_exposure' folder: | |
# ./normal_exposure.sh | xargs -I '{}' cp '{}' normal_exposure/ | |
set -e pipefail | |
for file in *.CR2; | |
do | |
exiftool "$file" | grep -P "AEB Bracket Value\s+: 0" | true | |
if [ "${PIPESTATUS[1]}" -ne 1 ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
NestedDict wrapper | |
""" | |
class NestedDict(dict): | |
def __getitem__(self, key_namespace): | |
if "." not in key_namespace: | |
return super(NestedDict, self).__getitem__(key_namespace) | |
keys = key_namespace.split('.') | |
val = self | |
for key in keys: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def instance = Jenkins.getInstance() | |
def pluginManager = instance.getPluginManager() | |
def plugins = pluginManager.getPlugins() | |
def installedPlugins = [] | |
plugins.each { | |
installedPlugins << it.getShortName() | |
} |