Skip to content

Instantly share code, notes, and snippets.

@jprupp
jprupp / minikey-wif.hs
Created January 8, 2021 17:44
Minikey to WIF converter
#!/usr/bin/env stack
{- stack
--resolver lts-16.28
--nix
--nix-packages "secp256k1 pkg-config zlib"
script
--package haskoin-core
--package bytestring
--package text
--extra-dep haskoin-core-0.18.0
@jprupp
jprupp / minikey.hs
Last active January 8, 2021 16:38
Casascius Minikey Generator
#!/usr/bin/env stack
{- stack
--resolver lts-16.28
--nix
--nix-packages "secp256k1 pkg-config zlib"
script
--package haskoin-core
--package entropy
--package bytestring
--package text
#!/bin/bash
set -e
SEED=$(( RANDOM + 30000 ))
BITCOIN_DIRS=(/tmp/regtest-{$(( SEED + 50 )),$(( SEED + 51 ))})
BITCOIN_PORTS=($(( SEED + 10 )) $(( SEED + 11 )))
BITCOIND_RPC=($(( SEED + 20 )) $(( SEED + 21)))
export DIR=/tmp/regtest-haskoin-$(( SEED + 40 ))
#!/bin/bash
set -e
NET='bch'
if [[ -n $1 ]]
then
NET="$1"
fi
@jprupp
jprupp / counter.hs
Created March 8, 2018 16:35
Toy actor that counts
#!/usr/bin/env stack
-- stack --resolver lts-10.8 runghc --package nqe-0.1.0.0
import Control.Monad
import Control.Concurrent.NQE
data CounterMessage = GetCounter (Reply Integer)
counter :: Inbox CounterMessage -> IO ()
counter inbox = do

Philippe (Haskoin) and I stumbled upon an interesting idea during the weekend while attempting to improve the reliability of 0-conf transactions. This is the first written description of the Fastchain proposal.

The motivation behind this was originally to have some way to do partial confirmations on mempool transactions, but it soon became evident that we stumbled upon a mechanism that can be used to increase the size of Bitcoin blocks via a soft-fork. I call this system the Fastchain.

The Fastchain is a parallel blockchain where each Fastchain block is merge-mined into the next Bitcoin block. The difficulty of the Fastchain is much lower than that of the main Bitcoin blockchain, with a ratio set at some established constant. Since this is a soft-fork that proposes changes to the Bitcoin consensus protocol, every miner will be required to merge-mine Fastchain, guaranteeing that Fastchain blocks get the full proof-of-work power of the Bitcoin network, therefore similar security guarantees.

Fastchain blocks

@jprupp
jprupp / sudoku.hs
Last active February 3, 2020 01:36
Sudoku Solver in Haskell
import Data.List
import Data.Maybe
full :: [[[Int]]]
full = replicate 9 $ replicate 9 [1..9]
solve :: Int -> [[Int]] -> Maybe [[Int]]
solve n s
| invalid s = Nothing
| complete s' = Just s'
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent
import Control.Concurrent.Async
import Control.DeepSeq
import Control.Monad
import Control.Monad.Trans
import Data.Aeson.Encode.Pretty
import Data.Conduit
import qualified Data.ByteString.Lazy.Char8 as L8
import qualified Data.Conduit.List as CL
@jprupp
jprupp / qs.cpp
Last active August 29, 2015 14:01
Recursive QuickSort in C++ (memory-efficient)
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
void qs(int count, int ls[])
{
int pivot, *hole;
if (count < 1) return;
@jprupp
jprupp / double.cpp
Created May 15, 2012 12:24
Double precision floating point disassembly/reassembly analyser
#include <cassert>
#include <cmath>
#include <iostream>
using namespace std;
void printbytes(double d) {
unsigned long long int* pi = (unsigned long long int*) &d;
unsigned long long int i = *pi;
short int e = (i >> 52 & 0x7ff) - 1023; // Exponent
unsigned long long int m = (i << 12 >> 12) + pow(2, 52); // Mantissa