Save this to ~/.local/bin/claude-local-mode
#!/usr/bin/env bash
set -euo pipefail
SETTINGS="$HOME/.claude/settings.json"| #!/bin/bash | |
| DB_NAME="your_database_name" | |
| INTERVAL=5 # seconds between samples | |
| previous_count=0 | |
| while true; do | |
| current_count=$(psql -d $DB_NAME -t -c "SELECT tup_inserted + tup_updated + tup_deleted FROM pg_stat_database WHERE datname = '$DB_NAME';") | |
| -- More info: https://www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-MONITORING | |
| -- run on primary | |
| SELECT application_name,state,sync_state,client_addr,client_hostname, | |
| pg_wal_lsn_diff(pg_current_wal_lsn(),sent_lsn) AS sent_lag, | |
| pg_wal_lsn_diff(sent_lsn,flush_lsn) AS receiving_lag, | |
| pg_wal_lsn_diff(flush_lsn,replay_lsn) AS replay_lag, | |
| pg_wal_lsn_diff(pg_current_wal_lsn(),replay_lsn) AS total_lag, | |
| now()-reply_time AS reply_delay | |
| FROM pg_stat_replication; |
| #!/bin/bash | |
| PROJECT_ID=... | |
| # we might have to update this value from time to time | |
| CLOUD_SQL_AUTH_PROXY_VERSION=2.13.0 | |
| # The arrays INSTANCES, REGIONS, PORTS should have the same length, value at index i is used for the i-th instance | |
| # Put the list of cloud sql instance names here, e.g. master and the replicas | |
| declare -a INSTANCES=("instance-name-1" "instance-name-2") |
| -- logical replica in postgresql won't have their sequence values updates | |
| -- this can be used to sync sequence values if needed | |
| -- to actually run the command uncomment the "EXECUTE setval_sql;" line | |
| DO $$ | |
| DECLARE | |
| seq_record RECORD; | |
| max_val BIGINT; | |
| setval_sql TEXT; | |
| BEGIN |
| # Add postgres repo | |
| # https://wiki.postgresql.org/wiki/Apt | |
| sudo apt install curl ca-certificates | |
| sudo install -d /usr/share/postgresql-common/pgdg | |
| sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc | |
| # Note: we have to use apt-archive since the repos for old distros like ubuntu 18 (bionic) are archived | |
| sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt-archive.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | |
| sudo apt update |
| module HashSchemaValidator | |
| def self.valid?(object, schema) | |
| schema.all? do |key, type| | |
| if type.instance_of?(Hash) | |
| valid?(object[key], type) | |
| elsif type.instance_of?(Class) | |
| object[key].instance_of?(type) | |
| elsif type.instance_of?(Array) | |
| type[0].instance_of?(Class) ? object[key].all? { |element| element.instance_of?(type[0]) } : type.include?(object[key]) | |
| else |
| # https://datatracker.ietf.org/doc/html/rfc6238 | |
| # Secret can only use characters in BASE32_CHARS | |
| module TOTP | |
| def self.totp(secret, interval = 30, time = nil) | |
| time ||= Time.now | |
| time_steps = time.to_i / interval | |
| hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha1"), self.base32_decode(secret), [time_steps].pack(">q").reverse) |
cd ~/.ssh
ssh-keygen -t rsa -C "first_account@email.com" -f "github-first-account"
ssh-keygen -t rsa -C "second_account@email.com" -f "github-second-account"| eval(" | |