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 / 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"
@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 / idea.indexes.sh
Last active January 11, 2022 18:07
Generate IntelliJ IDEA Shared Indexes and serve generated CDN structure locally
#!/usr/bin/env bash
set -euo pipefail
# https://www.jetbrains.com/help/idea/shared-indexes.html
# USAGE:
# idea.indexes.sh /path/to/project/dir
CDN_ROOT="$HOME/_idea_cdn"
mkdir -p "$CDN_ROOT"
@siberex
siberex / cli-spinner.md
Last active August 24, 2021 19:20
CLI spinner fun

How it started:

let i = 0,
    spin = () => process.stdout.write(`  ${[...'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'][i++ % 10]}\r`),
    stop = (id => () => clearInterval(id))(setInterval(spin, 100));

And I simply could not resist from sticking generator in it:

@siberex
siberex / _setup_gcloud.sh
Last active June 11, 2021 15:18
Script to setup service account for Google App Engine deployment (for GitHub Actions or any other CI)
#!/usr/bin/env bash
# Usage: _setup_gcloud.sh [PROJECT_ID]
set -euo pipefail
BASEDIR="$(
cd "$(dirname "$0")" || true
pwd -P
)"
@siberex
siberex / adventofcode.2019.md
Last active December 6, 2020 21:52
Advent of code 2019

1: The Tyranny of the Rocket Equation

let input = await fetch('https://adventofcode.com/2019/day/1/input').then(r => r.text());
input = input.split('\n').filter(Boolean);

// Part 1
@siberex
siberex / adventofcode.2020.md
Last active December 18, 2020 14:49
Advent of code 2020

1: Report Repair

input = input.split('\n').map(v => parseInt(v));
for (let i = 0; i < input.length; i++) {
  const a = input[i];
  for (let j = i + 1; j < input.length; j++) {