Skip to content

Instantly share code, notes, and snippets.

View sunsided's full-sized avatar
🇺🇦
#StandWithUkraine

Markus Mayer sunsided

🇺🇦
#StandWithUkraine
View GitHub Profile
@sunsided
sunsided / purge-schemata.sql
Last active August 24, 2024 18:56
Delete all tables, functions and triggers from all schemata in a PostgreSQL database
DO $$
DECLARE
r RECORD;
s RECORD;
BEGIN
-- Loop through all non-system schemas
FOR s IN (SELECT schema_name FROM information_schema.schemata
WHERE schema_name NOT IN ('pg_catalog', 'information_schema', 'public')
AND schema_name NOT LIKE 'pg_%') LOOP
@sunsided
sunsided / dynamic_type_construction.rs
Last active June 7, 2024 22:27
Dynamically and iteratively combine arbitrary types in Rust. Makeshift variadic generics, anyone?
/// The base type acts as a stop token.
struct Base;
/// The wrapped type, defined in terms of the wrapped base `B` and the new value `T`.
/// You can stuff it with references and live without lifetime definitions on the type.
struct Wrapped<B, T>(B, T);
impl Base {
pub fn new(value: &str) -> Wrapped<Self, &str> {
Wrapped(Base, value)
@sunsided
sunsided / git-merge-orphan-branches.sh
Last active February 19, 2024 20:57
Git tricks to merge orphan branches
# Merge an orphan branch and overwrite our changes ("take theirs").
git merge --allow-unrelated-histories -Xtheirs $ORPHAN_BRANCH
# List all files existing in branch "timeline" that do not exist in branch "$ORPHAN_BRANCH"
git diff-tree -r --diff-filter=D --name-only timeline $ORPHAN_BRANCH
# ... and delete them
git diff-tree -r --diff-filter=D --name-only timeline $ORPHAN_BRANCH | xargs -d '\n' git rm
@sunsided
sunsided / gp
Last active February 14, 2024 12:45
Kubernetes Pod Watching Scripts
#!/usr/bin/env bash
# See https://gist.github.com/sunsided/af8a90b0700917b5f16cf6f4ebb49dcb
set -euo pipefail
# check if stdout is a terminal...
#if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput -T ansi bold)"
@sunsided
sunsided / 50-usb-power-save.rules
Last active January 21, 2024 20:04
/etc/udev/rules.d/50-usb-power-save.rules
# Added for AV Access KVM switch
# deactivate USB power management
# QinHeng Electronics WCH UART TO KB-MS_V1.7displ
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="e229"
# QinHeng Electronics CH340 serial converter
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="7523"
# C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0d8c", ATTR{idProduct}=="0014"
@sunsided
sunsided / trivy-sbom-local
Last active January 12, 2024 19:03
Create SBOMs in SPDX and CycloneDX format for a local repository
#!/usr/bin/env bash
set -euo pipefail
CACHE=$(realpath ~/.cache/trivy)
if [ $# -eq 0 ]; then
echo "Please specify a local repository to scan."
exit 1
else
REPO=$(realpath $1)
cargo crev trust --level low https://github.com/sunsided/crev-proofs
@sunsided
sunsided / cargo crev review
Created December 7, 2023 15:17
cargo crev review
# Package Review of some-package 0.1.2
review:
thoroughness: low
understanding: medium
rating: positive
flags:
unmaintained: false
alternatives:
- source: https://crates.io
name: ''
@sunsided
sunsided / cargo crev verify.sh
Created December 7, 2023 15:06
cargo crev verify
$ cargo crev verify --show-all
status reviews issues owner downloads loc lpidx geiger flgs crate version latest_t
pass 1 3 0 0 0 2 17226K 183779K 870 178 101 ____ once_cell 1.8.0 ↑1.16.0
none 0 0 0 0 2 2 2807K 61575K 3371 57 1137 ____ bumpalo 3.8.0
none 0 2 0 0 0 1 8038K 125055K 5595 57 0 CB__ typenum 1.14.0 ↓1.11.2
pass 1 1 0 0 1 2 7059K 126074K 323 239 32 CB__ futures-core 0.3.17 =
none 0 2 0 0 1 1 35346K 197798K 4814 79 2193 CB__ memchr 2.4.1 ↓2.2.1
pass 3 8 0 0 1 2 167548K 192133K 134 418 8 ____ lazy_static 1.4.0 =
pass 1
@sunsided
sunsided / cargo crev repo fetch all.sh
Last active December 7, 2023 15:48
cargo crev repo fetch all
$ cargo crev repo fetch all
Fetching...
https://github.com/dpc/crev-proofs no updates
https://github.com/matklad/crev-proofs no updates
https://github.com/nbigaouette-eai/crev-proofs no updates
https://github.com/kornelski/crev-proofs no updates
https://github.com/toidiu/crev-proofs no updates
https://github.com/apoelstra/crev-proofs no updates
...