Skip to content

Instantly share code, notes, and snippets.

View acodeninja's full-sized avatar

Lawrence acodeninja

View GitHub Profile
@acodeninja
acodeninja / .gitprofiles.json
Created February 17, 2023 11:56
Quickly switch between git profiles after cloning a new repo
{
"acodeninja": {
"name": "Lawrence",
"email": "lawrence@...",
"signingkey": "...."
},
"madetech": {
"name": "Lawrence Goldstien",
"email": "lawrence.goldstien@...",
"signingkey": "...."
@acodeninja
acodeninja / wait-for-service.sh
Created June 15, 2022 08:23
A simple script to wait for a service's port to open.
#!/usr/bin/env sh
WAIT_FOR_HOST=$1
WAIT_FOR_PORT=$2
while ! nc -z "$WAIT_FOR_HOST" "$WAIT_FOR_PORT"; do
sleep 0.3
echo "INFO [wait-for] Checking $WAIT_FOR_HOST:$WAIT_FOR_PORT"
done
@acodeninja
acodeninja / nvm-use.sh
Created September 17, 2021 12:41
Switch nvm version based on package.json engines entries
#!/usr/bin/env bash
nvm use $(cat package.json | jq '.engines.node' -r)
@acodeninja
acodeninja / install-gh-ssh-keys.sh
Created September 17, 2021 11:43
Install github ssh keys on a remote box
#!/usr/bin/env bash
GH_USER=$1
sudo apt-get instal jq -y
curl "https://api.github.com/users/$GH_USER/keys" | jq '.[].key' -r > ~/.ssh/authorized_keys
@acodeninja
acodeninja / Checkout.js
Created January 14, 2020 17:17
ukef-code-test-nodejs
module.exports = class Checkout {
constructor(pricing_rules) {
this.pricing_rules = pricing_rules;
this.items = [];
}
scan(item) {
if (! Object.keys(this.pricing_rules).includes(item)) {
throw new Error("not in the rules");
}
@acodeninja
acodeninja / aws-credentials-setup.sh
Created November 11, 2019 09:43
Used on non-ec2 friendly instances to get an auth session
#!/usr/bin/env bash
which tar1 &>/dev/null
[ $? -eq 0 ] || sudo yum install jq
CREDS=$(curl http://169.254.169.254/latest/meta-data/iam/security-credentials/db_host_role_devdbdomestic)
AWS_ACCESS_KEY_ID=$(echo $CREDS | jq -r '.AccessKeyId')
AWS_ACCESS_SECRET=$(echo $CREDS | jq -r '.SecretAccessKey')
AWS_SESSION_TOKEN=$(echo $CREDS | jq -r '.Token')
@acodeninja
acodeninja / tmp-image-cleanup.sh
Created April 12, 2019 09:49
Clean out temporary image files from a directory of your choosing.
#!/usr/bin/env bash
FILE_AGE=$1
FILE_COUNT=$2
FILE_LOCATION=$3
if [ -z "$FILE_AGE" ] || [ -z "$FILE_COUNT" ] || [ -z "$FILE_LOCATION" ]; then
echo "Usage: $(basename $0) [file age in days] [file count] [directory location]"
exit 1
fi
@acodeninja
acodeninja / sourcerer-repo-scan.sh
Created March 26, 2019 21:03
Add any repositories from the local directory (recursively) to sourcerer cli app
#!/usr/bin/env bash
echo "Scanning, this might take a while, especially if you have lots of vendor directories"
while read d; do
echo "Adding directory $d to sourcerer"
sourcerer add $d
done < $(find . -type d \
-exec sh -c 'cd "{}"; git rev-parse --git-dir 2> /dev/null 1>&2' \; \
-prune \
@acodeninja
acodeninja / Vagrantfile
Last active September 24, 2018 10:17
A drop in `Vagrantfile` for Symfony3
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip: "192.168.190.#{2 + rand(255)}"
config.vm.hostname = "symfony-app.test"
config.hostmanager.enabled = true
@acodeninja
acodeninja / Dockerfile
Last active January 29, 2019 16:13
Symfony Docker Composer Setup
FROM php:fpm-alpine
# Install XDebug
RUN apk add g++ gcc make autoconf && \
pecl install xdebug-2.6.1 && \
docker-php-ext-enable xdebug && \
apk del g++ gcc make autoconf
# Install MySQL driver
RUN docker-php-ext-install pdo_mysql