Skip to content

Instantly share code, notes, and snippets.

@vindard
vindard / README.md
Last active March 29, 2022 19:20
Galoy graphql api demo for #LightningHackdayIST

Description

This gist contains 3 files that can be imported into postman to play with our api:

  • grapqhql_api collection which has our queries and mutations
  • devnet environment variables for local testing (uses regtest network)
  • staging environment variables for testing against our staging endpoint (uses testnet network)
@vindard
vindard / galoy-new-code-style-notes.md
Last active August 8, 2021 04:29
Galoy: Notes on the new well-typed code style we'd like to move to

Personal notes for Lightning Service PR

(link: GaloyMoney/blink#426)

domain: primitives

  • added 'Satoshis' and 'TxDenominationCurrency' primitives
  • added value object for 'Satoshis'

domain: expiration

  • moved 'delay' business logic to 'invoice-expiration' domain
  • moved 'getExpiration' logic to 'invoice-expiration' domain
@vindard
vindard / chan_id.sh
Created May 16, 2021 15:10
Lightning Network chan_id format converter
#!/bin/bash
# Usage: pass any number of chan_id values with 'x' character in them to be converted
# e.g. $ ./chan_id.sh 674831x113x1
convert() {
export VAL=$1
if [[ ! -z $VAL ]]; then
CONV=$(python3 -c "import os; arr = os.environ.get('VAL', '').rstrip().split('x'); print( (int(arr[0]) << 40) + (int(arr[1]) << 16) + int(arr[2]) )")
fi
@vindard
vindard / taproot.sh
Last active May 14, 2021 16:52 — forked from mutatrum/taproot.sh
Print a taproot signalling block diagram
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9)
SINCE=$(echo "$TAPROOT" | jq .since)
PERIOD=$(echo "$TAPROOT" | jq .statistics.period)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
PERIOD_COUNT=$(((BLOCKS - SINCE) / PERIOD))
SINCE=$((SINCE + (PERIOD * PERIOD_COUNT)))
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed)
@vindard
vindard / main.go
Last active May 11, 2021 15:18
A demo of the different ways to hit http.ServeMux (standard library router) when making a webserver in Go
// Context: https://rickyanto.com/understanding-go-standard-http-libraries-servemux-handler-handle-and-handlefunc/
package main
import (
"fmt"
"net/http"
)
func handlerFunc(w http.ResponseWriter, r *http.Request) {
// w.Header().Set("Content-Type", "text/html")
@vindard
vindard / xpub_zpub_convert.py
Created May 8, 2021 17:34 — forked from freenancial/xpub_zpub_convert.py
Convert xpub/xprv to zpub/zprv
import base58
x = 'xprv9s21ZrQH143K2f55zo5GiXiX16MiPzBgc2bEXNd77e1ooGsjxAyXjozyuniqiSB76VESjTW8s7vdsK3NFboha6tZgF9BzcDdNtUT6Aw99P2'
zp = b'\x04\xb2\x43\x0c'
base58.b58encode_check(zp + base58.b58decode_check(x)[4:]).decode('ascii')
# output: 'zprvAWgYBBk7JR8GjFTKfWeX8huXM2ecHEAgSFdg6AQssemZuUWCTVJeywKFxCe1iFUwumU4EQhFnSdjdtGVgzdjAaFmQvY3ARrbvLbjsLf6oNE'
# xprv = b'\x04\x88\xad\xe4'
# yprv = b'\x04\x9d\x78\x78'
# zprv = b'\x04\xb2\x43\x0c'
@vindard
vindard / ln_invoice
Created April 17, 2021 18:54
Invoice for Lightning Torch
lnbc1750n1ps8ktk7pp59mxy9asaff5rpl9wgf2vnw25du0nn7swd29yzl4awxl6wpy0wm9qdzqydxxjemgw3hxjmn8fd5kcmrn2d5xjarrda5kuueqydxxjemgw3hxjmn823hhycmgxqyjw5q9qtzqqqqqq9qsqsp5237kh63xksekrvszf726p8zep8s3vvw9tv4xe9rt5mwpdjy0ktgqrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glcllagfp8qkplwlyqqqqlgqqqqqeqqjqnp2gwz7hsdz6tr42c3gujxupscn686kgwn9lau0f9cta2dx2a6h9yekzwq7cld6ekxmkpgps9lf6ne4xu6f2wxwwesaw20qxwcy33wsp598zyl
@vindard
vindard / backup-breakdown.md
Last active April 17, 2021 15:15
Breaking down a one-liner I'm using to backup files to S3 via crontab

Breaking down bash one-liner

I use the following one-liner to backup a file to AWS S3 daily as a cronjob

EXT=<extension here>; DIR="/home/pi/SERVER-SHARES"; FILENAME=$(ls -t "$DIR" | head -n 1 | grep ".$EXT$"); PRE=$(date -d "$(echo "$FILENAME" | awk '{print $4,$5}' | sed 's/,/, /g')" +"%Y%m%d"); RES=$(/home/pi/.pyenv/versions/awscli/bin/aws s3 cp --no-progress --storage-class DEEP_ARCHIVE "$DIR"/"$FILENAME" s3://<bucket-here>/"$PRE"--"$FILENAME" 2>&1); DATE=$(date +'%Y-%m-%d %T'); echo "$DATE | $RES" | sed -e :a -e '$!N;s/\n/^$DATE | /;ta' | tr '^' '\n' >> /home/pi/SERVER-SHARES/aws.log

Breakdown

@vindard
vindard / glacier_frustration_story.md
Last active April 15, 2021 03:19
An account of my journey trying to upload a single file from a Raspberry Pi to AWS Glacier Deep Archive

My Glacier Deep Archive user story

to be shared with AWS support

What I want to do?

  • Save stuff to Glacier from a Raspberry Pi

My steps:

  1. It's a storage thing I think since it's called S3 Glacier, so I assume I start with awscli to get s3 access:
@vindard
vindard / .env
Last active March 25, 2021 05:15
A bash script that can source its required environment variables from an env file and re-execute itself
export TEST_VAL_A=1
export TEST_VAL_B=2