Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / helm_chart_validate.yml
Created February 24, 2023 15:00
GitHub Action to validate Helm charts
name: Validate Helm chart
on:
push:
branches: [ main, master ]
pull_request:
jobs:
validate:
runs-on: ubuntu-latest
@magickatt
magickatt / cloudbuild.yaml
Created August 10, 2021 15:31
Add deploy key to SSH agent forwarding for Docker build in Google Cloud Build
- name: 'gcr.io/cloud-builders/git'
secretEnv: ['SSH_KEY']
entrypoint: 'bash'
args:
- -c
- |
echo "$$SSH_KEY" >> /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
volumes:
- name: 'ssh'
@magickatt
magickatt / silly_super.py
Created September 26, 2022 20:14
Silly example of method overriding using the parent return value
class Animal:
def what_am_i(self) -> str:
return "I am a "
class Fox(Animal):
def what_am_i(self) -> str:
return super().what_am_i() + "Fox"
@magickatt
magickatt / gist:6130199
Last active September 19, 2022 23:42
Output CSV to browser
<?php
// Headings and rows
$headings = array('ID', 'Name', 'Colour');
$array = array(
array(1, 'Apple', 'Green'),
array(2, 'Banana', 'Yellow'),
array(3, 'Orange', 'Orange'),
);
@magickatt
magickatt / delete_namespace.sh
Created September 19, 2022 14:27
Delete a k8s namespace that is stuck in terminating state
#!/bin/bash
NAMESPACE=test
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
killall kubectl
@magickatt
magickatt / example_uid.yaml
Created August 6, 2020 21:15
Expose Kubernetes Pod UID as an environment variable to a container
apiVersion: v1
kind: Pod
metadata:
name: example-uid
spec:
containers:
- name: test
image: busybox
command: ["/bin/sh", "echo", "$EXAMPLE_UID"]
env:
@magickatt
magickatt / jq_dashes.sh
Last active June 10, 2022 15:27
Escape JSON fields with numbers or dashes to avoid jq compile errors
echo '{"my-field": "something"}' > example.json
cat example.json | jq '.my-field' # Incorrect
# jq: error: key/0 is not defined at <top-level>, line 1: .my-field
# jq: 1 compile error
cat example.json | jq '."my-field"' # Correct
# "something"
@magickatt
magickatt / check_if_safe_to_release.sh
Last active March 29, 2022 15:18
Check if a CircleCI workflow is being run more than 1 at once
#!/bin/bash
# Project in the form vcs-type/organisation-name/repository-name
PROJECT=github/magickatt/example
# First, get all the Pipeline IDs for this workflow (triggered by a Git tag from a new release)
PIPELINE_IDS=(`curl --silent GET https://circleci.com/api/v2/project/$PROJECT/pipeline \
--header "Circle-Token: $CIRCLE_API_TOKEN" \
| jq --raw-output '.items | map(select(.vcs.tag != null)) | .[].id'`)
@magickatt
magickatt / Dockerfile
Created August 10, 2021 15:36
Use forwarded SSH agent in Docker build
FROM python:3.9-buster
# Prevents issues with cloning private PIP packages from GitHub
RUN --mount=type=ssh mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts
RUN pip install --upgrade pip
RUN pip install pipenv
COPY . .
# Use the forwarded SSH agent when installing pip packages
@magickatt
magickatt / gist:bb7108d276bce430cf35
Created August 15, 2014 09:50
Example of how to use the Symfony Config component
<?php
// Load application-specific configuration
try {
$basepath = __DIR__ . '/config';
$configuration = Yaml::parse($basepath . '/config.yml');
} catch (\InvalidArgumentException $exception) {
exit("Are you sure the configuration files exist?");
}