Skip to content

Instantly share code, notes, and snippets.

View nickadam's full-sized avatar

Nick Vissari nickadam

View GitHub Profile
@nickadam
nickadam / redis-sentinel-local-cluster.sh
Created January 24, 2021 20:26
Launches a cluster with 3 nodes and 3 sentinel instances to demonstrate how automated redis failover and recovery behaves.
#!/bin/bash
PASSWORD="badpassword"
create_config(){
cat <<EOF > "${1}"
port 555"${2}"
sentinel monitor mycluster 127.0.0.1 7770 2
sentinel down-after-milliseconds mycluster 5000
sentinel failover-timeout mycluster 60000
sentinel parallel-syncs mycluster 1
@nickadam
nickadam / ps1_to_cmd.ps1
Created March 31, 2020 16:38
[ps1_to_cmd] Convert a multiline PS1 script to a single line cmd file #PowerShell
$s = Get-Content script.ps1 | Out-String
$j = [PSCustomObject]@{
"Script" = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($s))
} | ConvertTo-Json -Compress
$oneline = "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(('" + $j + "' | ConvertFrom-Json).Script)) | iex"
$c = [convert]::ToBase64String([System.Text.encoding]::Unicode.GetBytes($oneline))
("Powershell -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Encoded " + $c) | Out-File -Encoding Default script.cmd
@nickadam
nickadam / elasticsearch-kibana.yml
Created November 10, 2019 00:09
Elasticsearch three node cluster and kibana with security
version: '3.5'
services:
kibana:
image: docker.elastic.co/kibana/kibana:7.4.2
environment:
- ELASTICSEARCH_HOSTS=http://es01:9200
- ELASTICSEARCH_USERNAME=kibana
- ELASTICSEARCH_PASSWORD=agoodpassword
ports:
- target: 5601
@nickadam
nickadam / byers_wall.py
Created October 17, 2019 11:37
#ws281x #strangerthings
#!/usr/bin/env python3
import time
import random
from rpi_ws281x import PixelStrip, Color
import argparse
# LED strip configuration:
LED_COUNT = 50 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
@nickadam
nickadam / kibana-k8s.yml
Created October 10, 2019 11:32
Kibana on Kubernetes
apiVersion: kibana.k8s.elastic.co/v1alpha1
kind: Kibana
metadata:
name: hcpss
spec:
version: 7.2.0
nodeCount: 1
elasticsearchRef:
name: hcpss
@nickadam
nickadam / elasticsearch-k8s.yml
Last active October 10, 2019 11:52
Elasticsearch on Kubernetes
apiVersion: elasticsearch.k8s.elastic.co/v1alpha1
kind: Elasticsearch
metadata:
name: hcpss
spec:
version: 7.2.0
nodes:
- nodeCount: 3
config:
node.master: true
@nickadam
nickadam / Get-Subordinates.ps1
Created September 17, 2019 18:37
Get-Subordinates.ps1
function Get-Subordinates(){
param(
[Parameter(Mandatory=$True,
HelpMessage='The username of the person at the top of the org')]
[string]$Username,
[Parameter(Mandatory=$False,
HelpMessage='The level to traverse into the org, i.e. 1 = only include direct reports, -1 = all')]
[int]$Depth
)
@nickadam
nickadam / install_docker-ce.sh
Created July 31, 2019 11:26
Install docker-ce Ubuntu
#!/bin/bash
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
function List-Acls {
param (
$Path,
$Depth
)
$Depth = $Depth - 1
Get-ChildItem $Path | ForEach-Object{
$FullName = $_.FullName
$FilePath = $_.FullName -replace "^[^$]+\$\\"
$FileOrFolder = "File"
@nickadam
nickadam / copy_docker_secret.sh
Last active September 22, 2021 19:12
Copy a docker swarm secret between two clusters
#!/bin/sh
SRC="$1"
DST="$2"
SECRET_NAME="$3"
SLEEP=3
if [ "$SRC" = "localhost" ]
then
secret=$(docker service create --restart-condition=none --name copy_secret --secret $SECRET_NAME -d alpine cat /run/secrets/$SECRET_NAME >/dev/null; sleep $SLEEP; docker service logs --raw copy_secret; docker service rm copy_secret>/dev/null)