Skip to content

Instantly share code, notes, and snippets.

View duboisf's full-sized avatar

Fred Dubois duboisf

View GitHub Profile
@duboisf
duboisf / sort.go
Last active September 24, 2025 19:30
Generic golang functions to do a unique sort of elements
package sort
// SortedUniqueFunc returns a sorted list of unique elements extracted from the input slice using the provided getter function.
func SortedUniqueFunc[T any, E cmp.Ordered](ts []T, get func(T) E) []E {
elems := make(map[E]struct{})
for _, t := range ts {
elem := get(t)
elems[elem] = struct{}{}
}
return slices.Sorted(maps.Keys(elems))

HOWTO: ammend a git commit with fixup instead of interactive rebase

I did some modifications to the AGENTS.md file in my GitHub repo and I want to add this change to the commit that added this file in my feature branch. Normally I would:

  • Stash my changes
  • Run git rebase -i main and mark the target commit with edit
  • When the rebase stops at the target commit, I would apply my stashed changes and amend the commit with git commit --amend
  • Finally, I would continue the rebase with git rebase --continue

But there is a much easier way to do this! I can use the --fixup option of git commit to create a new commit that will be automatically squashed into the target commit during a rebase.

@duboisf
duboisf / HOWTO-monitor-files-with-opensnoop-bpfcc.md
Last active September 18, 2025 13:43
HOWTO: Monitor file access with opensnoop-bpfcc

HOWTO: Monitor File Opens with opensnoop-bpfcc

opensnoop-bpfcc is a BPF-based monitoring tool that traces file open system calls in real-time. It's part of the BCC (BPF Compiler Collection) toolkit and provides detailed visibility into which processes are opening files on your system.

I find it easier to use than strace, it gives simple output.

Usage

The command shown monitors all file opens by processes containing "go" in their name:

@duboisf
duboisf / example.md
Created August 28, 2025 19:46
Use kubectl get --raw to connect to a pod using reverse proxy
kubectl get --raw /api/v1/namespaces/argocd/pods/argocd-server-75db8b479f-fpc48:8083/proxy/metrics | grep argocd_info   
# HELP argocd_info ArgoCD version information
# TYPE argocd_info gauge
argocd_info{version="v2.14.9+38985bd"} 1
@duboisf
duboisf / aws_athena_cur_query.sql
Last active July 29, 2025 20:00
AWS EKS per deployment costs
-- Note: pods that aren't part of a deployment will be summed up together
-- I _think_ this gives total cost per pod.........
-- Ref: https://docs.aws.amazon.com/cur/latest/userguide/example-split-cost-allocation-data.html
SELECT
ELEMENT_AT(resource_tags, 'aws_eks_cluster_name') AS eks_cluster,
ELEMENT_AT(resource_tags, 'aws_eks_namespace') AS namespace,
ELEMENT_AT(resource_tags, 'aws_eks_deployment') AS deployment,
ROUND(SUM(split_line_item_split_cost), 2) AS split_cost,
ROUND(SUM(split_line_item_unused_cost), 2) AS split_unused_cost,
ROUND(SUM(split_line_item_split_cost) + SUM(split_line_item_unused_cost), 2) as total_cost
@duboisf
duboisf / kube_search_api_resources.zsh
Created July 24, 2025 15:20
zsh function to search for kubernetes resources across clusters
emulate -RL zsh
setopt err_return warn_create_global
local API_RESOURCE="$1"
local ctx
local kind
if [[ -z "$API_RESOURCE" ]]; then
print "Usage: kubectl_search_api_resources <API_RESOURCE>" >&2
print "Will search for the api resources that match the regex API_RESOURCE in all clusters and all namespaces" >&2
@duboisf
duboisf / used-images-in-kubernetes-cluster.nu
Last active July 22, 2025 14:51
Find all images used in the current kubernetes cluster with image sizes
kubectl get no -o json
| from json
| get items
| select status.images status.nodeInfo.architecture
| rename images arch
| flatten
| update images.names { |in|
if ($in | length) > 1 {
$in | filter { $in !~ @sha }
} else {
@duboisf
duboisf / gh-changelog.md
Created June 11, 2025 17:15
Generate a changelog on the fly for a github repo based on releases with nu and the gh cli

In nushell, you can generate a changelog on the fly with the following:

gh release list --json name
| from json
| get name
| par-each --keep-order { |name|
    gh release view $name --json name,body,author
    | from json
 | $"# ($in.name) by ($in.author.login)\n\n($in.body)"

Troubleshooting Redis StatefulSet: Clearing Data from a PVC When Pods Are Crashlooping

The Problem

I encountered an issue with a Redis StatefulSet in our staging environment where the pods were stuck in a crashloop. The root cause was a full Persistent Volume Claim (PVC) that had run out of space. Since this was cache data in a staging environment, I needed to clear the /data folder to resolve the issue.

The challenge was that I couldn't exec into the pod directly because the Redis container was continuously crashlooping, making standard troubleshooting approaches impossible.

The Solution

@duboisf
duboisf / enable-scan-on-push.nu
Created May 27, 2025 19:58
Enable scan on push for all AWS ECR repositories that don't have it enabled, in nushell
aws ecr describe-repositories | from json | get repositories.repositoryName
| sort
| each { |repo|
let scanOnPush = (aws ecr batch-get-repository-scanning-configuration --repository-names $repo
| from json
| get scanningConfigurations
| first
| get scanOnPush
)
print $"Repository: ($repo), Scanning on push: ($scanOnPush)"