Skip to content

Instantly share code, notes, and snippets.

@sgdan
sgdan / awslogin
Last active August 24, 2019 15:12
Utility shell script for logging into AWS CLI named profile using an MFA token
#!/bin/bash
if [ $# -lt 1 ]; then
cat << EOF
usage: awslogin <profile>
Utility script for logging into AWS CLI named profile with an MFA token.
A session token will be requested and the "default" profile will be updated
with the valid session data. Make sure you have a named profile configured
as described below, including the "mfa" arn:
@sgdan
sgdan / dockerignore-test.sh
Created May 11, 2019 23:58
Test the ".dockerignore" file to ensure the build context doesn't contain unwanted files
#!/bin/sh
# Based on BMitch's answer from:
# https://stackoverflow.com/questions/38946683/how-to-test-dockerignore-file
# Note: will create and delete temporary file "Dockerfile.build-context"
# 1. Copy to project folder where image is being built
# 2. Run script
# 3. You should see list of files in build context
@sgdan
sgdan / rds-create-db-user-example.sql
Created October 19, 2018 20:14
Create database and user login for AWS SQL Server RDS database
/*
Example for AWS SQL Server RDS instance:
- create database
- create login with basic permissions
Since RDS is managed there are some restrictions when creating users and assigning
permissions. This procedure shows how to create a database and login with combinations
of ddl, read and write permissions.
*/
create procedure #createdbuser (
@sgdan
sgdan / Start-rancher2-self-signed-cert.sh
Created August 13, 2018 12:21
For local dev purposes, create a self-signed certificate and start Rancher 2 server container
# The Rancher 2 server container generates its own certificate but for some reason
# my browser wouldn't accept it, and didn't give me the option to override. Here's
# a way to generate a self-signed cert and use it to start the container.
# Note: I ran this on Git Bash shell in Windows 10, format for Linux may differ
# Generate certificate and key
openssl req -x509 -newkey rsa:4096 \
-keyout key.pem -out cert.pem \
-days 1000 -nodes \
@sgdan
sgdan / ExportDashboardCert.sh
Last active August 12, 2018 23:14
Use Kubernetes Dashboard with docker-for-desktop
# I've installed Docker for Windows and enabled the Kubernetes cluster
# My kubectl context is "docker-for-desktop" (right-click on docker tray icon > Kubernetes > docker-for-desktop)
# Docker should have updated my ~/.kube/config file for kubectl access
# Install the dashboard as per https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ by running:
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
# Using git bash shell on windows:
grep 'client-certificate-data' ~/.kube/config | awk '{print $2}' | base64 -d >> kubecfg.crt
grep 'client-key-data' ~/.kube/config | awk '{print $2}' | base64 -d >> kubecfg.key
@sgdan
sgdan / Vagrantfile
Created August 7, 2018 08:58
Create single node kubernetes cluster with kubeadm using vagrant and ubuntu
$script = <<-SCRIPT
#!/bin/sh
set -ex
apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee > /etc/apt/sources.list.d/kubernetes.list
apt-get update && apt-get install -y docker.io kubeadm
swapoff -a
sudo sed -i.bak '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
@sgdan
sgdan / KeepInList.elm
Created November 5, 2017 12:36
Iterate through an Elm list and compare each element against all the others
{--
Iterate through a list and compare each element to all the others to decide what to keep
Run at http://elm-lang.org:1234/try
--}
import Html exposing (text, div, br)
import String exposing (..)
initial = ["a", "ab", "c", "cdb", "cd"]
@sgdan
sgdan / DictIterators.elm
Created October 29, 2017 04:23
Iterating over a map in Elm
{--
Some Elm code for various ways to iterate over a map
Run at http://elm-lang.org:1234/try
--}
import Html exposing (text, div, br)
import Dict exposing (Dict)
import String exposing (toUpper)
@sgdan
sgdan / DictOfSets.elm
Last active October 29, 2017 01:27
Create a map of sets in Elm
{--
Some Elm code for a map of sets. This maps prices to the set of items
with that price.
Run at http://elm-lang.org:1234/try
--}
import Html exposing (text, div, br)
import Dict exposing (Dict)
import Set exposing (Set)
@sgdan
sgdan / loadResource.kts
Last active October 10, 2017 04:39
Compare loading a text resource via classpath or file
// Assume folder containing script is in the classpath
// To append current folder to classpath can pass: -Xbootclasspath/a:.
// load from file system
val fileContent = java.io.File("loadResource.kts").readText()
println("file content length: ${fileContent.length}")
// load via class path (can also use javaClass.getResource method but seems more reliable to go via class loader)
val urlContent = javaClass.classLoader.getResource("loadResource.kts").readText()
println("url content length: ${urlContent.length}")