Skip to content

Instantly share code, notes, and snippets.

@justinmoon
justinmoon / demo.py
Created August 14, 2018 19:32
Check if thread is dead in Python
import threading
import time
def doom():
raise RuntimeError()
def zoom():
while True:
@justinmoon
justinmoon / demo.py
Created August 14, 2018 23:13
Python: How to subclass threading.Thread
import random
import threading
import time
class MyThread(threading.Thread):
def run(self):
seconds = random.random()
print(f"sleeping for {seconds} seconds")
time.sleep(seconds)
@justinmoon
justinmoon / whoami.md
Last active September 10, 2018 18:15
Who am I

Objective

  • Find role where I can most help Bitcoin become reserve currency of world
  • Meet partners for next wave of ventures 10 years out, when Bitcoin has become boring and mainstream
  • Become financially independent (not there yet)
  • I'm currently trying to create a Bitcoin programming bootcamp to help experienced devs get Bitcoin jobs. My goal is to start first cohort on November 1. It would be free for students, and would monetize with recruiter fees from job placements.

Skills / Background

  • Interdisciplinary. I like to think about sales and I like to think about code.
  • First employee at Karmic Labs.
  • One of our products was an expense management system for corporations that issued debit cards to all employees and apps for spending authorization in place of reimbursements. I built the mobile app.
@justinmoon
justinmoon / mynewblockcoin.py
Created November 7, 2018 21:43
mynewblockcoin.py
"""
BanknetCoin
Usage:
banknetcoin.py serve
banknetcoin.py ping
banknetcoin.py tx <from> <to> <amount>
banknetcoin.py balance <name>
Options:
"""
BanknetCoin
Usage:
banknetcoin.py serve
banknetcoin.py ping
banknetcoin.py tx <from> <to> <amount>
banknetcoin.py balance <name>
Options:
@justinmoon
justinmoon / lambda-calculus.scm
Created January 9, 2019 20:14
The lambda calculus in Racket / Scheme
#lang lazy
; - single argument procedures are the only thing
; - nothing else
(define (TRUE x)
(lambda (y) x))
(define (FALSE x)
(lambda (y) y))
### Keybase proof
I hereby claim:
* I am justinmoon on github.
* I am justinmoon (https://keybase.io/justinmoon) on keybase.
* I have a public key ASAUUTp8gNM-v2dKHQ5KCp71jDQMyiIDbhWCpcpGTAkSygo
To claim this, I am signing this object:
@justinmoon
justinmoon / btcpay-migration.md
Last active January 9, 2024 19:37
Transferring BTCPayServer data from one server to another

First, update your old BTCPayServer to the newest version. This way there aren't any database schema conflicts with the your server.

SSH to old server you are migrating from. Create a dump of the your database's schema and data

docker exec generated_postgres_1 pg_dumpall -c -U postgres > backup.sql

Try opening that backup.sql file in your text editor of choice. You will see it's just a series of SQL statements which:

@justinmoon
justinmoon / gist:8128e66fc11d90ae5732f2491570bfc5
Last active February 8, 2024 04:45
Recovering from a lost BTCPay password w/o SMTP set up

You setup a btcpay server account, forgot to setup SMTP (or set it up wrong) and then forgot your password. Now you can't get back in. Here's how I recovered from this situation:

  1. Create a new user according to these instructions. But this isn't enough because (1) Your new user isn't a member of any stores and (2) for me at least this new user couldn't setup SMTP ...

  2. There is a postgres table called UserStore which tracks membership of users in stores. When you execute the following command in postgres

select * from "UserStore";
@justinmoon
justinmoon / getaddr_profile.py
Created March 26, 2019 04:05
Measure speed of `addr` response to `getaddr` message on Bitcoin network
# Depends on python-bitcoinlib only
import socket, time, bitcoin
from bitcoin.messages import msg_version, msg_verack, msg_addr, msg_getaddr, MsgSerializable, msg_pong
from bitcoin.net import CAddress
from statistics import mean
from threading import Thread
from concurrent.futures import ThreadPoolExecutor