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 / pico2_risk_sdk_setup.sh
Last active August 30, 2024 20:05
Pico2 SDK setup for RISC-V
# https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf
# 2.10. Supporting both RP2040 and RP2350 (Page 31)
sudo apt install -y autoconf automake autotools-dev curl python3 python3-pip \
libmpc-dev libmpfr-dev libgmp-dev gawk build-essential \
bison flex texinfo gperf libtool patchutils bc \
zlib1g-dev libexpat1-dev ninja-build git cmake libglib2.0-dev libslirp-dev
sudo mkdir -p /opt/riscv/gcc14-rp2350-no-zcmp
sudo chown -R $(whoami) /opt/riscv/gcc14-rp2350-no-zcmp
@siberex
siberex / macos_open_ports.sh
Created August 13, 2024 15:10
macos_open_ports.sh
# https://x.com/seldo/status/1823126087423099192
sudo lsof -iTCP -sTCP:LISTEN -n -P | awk 'NR>1 {print $9, $1, $2}' | sed 's/.*://' | while read port process pid; do echo "Port $port: $(ps -p $pid -o command= | sed 's/^-//') (PID: $pid)"; done | sort -n
@siberex
siberex / get_onvif_streams.sh
Created August 9, 2024 21:37
Get ONVIF streams
# https://superuser.com/a/1711576/1129367
# sudo apt install -y curl libxml2-utils
FRIGATE_RTSP_PASSWORD="admin"
curl -u "admin:${FRIGATE_RTSP_PASSWORD}" --anyauth -X POST "http://10.0.0.2:8000/onvif/device_service" \
-H 'Content-Type: application/soap+xml; charset=utf-8'\
-H 'SOAPAction: "http://www.onvif.org/ver10/media/wsdl/GetProfiles"'\
-d '
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsdl="http://www.onvif.org/ver10/media/wsdl">
@siberex
siberex / toggle-wvkbd.sh
Last active June 28, 2024 21:01
Raspberry Pi onscreen keyboard
#!/bin/bash
# apt install -y wvkbd
PID="$(pidof wvkbd-mobintl)"
if [ "$PID" != "" ]; then
killall wvkbd-mobintl
else
wvkbd-mobintl -L 300 --landscape-layers full,special
fi
ps aux | grep chrom | grep -v grep | awk '{print $2}' | xargs sudo kill -9
@siberex
siberex / update_cloudflare_record.sh
Last active August 8, 2024 23:15
Updates A-record to specified IP with CloudFlare API
#!/usr/bin/env bash
set -euo pipefail
API_BASEURL="https://api.cloudflare.com/client/v4"
# https://dash.cloudflare.com/profile/api-tokens
# DNS:Edit
CF_TOKEN="$(cut -d '=' -f2 < $HOME/.cloudflare.auth | xargs)"
INTERNAL_IP="$(tailscale ip -4)"
HOSTNAME="home.sib.li"
@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 / 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 / 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"