Skip to content

Instantly share code, notes, and snippets.

@vindard
vindard / tmux_bitcoin.sh
Created March 14, 2021 05:21
Tmux script for setting up a bitcoin monitoring session on my full node
#!/bin/bash
# Source: https://michaelwelford.com/post/saving-time-preset-tmux-setup
# Note that this assumes base index of 1
# check for existence of required things
# $1 is the name of the window
if [ $# -eq 0 ]
then
@vindard
vindard / split_paragraph.py
Last active March 9, 2021 05:35
Splits a paragraph string into smaller paragraph strings based on the 'max_lines' number passed in
from typing import List
def split_para(para_string: str, max_lines: int = 3) -> List[str]:
if not max_lines > 0:
print(f"Error: Please pass a 'max_lines' arg greater than 0")
return [para_string]
# Get 1st 'max chunk' of para_string and add to result
para_lines = para_string.split('\n')
para_1st_string = '\n'.join(para_lines[:max_lines])

Working with map objects in GoLang

This short post is to explore a sticking point I came across when trying to implement a familiar pattern (from Python) in GoLang. In a nutshell, the idea was to loop over a map data structure to execute some lines of code instead of manually duplicating these lines.

var (
    homeTemplate     *template.Template
	contactTemplate  *template.Template
)
@vindard
vindard / noip2.service
Created February 12, 2021 01:11
'systemd' service for No-IP Dynamic Update Client
# Simple No-ip.com Dynamic DNS Updater
#
# By Nathan Giesbrecht (http://nathangiesbrecht.com)
#
# 1) Install binary as described in no-ip.com's source file (assuming results in /usr/local/bin)
# 2) Run sudo /usr/local/bin/noip2 -C to generate configuration file
# 3) Copy this file noip2.service to /etc/systemd/system/
# 4) Execute `sudo systemctl enable noip2`
# 5) Execute `sudo systemctl start noip2`
#
@vindard
vindard / group_chars.py
Last active February 6, 2021 15:13
Solution to a twitter interview question: https://twitter.com/Al_Grigor/status/1357028887209902088
import re
INPUT = "aaaabbbcca"
OUTPUT = [("a", 4), ("b", 3), ("c", 2), ("a", 1)]
def convert(input_str):
res = []
for c in input_str:
if not res or c != res[-1][0]:
@vindard
vindard / arrayFromHexString.js
Created January 26, 2021 03:10
Javascript: Convert hex string to binary array
// Source: https://github.com/janoside/btc-rpc-explorer/commit/b24cd8945405bbeb87c80ab62c53c675f2dfa707#diff-7df1f014b703ad2b6416ed2d53f1a6ed05d52429571651fd2f6cfa5c94b027f2R826
const parseHexString1 = hexdata =>
new Uint8Array(hexdata.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
// Source: https://stackoverflow.com/a/26019433
function parseHexString2(hexdata) {
let byteArray = new Uint8Array(hexdata.length/2);
for (let x = 0; x < byteArray.length; x++){
byteArray[x] = parseInt(hexdata.substr(x*2,2), 16);
}
@vindard
vindard / whitepaper-node.ts
Last active October 31, 2022 22:50
A script to pull the whitepaper from the bitcoin blockchain
const axios = require('axios')
const fs = require('fs')
const TXID = "54e48e5f5c656b26c3bca14a8c95aa583d07ebe84dde3b7dd4a78f4e4186e713"
const fetchHex = (txid) => {
const endpoint = (txid) => `https://mempool.space/api/tx/${txid}/hex`
return axios.get(endpoint(TXID))
.then(res => res.data)
}
@vindard
vindard / fetch_release_emails.py
Last active December 20, 2020 18:33
Fetch all Bitcoin Core release emails to Linux Foundation mailing list and save to a 'release_links.json' file
from datetime import datetime as dt
import json
import re
import requests
url = "https://lists.linuxfoundation.org/pipermail/bitcoin-dev/{}-{}/{}"
months = [dt(2020, i, 1).strftime('%B') for i in range(12, 0, -1)]
years = list(range(2020, 2010, -1))
@vindard
vindard / torrent-steps.md
Last active December 20, 2020 18:32
A set of steps for setting up an always-on bitcoin torrent seed-box on existing bitcoin nodes

Description

The guide is based on installing on a node setup using the Raspibolt steps, but it should be easy to adapt for other Raspberry Pi or Linux-based setups.

The following steps will guide you on how to install the Transmission torrent daemon & client and then download and seed the bitcoin torrent. I chose to use Transmission since it seems to be the default client for Linux distros like Ubuntu and it has a pretty friendly cli interface to control the daemon from.

Future improvements could include automatic steps for verifying the magnet link and downloaded files before continuing to seed using transmission-remote's --torrent-done-script flag to pause the torrent if any checks fail (see this twitter thread)


@vindard
vindard / python-test.sh
Last active December 16, 2020 20:55
Different ways to run coverage.py for testing
#!/bin/bash
coverage run -m unittest && coverage report -m && coverage html
# coverage run -m unittest && coverage report -m
# coverage run -m unittest test.integration.test_app && coverage report -m
# coverage run -m unittest discover -s test/integration -t . && coverage report -m
# coverage run -m unittest discover -s test/unit -t . && coverage report -m
# coverage run -m unittest discover -s test/smoke -t . && coverage report -m