Skip to content

Instantly share code, notes, and snippets.

View detj's full-sized avatar
🖥️
deep into work

Debjeet Biswas detj

🖥️
deep into work
View GitHub Profile
@detj
detj / homebrew-package-disk-usage.sh
Last active October 11, 2025 13:26
List disk usage by homebrew packages
# Usage by formulae
echo "=== Formulae ==="
du -sh $(brew --cellar)/* 2>/dev/null | sort -h
# Usage by casks
echo "=== Casks ==="
du -sh /opt/homebrew/Caskroom/* 2>/dev/null | sort -h
@detj
detj / list-roles-predefined-role.sh
Last active October 8, 2025 19:52
List IAM roles for a predefined role
# List all the roles for a predefined role
#
# gcloud iam roles describe [PREDEFINED_ROLE]
gcloud iam roles describe roles/owner
gcloud iam roles describe roles/editor
gcloud iam roles describe roles/viewer
@detj
detj / read-x509.sh
Created October 8, 2025 12:32
Read an x509 certificate
# assuming the certificate is in a file at /tmp/cert.txt
cat /tmp/cert.txt | openssl x509 -text -noout
@detj
detj / isObject.js
Created October 2, 2025 09:57
isObject(something)
// Check if 'something' is just a plain JavaScript object
// like a map of keys and values.
function isObject(something) {
const type = Object.prototype.toString.call(something);
return something === Object(something) && type !== "[object Array]" && type !== "[object Function]" && type !== "[object Date]" && type !== "[object RegExp]" && type !== "[object Set]" && type !== "[object Map]";
}
// truthy
console.log("{}", isObject({}));
console.log("Object.create(null)", isObject(Object.create(null)))
@detj
detj / manage-gcloud-regions.sh
Last active September 29, 2025 06:26
Google Cloud Regions and Zones
# List all Google Cloud regions and zones
#
# It may ask to enable the [compute.googleapis.com] API if it has not been enabled earlier.
gcloud compute zones list
# List all Google Cloud zones of a region
gcloud compute zones list | rg us-central
# Set the default region for a configuration
gcloud config set compute/region REGION_NAME
@detj
detj / gcloud-configurations.sh
Created September 29, 2025 05:55
Manage Google Cloud CLI Configurations
# List all configurations
gcloud config configurations list
# Activate a configuration
gcloud config configurations activate CONFIGURATION_NAME
# Rename a configuration
gcloud config configurations rename CONFIGURATION_NAME --new-name=NEW_NAME
@detj
detj / list-gcloud-enabled-services.sh
Last active October 8, 2025 19:50
List Enabled Google Cloud Services
# List all the enabled Google Cloud APIs
gcloud services list --enabled
@detj
detj / delete-unused-revisions.sh
Last active September 23, 2025 14:00
Delete unused Cloud Run revisions
# This command keeps the last 5 revisions and deletes the rest.
# --quiet - do not prompt for (Y/n)
# Replace <name> with the name of of the Cloud Run service
#
# Depending on the count of unused revisions this operation will
# take a few minutes to complete.
gcloud run revisions list --service=<name> --format="value(metadata.name)" | tail -n +6 | xargs -n1 gcloud run revisions delete --quiet
@detj
detj / drop_connections.sql
Created September 17, 2025 15:07
Drop all Postgres connections
-- Drop all connections except the one running this query
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'measure'
AND pid <> pg_backend_pid();
@detj
detj / current-git-tag.sh
Created August 31, 2025 16:21
current git tag
#!/usr/bin/env bash
git describe --tags --abbrev=0