Skip to content

Instantly share code, notes, and snippets.

@84adam
84adam / lnd-postgres-kv-decoder.py
Created February 23, 2023 04:58
Decode Keys/Values from Postgres LND Database
# lnd-postgres-kv-decoder.py
from decouple import config
import psycopg2
import psycopg2.extras
import pandas as pd
import time
tables = ['channeldb_kv', 'decayedlogdb_kv', 'macaroondb_kv',
'towerclientdb_kv', 'towerserverdb_kv', 'walletdb_kv']
@84adam
84adam / postgres-separators.txt
Created January 4, 2023 21:27
PostgreSQL: format multiple columns into string for each row using a semicolon as separator between fields
### PostgreSQL: format multiple columns into string for each row using a semicolon as separator between fields
```
SELECT
FORMAT('%s; %s; %s; %s',
col_one, col_two, col_three, col_four)
AS entries
FROM table_name;
```
@84adam
84adam / i2pd.service
Last active December 21, 2022 14:39
i2pd.service: control/unit file, systemd service definition
[Unit]
Description=I2P Router written in C++
Documentation=man:i2pd(1) https://i2pd.readthedocs.io/en/latest/
After=network.target
ConditionFileIsExecutable=/usr/sbin/i2pd
[Service]
User=i2pd
Group=i2pd
RuntimeDirectory=i2pd
@84adam
84adam / bitcoin-inflation.py
Created October 20, 2022 16:44
Calculate future bitcoin supply and inflation
# bitcoin-inflation.py
# based on: https://github.com/ndsvw/Bitcoin-Supply-Calculator/blob/master/btcsupply.py
def btc_supply_at_block(b):
max_supply = 20999999.9769
if b >= 33 * 210000:
return max_supply, 1.0
else:
reward = 50e8
supply = 0
@84adam
84adam / tips.txt
Created October 17, 2022 17:16
Python Clean Code Tips & Tools
### Python Clean Code Tips & Tools
Check the quality of your code inside your CI pipeline.
- flake8 - style guide enforcer
- black - code formatting
- isort - optimize imports
- bandit - check for security vulnerabilities
- safety - check for security vulnerabilities of dependencies
@84adam
84adam / main.go
Created October 16, 2022 16:37
Simple Go Website
// a simple Go-based website
// based on: https://www.digitalocean.com/community/tutorials/how-to-make-an-http-server-in-go
// with 100 bytes of CSS from: https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41
package main
import (
"errors"
"fmt"
"io"
@84adam
84adam / progress-compaction.sh
Last active November 16, 2022 17:20
Monitor Esplora/Electrs compaction process
#!/bin/bash
MOUNTPOINT="/mnt/ext"
DISK="/dev/sda1"
echo ""
echo "-------------------------------------------------------------------------------- DISK SPACE USED/REMAINING"
df -m | head -n 1 ; df -m | grep "$DISK"
df -H | head -n 1 ; df -H | grep "$DISK"
echo "-------------------------------------------------------------------------------- DISK I/O"
echo ""
@84adam
84adam / neutrino-bitcoin-nodes.md
Last active April 12, 2023 23:18
Known Public Neutrino-Enabled Bitcoin Full Nodes
[Application Options]
feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json

[Bitcoin]
bitcoin.active=1
bitcoin.mainnet=1
bitcoin.node=neutrino

[neutrino]
@84adam
84adam / pandas-one-in-two-out-apply.py
Created June 10, 2022 23:07
Apply a function to one column and assign the output to two pandas dataframe columns.
import pandas as pd
# MAKE UP SOME DATA
data = {'id': [1, 2, 3, 4, 5],
'First Name': ['Mary', 'Harry', 'Larry', 'Fairy', 'Dairy',],
'Birth Year': [1930,1940,1950,1960,1970],
'Favorite Color': ['Blue', 'Red', 'Green', 'Pink', 'Orange']}
# CREATE A DATAFRAME
df = pd.DataFrame.from_dict(data)
import requests
import io
import pandas as pd
# SEE: https://fred.stlouisfed.org/series/T5YIFR/#0
url = """https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1168&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=T5YIFR&scale=left&cosd=2003-01-02&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Daily&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&nd=2003-01-02
"""
s = requests.get(url).content