Skip to content

Instantly share code, notes, and snippets.

View jsamuel1's full-sized avatar

Josh Samuel jsamuel1

  • Melbourne, Australia
View GitHub Profile
@jsamuel1
jsamuel1 / slash.sh
Created August 1, 2019 01:54 — forked from luciomartinez/slash.sh
Add or Remove trailing slash in bash
### Add trailing slash if needed
STR="/i/am/a/path"
length=${#STR}
last_char=${STR:length-1:1}
[[ $last_char != "/" ]] && STR="$STR/"; :
echo "$STR" # => /i/am/a/path/
@jsamuel1
jsamuel1 / clean_code.md
Created July 29, 2019 22:39 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

git checkout -b upstream
git remote add upstream [email protected]/upstream1/blah.git
git fetch upstream # or use -f in git remote add
git merge -s subtree upstream/master --allow-unrelated-histories -X theirs
@jsamuel1
jsamuel1 / uefi-firmware-update.sh
Created May 12, 2019 23:20
Commandline - check for bios updates on Ubuntu
#!/bin/sh
sudo service fwupd start
# download metadata from https://cdn.fwupdate.org/downloads/firmware.xml.gz
sudo fwupdmgr refresh
# Output if any upgrades for each of the uefi firmare modoles
sudo fwupdmgr update
@ECHO off
:top
CLS
ECHO Choose a shell:
ECHO [1] cmd
ECHO [2] bash
ECHO [3] PowerShell
ECHO [4] PowerShell Core
ECHO [5] Python
ECHO [6] Visual Studio Developer Command Prompt
@jsamuel1
jsamuel1 / lock.sh
Last active February 18, 2019 04:33
i3lock with a blured screenshot background
#!/bin/sh
# for autolock, have xautolock call this script:
# xautolock -time 10 -locker lock.sh -enable
scrot /tmp/screenshot.png
convert /tmp/screenshot.png -blur 0x7 -blue-shift 1.5 /tmp/screenshotblur.png
rm /tmp/screenshot.png
i3lock -i /tmp/screenshotblur.png
@jsamuel1
jsamuel1 / 012_ecs_long_ids.tf
Created February 13, 2019 03:05
Terraform to enable long ARN formats for aws ecs, so that we can use fargate on all our workload accounts.
// Ensure we enroll ecs with long resource IDs
// Delete after April 1st as all new accounts will be enrolled by default
resource "null_resource" "enable_long_ecs_resource_ids" {
provisioner "local-exec" {
command = <<EOF
# $1=account_id, $2=region
source ${path.root}/../scripts/assume_role.sh \
${var.workload_account_id} \
${var.workload_provider_region}
@jsamuel1
jsamuel1 / supportplan.sh
Last active February 13, 2019 02:30
AWS Enterprise Support Plan Enrollment
#!/bin/sh
# Call from the organization master accounts credentials after creating the account.
# Pass in the new account id.
aws support create-case --service-code customer-account --category-code other-account-issues --subject "Please add account $1 to our enterprise support plan" --severity-code low --communication-body "Please add account $1 to my organizations enterprise support plan"
@jsamuel1
jsamuel1 / i3-gaps.sh
Last active February 11, 2019 00:09 — forked from dabroder/i3-gaps.sh
Install i3-gaps on ubuntu 18.04
#!/bin/bash
sudo apt install -y checkinstall libxcb1-dev libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-cursor-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev autoconf libxcb-xrm0 libxcb-xrm-dev automake
cd /tmp
# clone the repository
git clone https://www.github.com/Airblader/i3 i3-gaps
cd i3-gaps
# compile & install
@jsamuel1
jsamuel1 / aws-s3-buckets-with-tags.sh
Last active February 25, 2019 04:36 — forked from filipenf/aws-s3-buckets-with-tags.sh
Print a list of aws buckets along with their tags
#!/bin/bash
# lists all buckets along with their tags in the following format:
# bucket_name | { tag_name: tag_value }
for bucket in `aws s3api list-buckets | jq .Buckets[].Name -r`; do
tags=$(aws s3api get-bucket-tagging --bucket $bucket 2>/dev/null | jq -c '.[][] | {(.Key): .Value}' | tr '\n' '\t')
echo $bucket '|' $tags
done