Skip to content

Instantly share code, notes, and snippets.

View mike-weiner's full-sized avatar

Michael Weiner mike-weiner

View GitHub Profile
@mike-weiner
mike-weiner / jots
Last active October 20, 2025 20:18
A tool to quickly create a new Markdown file in a given directory and open it with TextMate.
#!/bin/bash
# ------------------------------------------------------------------------------------------------------------------
# jots
#
# A tool to quickly create a new Markdown file in a given directory and open it with TextMate.
# Jots will be created with the naming scheme: yyyymmdd-<name>.md
#
# This script was inspired by https://github.com/tobi/try.
#
@mike-weiner
mike-weiner / k8s-registry-credential-secret.sh
Created September 26, 2025 19:57
Instructions for creating a Kubernetes Docker Configuration secret to pull container images from a private registry.
# Optional: Delete Existing Registry Credential
kubectl delete secrets -n <NAMESPACE> <SECRET-NAME>
# Create Docker Config Secret
kubectl create secret generic -n <NAMESPACE> <SECRET-NAME> \
--type=kubernetes.io/dockerconfigjson \
--from-file=.dockerconfigjson=/path/to/config.json
# /path/to/config.json should be in the format shown below.
# [REDACTED] should be your base64 encoded credentials.
@mike-weiner
mike-weiner / k8s-rollout-restart-all-deployments-in-namespace.sh
Last active September 26, 2025 19:57
Snippet to trigger a rolling restart of all deployments in a namespace.
# This snippet is used to do a rolling restart on all Kubernetes
# deployments in a namespace.
# Replace `<NAMESPACE>` with your desired namespace.
NS=<NAMESPACE>
kubectl get deployments -n "$NS" -o name | grep -v "<EXCLUDE-THIS-DEPLOYMENT>" | while read -r d; do
kubectl rollout restart -n "$NS" "$d"
sleep 0.1
done
@mike-weiner
mike-weiner / validate-tls-server-cert-and-key.md
Created September 24, 2025 00:09
Instructions to validate that a server's TLS certificate and key are a valid pair.

Validate TLS Server Certificate and Key Pair

This command starts a simple TLS/SSL server using OpenSSL.

openssl s_server -key server.key -cert server.crt -accept 8443

If the command runs successfully without errors, it indicates that the server key and certificate match and are valid. You can test the secure connection using:

@mike-weiner
mike-weiner / ssh-proxy.go
Last active August 31, 2025 18:38
A very basic SSH proxy using Go to simulate a client connection sending a TCP RST.
// Replace `<server-ip>` with your real endpoint.
// Use `go run ssh-proxy.go` for a healthy proxy.
// Use `go run ssh-proxy.go --broken` for a proxy that closes the connection.
package main
import (
"flag"
"io"
"log"
@mike-weiner
mike-weiner / ibmcloud-token-fetch.sh
Created July 14, 2025 12:59
A shorthand to fetch an IBM Cloud Access Token and store it in a shell environment variable.
export TOKEN=$(ibmcloud iam oauth-tokens | awk '{print $4}')
@mike-weiner
mike-weiner / base64-encode-no-newline.sh
Created June 12, 2025 19:05
The following command is used to base64 encode a string on macOS without a trailing newline that vim has as a "feature."
echo -n "<YOUR-CONTENT-TO-ENCODE>" | base64 -b 0
@mike-weiner
mike-weiner / custom-dns-resolver.go
Created January 19, 2025 01:08
A small Go snippet demonstrating how to use a custom DNS resolver to lookup IPs.
package main
import (
"context"
"fmt"
"net"
"time"
)
func main() {
@mike-weiner
mike-weiner / slack.sh
Created January 5, 2025 01:58
A simple Bash script that can be used to send Slack messages via curl to a Slack Channel using the Slack Block API.
#!/bin/bash
SLACK_CHANNEL="automation"
SLACK_URL="https://slack.com/api/chat.postMessage"
AS_USER=true
slackMsgHeaderBlock=$(
jq -n '{
type: "rich_text",
elements: [
@mike-weiner
mike-weiner / basic-linux-security.md
Last active January 23, 2025 02:04
An explanation of how to do basic security hardening of a Linux box.

Basic Linux Server Hardening

This document is meant to serve as a basic guide for hardening a Linux server.

Change Default Port Used by SSH

  1. sudo nano /etc/ssh/sshd_config
  2. Uncomment #Port 22 and change it to Port <SSH_PORT>. (Replace <SSH_PORT> with your desired port to use for SSH connectivity.)
  3. sudo systemctl restart ssh
  4. reboot