Skip to content

Instantly share code, notes, and snippets.

View cnnrrss's full-sized avatar
🕶️

Connor Vanderhook cnnrrss

🕶️
View GitHub Profile
pods() {
command='kubectl get pods --all-namespaces' fzf \
--info=inline --layout=reverse --header-lines=1 \
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
--header $'╱ Enter (kubectl exec) ╱ CTRL-O (open log in editor) ╱ CTRL-R (reload) ╱\n\n' \
--bind 'start:reload:$command' \
--bind 'ctrl-r:reload:$command' \
--bind 'ctrl-/:change-preview-window(80%,border-bottom|hidden|)' \
--bind 'enter:execute:kubectl exec -it --namespace {1} {2} -- bash' \
--bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --all-containers --namespace {1} {2})' \
@cnnrrss
cnnrrss / find_empty.sql
Created February 20, 2024 19:20
Find empty tables in Postgres
SELECT
t.tablename
FROM
pg_catalog.pg_tables t
LEFT JOIN pg_stat_user_tables stat ON t.tablename = stat.relname
WHERE
t.schemaname = 'public' -- Adjust this to your schema name if different
AND stat.n_live_tup = 0;
@cnnrrss
cnnrrss / main.go
Created February 3, 2024 19:00
Simple http server
package main
import (
"context"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"""High-level support for working with threads in asyncio"""
import asyncio
import contextvars
import functools
async def run_in_thread_async(executor, func, *args, **kwargs):
"""https://github.com/python/cpython/blob/main/Lib/asyncio/threads.py"""
loop = asyncio.get_running_loop()
ctx = contextvars.copy_context()
@cnnrrss
cnnrrss / django cheatsheet
Created February 21, 2023 11:03
Reference for Django
# *****************************************************************************
# CODING STYLE > MAKING YOUR CODE READABLE
# *****************************************************************************
# 1. Avoid abbreviating variable names.
# 2. Write out your function argument names.
# 3. Document your classes and methods.
# 4. Comment your code.
# 5. Refactor repeated lines of code into reusable functions or methods.
@cnnrrss
cnnrrss / main.go
Created February 9, 2023 11:41
1 buffered chan errgroup result handling
package main
import (
"context"
"fmt"
"golang.org/x/sync/errgroup"
)
func race(ctx context.Context) ([]int, error) {
import UIKit
import SwiftUI
import Firebase
import AVFoundation
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
@cnnrrss
cnnrrss / random-big-file
Created May 17, 2022 04:18
APFS containers grow while writing data, but the unarchiver won’t start writing data, because the container didn’t grow enough (yet)
dd if=/dev/urandom of=temp_20GB_file bs=1024 count=20971520
@cnnrrss
cnnrrss / Makefile
Last active May 10, 2022 01:23
Makefile template for an AWS Lambda with Go 1.x runtime
ORG := FT
TENANT := dev-cnnrrss
GIT_EMAIL := $(shell git config user.email)
ARTIFACTS_BUCKET := artifacts-$(TENANT)
PACKAGE=$(shell basename $(PWD))
SHORT_COMMIT := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git branch --show)
@cnnrrss
cnnrrss / sudoers.sh
Created March 11, 2022 03:12
avoid retyping your password for a sudo call, and allow no password sudo for a binary
sudo sh -c 'echo "%admin ALL=(ALL) NOPASSWD: /usr/local/bin/openconnect" > /etc/sudoers.d/openconnect'