Skip to content

Instantly share code, notes, and snippets.

@gray
gray / wif2addr.pl
Last active December 26, 2016 23:03
Convert bitcoin private key to address
use Crypt::OpenSSL::Bignum;
use Crypt::OpenSSL::EC;
use Crypt::RIPEMD160;
use Digest::SHA qw(sha256);
use Encode::Base58::GMP;
sub wif2addr {
my $wif = shift;
my $bytes = pack 'H*', decode_base58($wif, 'bitcoin')->Rmpz_get_str(16);
@gray
gray / extract-session-cookie.pl
Last active March 18, 2018 03:31
Extract a Firefox session cookie
@gray
gray / parse-wkipedia.pl
Created February 4, 2016 02:26
Parse a Wikipedia dump file and search for particular articles
#!/usr/bin/env perl
use 5.012;
use warnings;
use XML::LibXML::Reader;
my $reader = XML::LibXML::Reader->new(IO => \*STDIN);
my $xpc = XML::LibXML::XPathContext->new;
$xpc->registerNs('w', 'http://www.mediawiki.org/xml/export-0.10/');
@gray
gray / solvemedia-captcha-tweaks.js
Last active August 29, 2015 14:18
SolveMedia Captcha Tweaks
// ==UserScript==
// @name SolveMedia Captcha Tweaks
// @namespace http://gist.github.com/gray
// @description Make the SolveMedia captcha less annoying
// @include *
// @grant none
// ==/UserScript==
// Remove the captcha iframe wrapper from the tab order, so a single tab
// brings focus to the input field.
@gray
gray / depuzzlefy.pl
Created March 12, 2015 04:45
Solves image jigsaw puzzles created by http://flash-gear.com/puzzle/
#!/usr/bin/env perl
use 5.012;
use warnings;
use File::Temp;
use IPC::System::Simple qw(capture system);
use LWP::UserAgent;
use URI;
use URI::QueryParam;
@gray
gray / gist:e8f4210faaecd9c1bf49
Last active August 29, 2015 14:09
List bitcoin addresses with their balances
bitcoin-cli listunspent 0 \
| jq -r 'group_by(.address) | map({
address: .[0].address,
amount: map(0, select(.spendable == true).amount) | add
}) | .[] | .address + ": " + (.amount | @text)' \
| awk '{printf "%s %.8f\n", $1, $2}' \
| sort -n -r -k 2
@gray
gray / gist:f16ece0398d24724f5ed
Last active August 29, 2015 14:06
regex: match nested HTML tags
# This will capture the contents of the div of interest, including any nested div tags.
use 5.010;
my ($div) = $content =~ m[
\Q<div id="matchme">\E
( (?> [^<]++ | <(?!/?div\b) | <div\b[^>]*+>(?1)</div> )*+ )
</div>
]x;
@gray
gray / obscure.php
Last active August 29, 2015 13:55
Obscure text by converting to a captcha-like image
<?php
$text = isset($_GET['t']) ? $_GET['t'] : '0.0000005';
$width = 140;
$height = 32;
$img = imagecreate(140, 32);
$white = imagecolorallocate($img, 255, 255, 255);
@gray
gray / list-noncpan-prereqs.pl
Created July 10, 2013 20:51
List non-CPAN prereqs
#!/usr/bin/env perl
use 5.014;
use warnings;
use Carp::Always;
use ElasticSearch;
use File::Spec::Functions qw(catfile tmpdir);
use LWP::UserAgent;
use PerlIO::gzip;
@gray
gray / jsonify-mozcookies.pl
Created May 30, 2013 20:04
Converts Firefox cookies into JSON so they can be imported into Chrome using the Edit Cookies extension.
#!/usr/bin/env perl
use 5.016;
use warnings;
use JSON;
use ORLite ();
my $file = shift or die 'Feed me firefox cookies sqlite file';
ORLite->import({ file => $file, package => 'DB' });