Skip to content

Instantly share code, notes, and snippets.

import asyncio
from colorama import Fore, Back, Style
from random import choice
def random_color():
return choice([Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE])
class Pool:
#[cfg(all(target_os = "linux"))]
fn are_you_on_linux() {
println!("You are running linux!");
}
#[cfg(not(target_os = "linux"))]
fn are_you_on_linux() {
println!("You are *not* running linux!");
}
import { readable } from "svelte/store";
import { interpret } from "xstate";
import { debugMachineTransition } from "./debug";
export function useMachine(machine: any, options: any = {}) {
const service = interpret(machine, { ...options, devTools: true });
const state = readable(machine.initialState, set => {
service
.onTransition(newState => {
@justinmoon
justinmoon / psbt.js
Created April 11, 2020 20:21
playing with psbts and bitcoinjs-lib
const bitcoin = require('bitcoinjs-lib')
// const raw = 'cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA'
// P2WPKH ledger-regtest-2
const raw = 'cHNidP8BAHICAAAAAbuKj5iuve6fDpK5pAj24ufiRXcA8312D6SRzg/QY2FxAAAAAAD+////AgDh9QUAAAAAF6kUbsH1OtmyE+5ByjQx5kEXQvgNK+yH6AUQJAEAAAAWABTv6SHVcAkCx33yCGcyQommoRfT3wAAAAAAAQEfAPIFKgEAAAAWABSa3W1HMiPOr9PK6zrzlZMCROA9qSIGA3pc9nuIbfhNan9xRt6Cxvth725E2MBD9U1G0jv29MX4GGuz1AMwAACAAAAAgAAAAIAAAAAAAQAAAAAAIgIDxKTMwYqQ9fXjc9KMVCI5s9dALIubvzjXNb4hpJrT79AYa7PUAzAAAIAAAACAAAAAgAEAAAAAAAAAAA=='
const psbt = bitcoin.Psbt.fromBase64(raw)
const signed = bitcoin.Psbt.fromBase64('cHNid
@justinmoon
justinmoon / errors.js
Created April 11, 2020 20:21
hwi & bitcoin rpc errors
import { RPC_ERRORS, HWI_ERRORS } from "@app/constants"
const bitcoinRpcErrorCodeToConstant = {
"-32600": RPC_ERRORS.INVALID_REQUEST,
"-32601": RPC_ERRORS.METHOD_NOT_FOUND,
"-32602": RPC_ERRORS.INVALID_PARAMS,
"-32603": RPC_ERRORS.INTERNAL_ERROR,
"-32700": RPC_ERRORS.PARSE_ERROR,
"-1": RPC_ERRORS.MISC_ERROR,
"-3": RPC_ERRORS.TYPE_ERROR,
@justinmoon
justinmoon / gist:1c50eb24c5ef5874adab6fc38244409b
Created April 8, 2020 21:45
Bitcoin Core RPC Transactions (from slack discussion)
Remember how we've seen some weirdness in the output of listtransactions ?
If you make one transactions there will be multiple entries in our transaction list?
That's because each separate input / output gets a different entry in listtransactions
This is one transaction:
{
"involvesWatchonly": true,
"address": "bcrt1qg9xjv8raj57pynq39hmgswruectr6qzdmeppvtgnnrwjvs4z9hws42jalj",
@justinmoon
justinmoon / utils.js
Created April 3, 2020 03:08
bitcoin.conf javascript utils
// Just update for a single network. Maybe they don't want to enable their mainnet RPC, for instance ...
function updateBitcoinConfig(config, network) {
// Would be better if this required confirmation ...
delete config['global']['testnet']
delete config['global']['regtest']
config[network]['server'] = 1
config[network]['disablewallet'] = 0
return config
}
This file has been truncated, but you can view the full file.
$ cargo clean
$ cargo build -vv
Compiling cc v1.0.50
Compiling pkg-config v0.3.17
Running `CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/cc-rs' CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=50 CARGO_PKG_VERSION_PRE= CARGO_MANIFEST_DIR=/home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50 CARGO_PKG_VERSION=1.0.50 LD_LIBRARY_PATH='/home/justin/dev/runlibtor/target/debug/deps:/usr/lib' CARGO_PKG_NAME=cc CARGO=/usr/bin/cargo CARGO_PKG_DESCRIPTION='A build-time dependency for Cargo build scripts to assist in invoking the native
C compiler to compile native C code into a static archive to be linked into Rust
code.
' CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/cc-rs' rustc --crate-name cc --edition=2018 /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,
$ cargo clean
$ cargo build -vv
Compiling cc v1.0.50
Compiling pkg-config v0.3.17
Running `CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/cc-rs' CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=50 CARGO_PKG_VERSION_PRE= CARGO_MANIFEST_DIR=/home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50 CARGO_PKG_VERSION=1.0.50 LD_LIBRARY_PATH='/home/justin/dev/runlibtor/target/debug/deps:/usr/lib' CARGO_PKG_NAME=cc CARGO=/usr/bin/cargo CARGO_PKG_DESCRIPTION='A build-time dependency for Cargo build scripts to assist in invoking the native
C compiler to compile native C code into a static archive to be linked into Rust
code.
' CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/cc-rs' rustc --crate-name cc --edition=2018 /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,
$ cargo clean
$ cargo build -vv
Compiling cc v1.0.50
Compiling pkg-config v0.3.17
Running `CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/cc-rs' CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=50 CARGO_PKG_VERSION_PRE= CARGO_MANIFEST_DIR=/home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50 CARGO_PKG_VERSION=1.0.50 LD_LIBRARY_PATH='/home/justin/dev/runlibtor/target/debug/deps:/usr/lib' CARGO_PKG_NAME=cc CARGO=/usr/bin/cargo CARGO_PKG_DESCRIPTION='A build-time dependency for Cargo build scripts to assist in invoking the native
C compiler to compile native C code into a static archive to be linked into Rust
code.
' CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/cc-rs' rustc --crate-name cc --edition=2018 /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.50/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,