Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / kubectl_commands.sh
Last active July 25, 2022 13:12
kubectl commands #k8s #snippet
# Get logs for all pods with a given label
kubectl logs -f -l app=my-app-label
# Get pod labels
kubectl get pods --show-labels
# ^^^ can be messy, so if your app label is the name of the deployment,
# just list the deployments
kubectl get deployments
@rsperl
rsperl / convert_date.sh
Last active July 25, 2022 12:47
date conversions #bash #snippet
#!/usr/bin/env bash
# convert from timestamp to epoch: 1626459360
date -d '2021-07-16 14:16:00' +%s
@rsperl
rsperl / remove_keys.md
Last active July 25, 2022 12:49
Use jq to remove keys based on regex #snippet

Remove all entries that have a key ending in .comment:

echo '{"key": "value", "key.comment": "key comment"}'  | \
	jq '.|with_entries(select(.key|test(".\\.comment$")|not))'

gives

@rsperl
rsperl / flatten.md
Last active July 25, 2022 13:05
flatten json to dot notation #snippet

Given json data like

data='{
	"message":"List of orders",
    "data":[
    	{"siteNum":"70293591","siteName":"VIYA 4 TESTING RICHARD SUGG REQ RITM0288018","number":"9CMW3K","date":"2021-11-29T17:09:10-05:00","updateStatus":"noUpdateAvailable","features":[],"downloadStatus":"ok","accessRole":"owner"},
        {"siteNum":"70180938","siteName":"Richard test","number":"9CPWF3","date":"2022-04-19T12:24:42-04:00","updateStatus":"noUpdateAvailable","features":[],"downloadStatus":"ok","accessRole":"owner"},
        {"siteNum":"70180938","siteName":"testing viya 4 order","number":"09YYND","date":"2021-10-11T13:52:08-04:00","updateStatus":"noUpdateAvailable","features":[],"downloadStatus":"ok","accessRole":"user"},
        {"siteNum":"70180938","siteName":"viya 4 test 6 - 04aug21","number":"09XZF5","date":"2021-08-04T13:51:49-04:00","updateStatus":"updateAvailable","features":[],"downloadStatus":"ok","accessRole":"user"}
@rsperl
rsperl / escape.md
Last active July 25, 2022 13:06
escape strings in bash or zsh #snippet

Bash

Enter a line of Bash starting with a # comment, then run !:q on the next line to see what that would be with proper Bash escaping applied.

❯ bash
bash-5.1$ # this' string" has! bad ()[] chars in it:
bash-5.1$ !:q
'# this'\'' string" has! bad ()[] chars in it:'
bash: # this' string" has! bad ()[] chars in it:: command not found
@rsperl
rsperl / run_docker_container.py
Last active July 25, 2022 13:11
Run a docker container from python #docker #container #python #snippet
#!/usr/bin/env python3
import docker
import os
import sys
import base64
image = "registry.com/me/image:1.2.3"
CWD = os.path.abspath(os.path.dirname(__file__))
# DOCKER_HOST=unix://var/run/docker.sock
@rsperl
rsperl / get_oldest_file_or_dir.py
Last active July 25, 2022 15:51
get the latest file/directory #python #snippet
#!/usr/bin/env python3
import os
def get_newest(src_dir: str) -> str:
"""return the newest file or directory"""
full_path = [src_dir + "/" + item for item in os.listdir(src_dir)]
oldest = max(full_path, key=os.path.getctime)
return os.path.basename(oldest)
@rsperl
rsperl / embed_template.go
Last active July 25, 2022 15:51
embed templates #snippet
import (
"embed"
"html/template"
"bytes"
)
//go:embed templates/*
var templateFS embed.FS
func unescape(s string) template.HTML {
@rsperl
rsperl / make_snippet.py
Last active July 25, 2022 15:38
create a snippet for vscode #snippet
#!/usr/bin/env python3
import json
import os
import sys
from collections import OrderedDict
if len(sys.argv) != 4:
sys.exit(f"Usage: {sys.argv[0]} <name> <prefix> <path-to-body-file>")
@rsperl
rsperl / listen.go
Last active July 25, 2022 15:35
listen for signals #snippet
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)