Skip to content

Instantly share code, notes, and snippets.

@hkrutzer
hkrutzer / azure-ad-ssh.sh
Created July 6, 2025 11:17
Auto renew Azure AD SSH certificate for Ansible
#!/usr/bin/env bash
#
# Transparent Azure-AD SSH for Ansible
#
# * Generates / refreshes the Azure AD user certificate on-demand
# * Falls back to plain OpenSSH for the real connection
# * Can be invoked in parallel by many Ansible forks (uses a lock)
#
set -euo pipefail
@hkrutzer
hkrutzer / sse.exs
Created December 9, 2024 10:31
Elixir Phoenix SSE
Application.put_env(:phoenix, :json_library, Jason)
Application.put_env(:sample, SamplePhoenix.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
adapter: Bandit.PhoenixAdapter,
secret_key_base: String.duplicate("a", 64)
)
Application.put_env(:mime, :types, %{
@hkrutzer
hkrutzer / elixir_term_to_json.ex
Created November 19, 2024 10:04
Converting Elixir data structures to JSON and back
e = {1, 2, 3}
e2 = [1, 2, 3]
test_data = [
e,
e2,
{{{:ok, "http_response"}, nil}},
URI.parse("//elixir-lang.org/"),
%{this_is: %{cool: true}}
]
@hkrutzer
hkrutzer / check_routes.ex
Created August 1, 2024 10:41
Elixir Phoenix check for routes to non-existing functions
defmodule Mix.Tasks.CheckRoutes do
use Mix.Task
@shortdoc "Checks for mismatched routes and controller functions"
def run(_) do
# Load the router module
router_module = YourRouter
# Get all routes
routes = router_module.__routes__()
@hkrutzer
hkrutzer / apt_outdated.py
Created August 29, 2022 17:17
Datadog check for apt outdated packages
from datadog_checks.base import AgentCheck
from datadog_checks.base.utils.subprocess_output import get_subprocess_output
__version__ = "0.0.1"
class AptOutdatedCheck(AgentCheck):
def check(self, instance):
stdout, package_counts, retcode = get_subprocess_output("/usr/lib/update-notifier/apt-check", self.log, raise_on_empty_output=False)
outdated_total, outdated_security = package_counts.split(';')
self.gauge("apt.package.outdated.count", int(outdated_total), tags=['kind:total'] + self.instance.get('tags', []))
@hkrutzer
hkrutzer / ssh_split.py
Created December 1, 2020 13:18
Connect to multiple SSH servers in iTerm split panes for use with iTerm broadcasting
#!/usr/bin/env python3
#
# Connect to multiple SSH servers in iTerm split panes for use with iTerm broadcasting.
#
# Read https://iterm2.com/python-api/tutorial/running.html#command-line for how to run this;
# something like
# $ ~/Library/Application\ Support/iTerm2/iterm2env-3.7/versions/3.7.9/bin/python3 ~/Library/Application\ Support/iTerm2/Scripts/ssh_split.py server1 server2 server3
#
import argparse
@hkrutzer
hkrutzer / devserver.js
Created December 12, 2017 14:17
Serve static HTML and proxy /api
const httpProxy = require('http-proxy');
const connect = require('connect');
const serveStatic = require('serve-static');
const PORT = (process.env.PORT || 3100);
const staticDir = './public';
const proxy = new httpProxy.createProxyServer();
const app = connect();
@hkrutzer
hkrutzer / gist:d5acc94cd1dc2e378ab8
Created May 1, 2015 13:13
[git] Restore delete files of a certain type
git reset HEAD^ -- (git diff HEAD^ --diff-filter=D --name-only --pretty="format:" | grep -e '\.png' -e '\.gif' -e '.\jpg' -e '.\jpeg')