Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / aws_ssm_get_parameters.md
Created January 31, 2018 14:38
Getting Secrets from SSM using GetParameters Example

Example with SSM to get Parameter Values using GetParameters:

Setting Environment Variables:

$ export MYSQL_HOSTNAME="/test/ruan/mysql/db01/mysql_hostname"
$ export MYSQL_USERNAME="/test/ruan/mysql/db01/mysql_user"
@ruanbekker
ruanbekker / report_status.sh
Created February 15, 2018 09:42
Report Status Codes in Bash
#!/bin/bash
#set -e
python -c "import $1" > /dev/null 2>&1
code=$?
if [ $code == 0 ]
then
echo "good"
echo "Status Code: $code"
else
@ruanbekker
ruanbekker / read_and_write-args.go
Last active March 2, 2018 11:18
Golang: Read File and Write to Disk with Arguments
package main
import (
"io/ioutil"
"os"
"fmt"
)
var (
input_filename string
@ruanbekker
ruanbekker / crypto_currency_ingest_elasticsearch.py
Created June 27, 2017 07:06
Ingest Crypto Currency Data into Elasticsearch using the coinmarketcap API
## Resources:
# https://pypi.python.org/pypi/coinmarketcap/
# https://coinmarketcap.com/api/
import json
import requests
from coinmarketcap import Market
c = Market()
@ruanbekker
ruanbekker / generate_random_setbyte_strings.py
Created April 30, 2018 06:09
Generate 16 or 32 Byte Readable Strings with Python
>>> import random, string
>>> key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for x in range(32))
>>> iv = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for x in range(16))
>>> print(key, len(key))
('eXS8qhYpisQf4zm60pBeMGbCTh5dfXiQ', 32)
>>> print(iv, len(iv))
('mjVRMZ3WSd31fEVn', 16)
@ruanbekker
ruanbekker / report-untagged-aws-resources.py
Created August 10, 2017 14:11
Report Untagged AWS Resources using CSV reader in Python (Per Service and Detailed)
# get the csv from:
# https://resources.console.aws.amazon.com/r/tags
import csv
from collections import Counter
with open('resources.csv', 'rb') as csvfile:
print("Missing Tags Per Service:")
print("=========================")
reader = csv.DictReader(csvfile)
@ruanbekker
ruanbekker / flask_cache_simple.py
Created May 12, 2018 20:55
Flask-Cache Example with Simple Type
from flask import Flask
from flask_caching import Cache
import random
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
@app.route("/route1")
@cache.cached(timeout=10)
def route1():
@ruanbekker
ruanbekker / git_empty_branch.sh
Created May 21, 2018 09:26
Create Empty Branch for Git
git checkout master
git checkout --orphan version
for x in `git ls-files`; do git rm --cached $x; done
for x in `ls`; do rm -rf $x; done
touch README.md
git add README.md
git commit -m "initial commit for empty version branch"
git push origin version
@ruanbekker
ruanbekker / bash_return_default_on_empty_var.sh
Created May 25, 2018 06:51
Bash: If Variable Empty Return Default Value
#!/bin/bash
set -ex
K=$1
K=${K:=BLANK_VARS}
if [ "$K" == "BLANK_VARS" ] ;
then echo "blanks" && exit 1 ;
else echo $K ;
@ruanbekker
ruanbekker / python-flask-caching.py
Created June 5, 2018 23:45
Python Flask-Caching Test using the Simple Cache Option (does not show response cache headers)
from flask import Flask
from flask_caching import Cache
from time import strftime
app = Flask(__name__)
app.config['CACHE_TYPE'] = 'simple'
app.cache = Cache(app)
def get_time():