Skip to content

Instantly share code, notes, and snippets.

View siberex's full-sized avatar
🛠️
Your stack will not be full without me

Stepan Legachev siberex

🛠️
Your stack will not be full without me
View GitHub Profile
@siberex
siberex / update_cloudflare_record.sh
Created May 20, 2024 01:04
Updates A-record to specified IP with CloudFlare API
#!/usr/bin/env bash
set -euo pipefail
API_BASEURL="https://api.cloudflare.com/client/v4"
CF_TOKEN="$(cut -d '=' -f2 < $HOME/.cloudflare.auth | xargs)"
INTERNAL_IP="$(tailscale ip -4)"
HOSTNAME="home.sib.li"
ZONE_NAME="$(echo "$HOSTNAME" | rev | cut -d '.' -f1,2 | rev)"
@siberex
siberex / rpi.temperature.sh
Last active April 21, 2024 09:17
Raspberry Pi temperature monitor
#!/bin/bash
printf '%(%Y-%m-%d %H:%M:%S)T\n' -1
# Note rPi CPU and GPU are on the same chip, and GPU don't hanve any separate temperature sensor
# vcgencmd and sysfs provide the same data
cpu_temp_sysfs=$(</sys/class/thermal/thermal_zone0/temp)
echo "vcgencmd => $(vcgencmd measure_temp | grep -o -E '[[:digit:]].*')"
echo "sysfs => $((cpu_temp_sysfs/1000))'C"
@siberex
siberex / multiply_digits.js
Last active December 17, 2023 02:32
Single-digit multiplication is just a mapping of a set of 55 (distinct) values to a set of 37 (distinct) values
const multipliers = new Map();
const multiplications = new Set();
for (let i = 0; i < 10; i++) {
for (let j = i; j < 10; j++) {
const res = i * j;
multiplications.add(res);
multipliers.set(
i.toString() + j.toString(),
res,
@siberex
siberex / gcloud_billing_status.sh
Last active December 25, 2022 15:51
Google Cloud: List all projects with billing status
# List all projects with assigned billing and status
gcloud beta billing accounts list --format 'value(ACCOUNT_ID)' | while read -r BILLING_ACCOUNT_ID; do
gcloud beta billing projects list --billing-account "$BILLING_ACCOUNT_ID" --format 'value(PROJECT_ID, BILLING_ACCOUNT_ID, BILLING_ENABLED)'
done
# Check if billing is enabled for Project Id
GOOGLE_CLOUD_PROJECT=${1:-$(gcloud config list --format 'value(core.project)')}
function isBillingEnabled() {
GOOGLE_CLOUD_PROJECT=$1
@siberex
siberex / CloudFlare.md
Last active December 7, 2022 10:20
CloudFlare API cheatsheet

Get Token

CF_TOKEN="..."

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer $CF_TOKEN"
@siberex
siberex / generic.sh
Last active December 1, 2022 07:11
Generic bash script stuff
#!/usr/bin/env bash
# Exit script when command fails
set -o errexit
# Exit when script tries to use undeclared variable
set -o nounset
# Exit if piped command fails
set -o pipefail
# aka:
# set -euo pipefail
@siberex
siberex / find_node_modules.sh
Last active July 26, 2022 11:21
Find all top-level node_modules and show each folder size
find . -name 'node_modules' -type d -not -path '*/node_modules/*/node_modules' -exec du -hs '{}' \;
# alias find_node_modules="find . -name 'node_modules' -type d -not -path '*/node_modules/*/node_modules' -exec du -hs '{}' \;"
# Same with dist, excludiong vendored thirdparty-js :
# find . -name 'dist' -type d -not -path '*/thirdparty-js/*/dist' -exec du -hs '{}' \;
# find . -name 'node_modules' -type d -not -path '*/node_modules/*/node_modules' -not -path '*/thirdparty-js/*/node_modules' -exec du -hs '{}' \;
@siberex
siberex / cancelot.sh
Last active July 14, 2022 03:03
Provides automation for cancelling previous ongoing Cloud Builds for the same branch/trigger
#!/usr/bin/env bash
# https://github.com/siberex/cancelot
#
# To download the latest version (if you trust running random bash scripts from the internets!):
# curl -L https://gist.github.com/siberex/bb0540b208019382d08732cc6dd59007/raw -o cancelot.sh && chmod +x cancelot.sh
#
# Provides automation for cancelling Cloud Builds
# Use as a first step to cancel previous builds currently in progress or queued for the same branch name and trigger id.
# Similar to: https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/cancelot
@siberex
siberex / gae_list_projects_regions.sh
Last active June 25, 2022 01:23
Google App Engine: List all projects along with their regions and mapped domains
# App Engine: List all project regions and mapped domains
# Effectively:
# gcloud projects list --format 'get(PROJECT_ID)'
# gcloud app describe --project "$projectId" --format 'get(locationId)'
# gcloud app domain-mappings list --project "$projectId" --format 'get(ID)' | xargs | sed 's/ /, /g'
printf "%s\t%s\t%s\n" "ProjectId" "Region" "Domains"
gcloud projects list --format 'get(PROJECT_ID)' | while read -r projectId; do
region=$(gcloud app describe --project "$projectId" --format 'get(locationId)' 2>/dev/null || echo 'N/A')
@siberex
siberex / gen_honeypot_urls.sh
Last active May 5, 2022 03:29
Honeypot URLs
#!/usr/bin/env bash
# Retrieves list of files larger than 600 MB from linux distros mirror
# Saves maximum 10 random links for each distro in the output.txt file
# Usage:
# gen_honeypot_urls.sh
# or:
# gen_honeypot_urls.sh /path/to/out.txt
# Exit script when command fails