Skip to content

Commit

Permalink
2025-01-30 17:12:22.705384 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Jan 30, 2025
1 parent f0dcfa6 commit feb11d9
Show file tree
Hide file tree
Showing 28 changed files with 1,260 additions and 795 deletions.
42 changes: 42 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
--------------------------------------------------------------------------------
2025-01-30 17:12:22.705384
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: snippet/Extreme_Value_Theory_1.py
deleted: snippet/Extreme_Value_Theory_2.py
deleted: snippet/Scraper Google Scholar Profiles.py
deleted: snippet/app.py
deleted: snippet/csf_release_no_packet_ip.sh
deleted: snippet/gcp_vertex_search_utils.py
deleted: snippet/single-number.py
deleted: snippet/test.java
deleted: snippet/vpn.sh

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/10-uname
snippet/20-raspberry-bitcoin
snippet/23-raspberry-lnd
snippet/26-raspberry-lightning
snippet/30-swap-warning
snippet/Dockerfile
snippet/automator.sh
snippet/azure-bastion-example.sh
snippet/code.java
snippet/deepseek_r1_web_app_grapio.py
snippet/docker-prone.sh
snippet/get_memory_size.py
snippet/main.go
snippet/morse_code.py
"snippet/na\303\257ve-rbp-btc.sh"
snippet/prep.sh
snippet/simple_task_usage.py
snippet/v2.py

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------
2025-01-29 17:12:39.499021
--------------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions seeker/snippet/10-uname
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#date: 2025-01-30T16:53:38Z
#url: https://api.github.com/gists/18b23955d3785c5b9e3754fc3dd37f49
#owner: https://api.github.com/users/micheldegeofroy

#!/bin/sh

# motd is generated with empty environment. This ensures that TERM is set, so that colors are displayed properly
# src: https://unix.stackexchange.com/a/417223/31104
export TERM="${TERM:-xterm-256color}"

# RED=$(tput setaf 1)
# GREEN=$(tput setaf 2)
# YELLOW=$(tput setaf 3)
# BLUE=$(tput setaf 4)
# VIOLET=$(tput setaf 5)
# SOME_COLOR=$(tput setaf 6)
WHITE=$(tput setaf 7)
RESET_STYLE=$(tput sgr0)

echo
echo -n "${WHITE}Raspberry Pi ($(hostname))${RESET_STYLE} " && uname -rvm
uptime
108 changes: 108 additions & 0 deletions seeker/snippet/20-raspberry-bitcoin
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#date: 2025-01-30T16:53:38Z
#url: https://api.github.com/gists/18b23955d3785c5b9e3754fc3dd37f49
#owner: https://api.github.com/users/micheldegeofroy

#!/bin/sh

# motd is generated with empty environment. This ensures that TERM is set, so that colors are displayed properly
# src: https://unix.stackexchange.com/a/417223/31104
export TERM="${TERM:-xterm-256color}"

BOLD=$(tput bold)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
# BLUE=$(tput setaf 4)
# VIOLET=$(tput setaf 5)
SOME_COLOR=$(tput setaf 6)
# WHITE=$(tput setaf 7)
RESET_STYLE=$(tput sgr0)

ram_total=$(free -mh | grep Mem | awk '{ print $2 }')
ram_used=$(free -mh | grep Mem | awk '{ print $3 }')

swap_memory=$(free -mh | grep -i swap)
swap_total=$(echo ${swap_memory} | awk '{ print $2 }')
if [ "${swap_total}" != "0" ]; then
swap_used=$(echo ${swap_memory} | awk '{ print $3 }')

swap_info="swap: ${BOLD}${swap_used} / ${swap_total}${RESET_STYLE}"
fi

sd_total=$(df -h | grep "/$" | awk '{ print $2 }')
sd_used=$(df -h | grep "/$" | awk '{ print $3 }')

external_storage=$(df -h | grep '/dev/sd')
if [ ! -z "${external_storage}" ]; then
external_total=$(echo ${external_storage} | awk '{ print $2 }')
external_used=$(echo ${external_storage} | awk '{ print $3 }')

external_info="external: ${BOLD}${external_used} / ${external_total}${RESET_STYLE}"
fi

btc_path=$(command -v bitcoin-cli)
if [ ! -z ${btc_path} ]; then
btc_line1="₿itcoin Core"

bitcoin_user=$(ps -eo user:10,command | grep "[b]itcoind" | awk '{ print $1 }')
data_dir="/home/${bitcoin_user}/.bitcoin"

BLOCKCHAIN_INFO="$(bitcoin-cli -datadir=${data_dir} getblockchaininfo 2> /dev/null)"
chain="$(echo ${BLOCKCHAIN_INFO} | jq -r '.chain')"
if [ ! -z $chain ]; then
chain="${chain}net"
fi

blocks="$(echo ${BLOCKCHAIN_INFO} | jq -r '.blocks')"

# add current sync status
progress="$(echo ${BLOCKCHAIN_INFO} | jq -r '.verificationprogress')"
percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')")
if [ -n $percentage ]; then
l2_extra="sync progress: ${percentage}"
fi

PEER_INFO="$(bitcoin-cli -datadir=${data_dir} getpeerinfo 2> /dev/null)"
peers_count=$(echo ${PEER_INFO} | jq 'length')

balance="$(bitcoin-cli -datadir=${data_dir} getbalance 2> /dev/null)"

NETWORK_INFO="$(bitcoin-cli -datadir=${data_dir} getnetworkinfo 2> /dev/null)"
networks="$(echo ${NETWORK_INFO} | jq -r '[.localaddresses[] | [.address, .port|tostring] | join(":")] | join("\t")')"
version="$(echo ${NETWORK_INFO} | jq -r '.subversion' | grep -Po '((\d+\.?){3})')"

MEMPOOL_INFO="$(bitcoin-cli -datadir=${data_dir} getmempoolinfo 2> /dev/null)"
mempool="$(echo ${MEMPOOL_INFO} | jq -r '.size')"
else
btc_line2="$(tput -T xterm setaf 1)NOT RUNNING"
fi

if [ ! -z "${btc_line1}" ] && [ ! -z ${chain} ]; then
btc_line1="${btc_line1} ${BOLD}(v${version}, ${chain})${RESET_STYLE}"
btc_line2="peers connected: ${BOLD}${peers_count}${RESET_STYLE}\t${SOME_COLOR}last block: ${BOLD}${blocks} (${percentage})${RESET_STYLE}"
btc_line3="balance: ${BOLD}${balance}${RESET_STYLE}\t${SOME_COLOR}mempool transactions: ${BOLD}${mempool}${RESET_STYLE}"

if [ ! -z "${networks}" ]; then
btc_line4="${networks}"
fi
else
ps cax | grep bitcoind >/dev/null 2>&1
if [ $? -eq 0 ]; then
btc_line2="${YELLOW}STARTING…"
else
btc_line2="${RED}NOT RUNNING"
fi
fi

echo "${GREEN}
.~~. .~~. resources used
'. \ ' ' / .' mem: ${BOLD}${ram_used} / ${ram_total}${RESET_STYLE}${GREEN}\t\t${swap_info}${RED}
.~ .~~~..~. ${GREEN}storage: ${BOLD}${sd_used} / ${sd_total}${RESET_STYLE}${GREEN}\t${external_info}${RED}
: .~.'~'.~. :
~ ( ) ( ) ~ ${SOME_COLOR}${btc_line1}${RED}
( : '~'.~.'~' : ) ${SOME_COLOR}${btc_line2}${RED}
~ .~ ( ) ~. ~ ${SOME_COLOR}${btc_line3}${RED}
( : '~' : )
'~ .~~~. ~' ${SOME_COLOR}accessible as${RED}
'~' ${SOME_COLOR}${BOLD}${btc_line4}${RESET_STYLE}${RED}
${RESET_STYLE}"
109 changes: 109 additions & 0 deletions seeker/snippet/23-raspberry-lnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#date: 2025-01-30T16:53:38Z
#url: https://api.github.com/gists/18b23955d3785c5b9e3754fc3dd37f49
#owner: https://api.github.com/users/micheldegeofroy

#!/bin/sh

# motd is generated with empty environment. This ensures that TERM is set, so that colors are displayed properly
# src: https://unix.stackexchange.com/a/417223/31104
export TERM="${TERM:-xterm-256color}"

BOLD=$(tput bold)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
# VIOLET=$(tput setaf 5)
# SOME_COLOR=$(tput setaf 6)
WHITE=$(tput setaf 7)
RESET_STYLE=$(tput sgr0)

ln_path=$(command -v lnd)
if [ ! -z ${ln_path} ]; then
ln_line1="lnd ⚡"
fi

ln_line1="${BLUE}lnd ${YELLOW}⚡"

lnd_user=$(ps -eo user:10,command | grep "[l]nd" | awk '{ print $1 }' | grep -v root)
if [ ! -z "${lnd_user}" ]; then
data_dir="/home/${lnd_user}/.lnd/"

INFO=$(lncli --lnddir=${data_dir} getinfo)
version="$(echo ${INFO} | jq -r '.version')"
network="$(echo ${INFO} | jq -r '.chains[0]')"
testnet="$(echo ${INFO} | jq -r '.testnet')"
if [ "${network}" != "bitcoin" ]; then
network="${network}-"
else
network=""
fi

if [ "${testnet}" = true ]; then
network="${network}testnet"
else
network="${network}mainnet"
fi

blocks="$(echo ${INFO} | jq -r '.block_height')"

pubkey="$(echo ${INFO} | jq -r '.identity_pubkey')"
peers_count=$(echo ${INFO} | jq '.num_peers')
best_connstring=$(echo ${INFO} | jq -r '.uris[0]')

BALANCE=$(lncli --lnddir=${data_dir} walletbalance)
on_chain="$(echo ${BALANCE} | jq -r '.total_balance')"
on_chain=$(printf "%0.8f\n" ${on_chain})

CHANNELS=$(lncli --lnddir=${data_dir} listchannels)
ch_open="$(echo ${CHANNELS} | jq '.channels | length')"

channels_mine=$(echo ${CHANNELS} | jq '[.channels[].local_balance] | map(tonumber) | add | if . == null then 0 else . / 1e8 end')

max_out=$(echo ${CHANNELS} | jq '[.channels[].local_balance] | map(tonumber) | max | if . == null then 0 else . / 1e8 end')
if [ "${max_out}" != "0" ]; then
max_send=" (max: ${max_out})"
fi

channels_their=$(echo ${CHANNELS} | jq '[.channels[] | .remote_balance] | map(tonumber) | add | if . == null then 0 else . / 1e8 end')

max_in=$(echo ${CHANNELS} | jq '[.channels[] | .remote_balance] | map(tonumber) | max | if . == null then 0 else . / 1e8 end')
if [ "${max_in}" != "0" ]; then
max_receive=" (max: ${max_in})"
fi

PENDING_CHANNELS=$(lncli --lnddir=${data_dir} pendingchannels)
ch_pending="$(echo ${PENDING_CHANNELS} | jq '.pending_open_channels | length')"
ch_closing="$(echo ${PENDING_CHANNELS} | jq '[.pending_closing_channels, .pending_force_closing_channels, .waiting_close_channels] | map(length) | add')"

ln_line1="${ln_line1} ${BLUE}${BOLD}(${version}, ${network})${RESET_STYLE}"
ln_line2="id: ${BOLD}${pubkey}${RESET_STYLE}"
ln_line3="peers connected: ${BOLD}${peers_count}${RESET_STYLE}\t${BLUE}synced to block: ${BOLD}${blocks}${RESET_STYLE}"
ln_line4="channels: ${BOLD}${ch_all}${RESET_STYLE} (${YELLOW}${BOLD}pending: ${ch_pending}${RESET_STYLE}${BLUE}, ${GREEN}${BOLD}open: ${ch_open}${RESET_STYLE}${BLUE}, ${RED}${BOLD}closing: ${ch_closing}${RESET_STYLE}${BLUE})"
ln_line5="balance:"
ln_line6="on-chain: ${BOLD}${on_chain}${RESET_STYLE}\t${BLUE}LN spend : ${BOLD}${channels_mine}${max_send}${RESET_STYLE}"
ln_line7="\t\t\t\tLN receive: ${BOLD}${channels_their}${max_receive}${RESET_STYLE}"

ln_line12="best connstring:"

ln_line14="${BOLD}${best_connstring}"

else
ln_line2="${RED}NOT RUNNING"
fi

echo "${YELLOW} ____ ${BLUE}${ln_line1}${YELLOW}
/ / ${BLUE}${ln_line2}${YELLOW}
/ / ${BLUE}${ln_line3}${YELLOW}
/ /_ ${BLUE}${ln_line4}${YELLOW}
/_ / ${BLUE}${ln_line5}${YELLOW}
/ / ${BLUE}${ln_line6}${YELLOW}
/ /_ ${BLUE}${ln_line7}${YELLOW}
/ /
/ / ${BLUE}${ln_line9}${YELLOW}
/ / ${BLUE}${ln_line10}${YELLOW}
// ${BLUE}${ln_line11}${YELLOW}
/ ${BLUE}${ln_line12}${YELLOW}

${ln_line14}
${RESET_STYLE}"
Loading

0 comments on commit feb11d9

Please sign in to comment.