Skip to content

Instantly share code, notes, and snippets.

Avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / python_datetime_gmtplus2.md
Last active Oct 1, 2021
Python use Datetime to get time in SAST or custom timezone
View python_datetime_gmtplus2.md

Install pytz:

pip install pytz

Python example to get time in GMT+2 or Africa/Johannesburg:

>>> import pytz
@ruanbekker
ruanbekker / Dockerfile
Created Jul 9, 2021
Liquibase Migrations in CI/CD CodeBuild Pipeline with Docker
View Dockerfile
FROM maven:3.6.1-amazoncorretto-11 as builder
ARG DB_USER
ARG DB_PASSWORD
ARG DB_URL
ENV DB_USER=${DB_USER}
ENV DB_PASSWORD=${DB_PASSWORD}
ENV DB_URL=${DB_URL}
RUN curl -LJO https://github.com/liquibase/liquibase/releases/download/v4.2.0/liquibase-4.2.0.tar.gz && \
@ruanbekker
ruanbekker / install_bitcoin_core_testnet.sh
Created Jun 23, 2021
Install Bitcoin Core Testnet on Linux Script
View install_bitcoin_core_testnet.sh
#!/usr/bin/env bash
# Note:
# I use this script to bootstrap testnet nodes, if you are using the mainnet,
# I STRONGLY recommend to set rpcallowip to localhost
# environment variables
export ARCH=x86_64
export BITCOIN_VERSION=0.21.1
export BITCOIN_URL=https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz
@ruanbekker
ruanbekker / awscli_v2_ubuntu.md
Created Feb 23, 2021
Install AWS CLI Version 2 on Ubuntu 20
View awscli_v2_ubuntu.md
$ apt update
$ apt search awscli
$ apt install curl wget unzip -y
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ ./aws/install
$ aws --version
aws-cli/2.1.28 Python/3.8.8 Linux/4.19.121-linuxkit exe/x86_64.ubuntu.20 prompt/off
@ruanbekker
ruanbekker / lambda_zip_package_python.md
Created Feb 22, 2021
Update AWS Lambda Function with Dependencies in Python using a Deployment Package
View lambda_zip_package_python.md

Change into our working directory:

$ mkdir -p myworkdir/src 
$ cd myworkdir

Create a virtual env:

@ruanbekker
ruanbekker / terraform_aws_buildspec.yml
Created Feb 19, 2021
Install Terraform on AWS CodeBuild
View terraform_aws_buildspec.yml
version: 0.2
env:
variables:
TERRAFORM_VERSION: "0.14.7"
phases:
install:
commands:
- curl -o "terraform.zip" https://releases.hashicorp.com/terraform/"$TERRAFORM_VERSION"/terraform_"$TERRAFORM_VERSION"_linux_amd64.zip
@ruanbekker
ruanbekker / initd_script.sh
Last active Feb 10, 2021
Amazon Linux Startup Script Template
View initd_script.sh
#!/usr/bin/env bash
# inspired by:
# https://unix.stackexchange.com/a/193568
# source function library
. /etc/init.d/functions
# application name
APP="node_exporter"
DESC="Node Exporter"
@ruanbekker
ruanbekker / terraform_output_aws_vpc.md
Created Feb 9, 2021
Output values with Terraform
View terraform_output_aws_vpc.md

provider.tf:

$ cat provider.tf
provider "aws" {
  version = "~> 2.0"
  region  = "eu-west-1"
  profile = "dev"
  shared_credentials_file = "~/.aws/credentials"
}
View pushover_notifiers_examples.md

In BASH:

# usage: ./pushover-notify home-pc "homepc notification"
#!/bin/bash
APP_TOKEN='x'
USER_TOKEN='x'
TITLE="$1"
MESSAGE="$2"
curl 'https://api.pushover.net/1/messages.json' -X POST -d "token=$APP_TOKEN&user=$USER_TOKEN&message=\"$MESSAGE\"&title=$TITLE"
@ruanbekker
ruanbekker / random_strings_or_numbers.md
Last active Feb 1, 2021
Bash: Return random number or string from array or range
View random_strings_or_numbers.md

Return random string from array:

#!/usr/bin/env bash
subnets[0]="subnet1"
subnets[1]="subnet2"
subnets[2]="subnet3"

size=${#subnets[@]}
index=$(($RANDOM % $size))