Skip to content

Instantly share code, notes, and snippets.

@sgdan
sgdan / awslogin
Last active Aug 24, 2019
Utility shell script for logging into AWS CLI named profile using an MFA token
View awslogin
#!/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
Test the ".dockerignore" file to ensure the build context doesn't contain unwanted files
View dockerignore-test.sh
#!/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 Oct 19, 2018
Create database and user login for AWS SQL Server RDS database
View rds-create-db-user-example.sql
/*
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 Aug 13, 2018
For local dev purposes, create a self-signed certificate and start Rancher 2 server container
View Start-rancher2-self-signed-cert.sh
# 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 Aug 12, 2018
Use Kubernetes Dashboard with docker-for-desktop
View ExportDashboardCert.sh
# 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 Aug 7, 2018
Create single node kubernetes cluster with kubeadm using vagrant and ubuntu
View Vagrantfile
$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 Nov 5, 2017
Iterate through an Elm list and compare each element against all the others
View KeepInList.elm
{--
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 Oct 29, 2017
Iterating over a map in Elm
View DictIterators.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 Oct 29, 2017
Create a map of sets in Elm
View DictOfSets.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 Oct 10, 2017
Compare loading a text resource via classpath or file
View loadResource.kts
// 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}")
You can’t perform that action at this time.