Skip to content

Instantly share code, notes, and snippets.

@joaocc
joaocc / .mateuszwenus--save_restore_dependencies.sql
Last active October 25, 2023 07:28 — forked from mateuszwenus/save_restore_dependencies.sql
PostgreSQL: How to handle table and view dependencies
Forked from https://gist.github.com/mateuszwenus/
@joaocc
joaocc / README.md
Created March 15, 2023 21:25 — forked from forivall/README.md
git-credential-manager reaper script

Simple background script to kill git-credential-manager when it hits the 100% cpu bug

@joaocc
joaocc / UUID_v7_for_Postgres.sql
Created February 7, 2023 18:18 — forked from kjmph/A_UUID_v7_for_Postgres.sql
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
declare
unix_ts_ms bytea;
uuid_bytes bytea;
begin
unix_ts_ms = substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3);
@joaocc
joaocc / check_multi_namespaces.sh
Last active March 27, 2022 11:03 — forked from lisawolderiksen/secrets_without_certificates.sh
Script to detect "orphaned" TLS secrets when Cert manager (cainjector) complains about "unable to fetch certificate that owns the secret", because deleting a Certificate will not (default) delete the Secret. (Ref. https://cert-manager.io/docs/usage/certificate/#cleaning-up-secrets-when-certificates-are-deleted)
#!/usr/bin/env bash
set -eo pipefail
set -x
while [ "$1" != "" ]
do
bash secrets_without_certificates.sh -n "$1"
shift
done
@joaocc
joaocc / acr-cleanup.sh
Created February 4, 2022 18:49
Cleaning up AzureML images from Azure Container Registry (ACR)
ACR_NAME="${ACR_NAME:-myacr}"
az acr show-usage -n "${ACR_NAME}" -o json
DK_IMAGES=(
"azureml/azureml_00000000111111110000000011111111"
"azureml/azureml_11111111000000001111111100000000"
)
for i in "${DK_IMAGES[@]}"
do
@joaocc
joaocc / AzureAD-Get-AAD-Roles.ps1
Created November 11, 2021 17:46
AzureAD - list AAD role assignments
# https://arindamhazra.com/list-azure-ad-roles-and-role-assignments/
Connect-AzureAD
$allAZADUserWithRoleMapping = @()
# Get all Azure AD roles and loop through members of those roles
# Add user/service principal details in psObject array
Get-AzureADDirectoryRoleTemplate | ForEach-Object{
$roleName = $_.DisplayName
@joaocc
joaocc / gist:3ca400e0750556597dc86fe1f341d123
Created October 29, 2021 12:28
Removing Auxiliary kexts in macOS bigSur+
# USE WITH CARE... NO WARRANTIES!!!
# THESE ARE NOTES ON HOW TO CLEANUP OR REMOVE SOME KEXTS
# AS A MATTER OF FACT, YOUR SYSTEM MAY START MALFUNCTIONING
# IF YOU DO FOLLOW THIS WITHOUT UNDERSTANDING WHAT YOU ARE DOING
(after the disclaimer, just some notes for my future reference)
(glad if they help you, but taking no responsibility)
this came across as the need to cleanup some Auxiliary Kernel Collection (AuxKC)
* com.samsung.portablessd.driver
@joaocc
joaocc / info.md
Created October 29, 2021 12:19
macOS high CPU usage from kernelmanagerd / com.apple.applefsplaceholder

Reference info

macOS 11.6.1 (20G224) (bigSur) on ARM M1

The following will be running stuff every minute

sudo kmutil log stream

Info here:

@joaocc
joaocc / inf_refresh_recursive.sql
Created March 4, 2019 00:45 — forked from bitdivine/inf_refresh_recursive.sql
Refresh postgres materialized views recursively
-- Refresh materialized views recursively
-- DEPENDS:
-- List the tables that a view depends on.
-- Thanks to Dave: http://stackoverflow.com/questions/4229468/getting-a-list-of-tables-that-a-view-table-depends-on-in-postgresql
create or replace function inf_view_dependencies(v text)
returns table (kind text, name text) as $$
SELECT cl_d.relkind::text as kind
, cl_d.relname::text AS name
FROM pg_rewrite AS r
@joaocc
joaocc / fulldump.sh
Created March 4, 2019 00:44 — forked from marcolino/fulldump.sh
Postgres full dump script
#!/bin/bash
# $Id: fulldump.sh,v 1.4 2013/10/31 14:25:36 postgres Exp postgres $
# $Source: /var/lib/postgresql/8.2/RCS/fulldump.sh,v $
# $Log: fulldump.sh,v $
#
# Revision 1.4 2013/10/31 14:25:36 postgres
# Removed pg_dump '-D' option, added $RETVAL
# default value for the initial case - MS.
#
# Revision 1.3 2007/09/28 13:29:07 postgres