Skip to content

Instantly share code, notes, and snippets.

View JBaczuk's full-sized avatar

Jordan Baczuk JBaczuk

View GitHub Profile
@JBaczuk
JBaczuk / UsePrevious.tsx
Created September 14, 2021 16:14
usePrevious - How to get the previous props or state in React
import React, { useEffect, useRef, useState } from "react";
function usePrevious(value: number) {
const ref = useRef<number | null>(null);
useEffect(() => {
ref.current = value;
});
return ref.current;
}
@JBaczuk
JBaczuk / mongo_setup.md
Last active April 10, 2019 18:19
How to set up authentication on mongodb

Mongo Authentication

  • Start mongod without auth enabled Make sure this is commented or missing from /etc/mongod.conf
#security:
#  authorization: enabled

The service should be running:

@JBaczuk
JBaczuk / addrgen
Created December 15, 2018 20:00
addrgen
#!/bin/bash
echo
echo "Welcome to the Bitcoin address generator!"
echo "input private key (32 bytes, hex format)"
read priv
echo ""
echo "#####################################"
# priv=0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D # Testing only
@JBaczuk
JBaczuk / btc_hashrate.py
Last active March 21, 2020 01:32
Bitcoin Network Hashrate
#!/usr/bin/env python
import sys
# Get command line arguments
##########################
# Note this script will calculate based on an average of 1 day's worth of blocks
if len(sys.argv) < 2:
print "Usage: $ btc_hashrate <blocks-24h> <current-difficulty>"
sys.exit()
@JBaczuk
JBaczuk / how_to_mine_genesis_block_2
Created November 8, 2018 14:50
How to mine genesis block snippet 2
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
@JBaczuk
JBaczuk / how_to_mine_genesis_block_1
Created November 8, 2018 14:22
How to mine genesis block snippet 1
/**
* Build the genesis block. Note that the output of its generation
* transaction cannot be spent since it did not originally exist in the
* database.
*
* CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
* CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
* CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* vMerkleTree: 4a5e1e
@JBaczuk
JBaczuk / secp256k1
Created October 16, 2018 14:38
secp256k1
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: $ secp256k1 <private-key-hex>"
exit 1
fi
priv=$1
## Calculate Public Keys
@JBaczuk
JBaczuk / sha256
Created October 8, 2018 14:16
SHA 256
#!/bin/bash
## Command Line parsing
#######################
if [[ $# -lt 1 ]]; then
echo "Usage: $ sha256 <input-hex>"
exit 1
fi
inputHex=$1
@JBaczuk
JBaczuk / hash160
Created October 8, 2018 14:16
Ripemd 160 Hash
#!/bin/bash
## Command Line parsing
#######################
if [[ $# -lt 1 ]]; then
echo "Usage: $ hash160 <input-hex>"
exit 1
fi
inputHex=$1
@JBaczuk
JBaczuk / reverse_endian.py
Created October 2, 2018 15:59
Reverse Endianess of a hex string
#!/usr/bin/env python
import sys
if len(sys.argv) < 1:
print "Usage: $ reverse_endian <input-hex>"
line = sys.argv[1]
n = 2
orig_list = [line[i:i+n] for i in range(0, len(line), n)]