Skip to content

Instantly share code, notes, and snippets.

@jgarzik
jgarzik / chomp.pl
Created April 30, 2012 18:58
Remove trailing whitespaces; files edited in-place.
#!/usr/bin/perl -w
use strict;
my ($argv_fn);
my $bytes_saved = 0;
while ($argv_fn = shift @ARGV) {
&chomp_file($argv_fn);
}
@jgarzik
jgarzik / mx.cc
Created May 15, 2012 14:48
Boost mutex static initialization example
/*
[jgarzik@bd tmp]$ g++ -O2 -Wall -g -o mx mx.cc -lboost_thread-mt
[jgarzik@bd tmp]$ ./mx
1. foo = 42
2. foo = 10
3. foo = 20
*/
#include <cstdio>
#include <boost/thread.hpp>
@jgarzik
jgarzik / boostgz.cc
Created May 17, 2012 04:03
Append a line of text to a gzip-compressed text file.
/*
Compile on Fedora 16 Linux:
g++ -O2 -Wall -g -o boostgz boostgz.cc -lboost_iostreams-mt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <iostream>
@jgarzik
jgarzik / getnetstats.txt
Created June 24, 2012 01:49
bitcoin 'getnetstats' output
Sample getnetstats JSON-RPC output, just after startup and 9-block sync-up:
{
"messages" : {
"addr" : [
"15",
"286929"
],
"alert" : [
"4",
@jgarzik
jgarzik / getpeerinfo-pmsg-example.txt
Created June 30, 2012 02:03
bitcoin 'getpeerinfo' per-message statistics
[
{
"addr" : "173.74.129.35:8333",
"services" : "00000001",
"lastsend" : 1341021734,
"lastrecv" : 1341021734,
"conntime" : 1341021329,
"recvbytes" : 37248,
"sendbytes" : 2823,
"version" : 32400,
@jgarzik
jgarzik / bip-blkv2.md
Created July 6, 2012 05:21
BIP XX: Block v2, Height in Coinbase

BIP XX: Block v2, Height in Coinbase

BIP: XX
Title: Block v2, Height in Coinbase
Author: Gavin Andresen <gavinandresen@gmail.com>
Status: Draft
Type: Standards Track
Created: 2012-07-06
@jgarzik
jgarzik / opcount.txt
Created July 26, 2012 05:48
bitcoin opcode counts
OP_0 104
OP_1 27
OP_2 12
OP_2OVER 182
OP_2SWAP 182
OP_3 16
OP_4 1
OP_CHECKMULTISIG 22
OP_CHECKSIG 12188693
OP_CODESEPARATOR 14
@jgarzik
jgarzik / opcount3.txt
Created July 26, 2012 05:54
bitcoin testnet3 opcode counts
OP_BOOLAND 4
OP_ENDIF 37
OP_8 3
OP_NOP1 3
OP_2DUP 6
OP_ROT 9
OP_4 13
OP_5 12
OP_6 5
OP_DEPTH 25
@jgarzik
jgarzik / samples.cfg
Created August 4, 2012 03:50
sample pynode configs
Example mainnet configuration
-----------------------------
db=/spare/tmp/chaindb
log=/spare/tmp/chaindb/debug.log
Example testnet configuration
-----------------------------
port=18333
@jgarzik
jgarzik / pynode-ripemd.patch
Created August 4, 2012 04:02
pynode patch for hashlib ripemd160
diff --git a/bitcoin/serialize.py b/bitcoin/serialize.py
index 6d7fc6d..13a3afd 100644
--- a/bitcoin/serialize.py
+++ b/bitcoin/serialize.py
@@ -7,6 +7,7 @@
#
import struct
+import hashlib
from Crypto.Hash import SHA256, RIPEMD160