Skip to content

Instantly share code, notes, and snippets.

View lawrencegripper's full-sized avatar

Lawrence Gripper lawrencegripper

View GitHub Profile
@lawrencegripper
lawrencegripper / buildyamlsnippet.yaml
Last active November 22, 2020 10:50
Trigger Job on file changes in Azure Devops
- job: ciml
displayName: "Machine Learning CI"
pool:
vmImage: 'Ubuntu 20.04'
steps:
- task: PowerShell@2
displayName: 'Run CI Task from make.ps1 in Devcontainer'
inputs:
targetType: 'inline'
script: 'Install-Module -Name PSake -Force && Invoke-psake ./make.ps1 ciml'
# Which is equivalent to
format = """
$username\
$hostname\
$shlvl\
$kubernetes\
$directory\
$git_branch\
$git_commit\
$git_state\
@lawrencegripper
lawrencegripper / main.tf
Last active September 28, 2023 19:07
Azure VPN Gateway OpenVPN
resource "random_string" "random" {
length = 8
special = false
upper = false
number = false
}
resource "azurerm_public_ip" "vpn_ip" {
name = "vpn-ip"
@lawrencegripper
lawrencegripper / trap.sh
Last active September 21, 2021 19:25
Cleanup in Bash script
#!/bin/bash
set -e
function cleanup()
{
echo -e "----> Trap caught! Do cleanup here"
}
trap cleanup EXIT
# imagine some stuff happens here
@lawrencegripper
lawrencegripper / togglemute.sh
Created April 12, 2020 21:33
Mute and unmute mic Ubuntu
#!/bin/bash
pacmd list-sources | \
grep -oP 'index: \d+' | \
awk '{ print $2 }' | \
xargs -I{} pactl set-source-mute {} toggle
MUTED=$(pacmd list-sources | grep "muted: no" | wc -l)
if (( $MUTED > 0 )); then
@lawrencegripper
lawrencegripper / 1_gen_image_sizes.sh
Last active February 24, 2020 12:14
Generate docker images of specific size
#!/bin/bash
set -e
set -x
# Push 200mb image
dd if=/dev/urandom of=./file.bin bs=1M count=200
docker build -t lawrencegripper/big:200mb .
docker push lawrencegripper/big:200mb
rm ./file.bin
@lawrencegripper
lawrencegripper / 1_devcontainer.json
Last active February 25, 2020 11:40
devcontainer k8s wip
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/go
{
"name": "Go",
"dockerFile": "Dockerfile",
"runArgs": [
// Uncomment the next line to use a non-root user. On Linux, this will prevent
// new files getting created as root, but you may need to update the USER_UID
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
// "-u", "vscode",
@lawrencegripper
lawrencegripper / Makefile
Last active January 15, 2020 12:53
Kind in make
KIND_CLUSTER_NAME ?= "opa-rego-teammapping"
WAIT_FOR_KIND_READY = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
WAIT_FOR_OPA_READY = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
.PHONY: all build test integration
all: test kind-integration
build: test
@lawrencegripper
lawrencegripper / test.rego
Created January 13, 2020 20:14
opa blog part3
# patch we expect to be generated
expectedPatch = {
"op": "add",
"path": "spec/nodeSelector",
"value": {
"agentpool": "pool1"
}
}
# Helper to check patch is set
@lawrencegripper
lawrencegripper / rules.rego
Created January 13, 2020 20:09
opa blog part2
# Rule: Check if the item submitted is a pod.
isPod {
input.request.kind.kind == "Pod"
}
# Rule: Check if pod already has a `nodeSelector` set
hasNodeSelector {
input.request.object.spec.nodeSelector
count(input.request.object.spec.nodeSelector) > 0
}