Skip to content

Instantly share code, notes, and snippets.

View shesek's full-sized avatar

Nadav Ivgi shesek

View GitHub Profile
@shesek
shesek / template-auto-escaping.js
Created July 20, 2011 11:49
Underscore.js templates escaping support
_.extend(_.templateSettings, {
encode: /<%=([\s\S]+?)%>/g,
interpolate : /<%==([\s\S]+?)%>/g
});
_.extend(_, {
// Taken from Backbone.js's escapeHTML()
escape: function(string) {
return (''+string).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
},
template: function(str, data) {
@shesek
shesek / address-to-scripthash.md
Last active January 5, 2024 00:55
Bitcoin address to electrum scripthash with nodejs
$ npm install bitcoinjs-lib
$ node -p 'b=require("bitcoinjs-lib");s=b.address.toOutputScript("2MwEUm842QN4YoetosKc1YbeFpHDjsZ6scS", b.networks.regtest);Buffer.from(b.crypto.sha256(s).reverse()).toString("hex")'

Note the b.networks.regtest, change if the address is on a different network.

@shesek
shesek / bitcoin-address-utxo.html
Last active December 19, 2023 08:11
Bitcoin address UTXO extractor based on Blockstream's API
<!DOCTYPE html>
<meta charset="utf-8">
<title>Bitcoin address UTXO extractor</title>
<style>
table, .csv { display: none }
</style>
<div class="container py-5">
<h2>Bitcoin address UTXO query</h2>
<form class="mt-3">
<div class="form-group">
@shesek
shesek / shutdown-status.sh
Created February 5, 2021 11:11
Display which services are in the process of shutting down (s6)
#!/bin/bash
sp='\|/-'
i=1
cd /var/run/s6/services
while :; do
services=$(for s in *; do s6-svstat $s 2> /dev/null | grep -q 'want down' && echo $s || true; done)
[ -n "$services" ] || break
echo -ne "[s6-finish] waiting for: $services ${sp:i++%${#sp}:1} \r"
sleep 0.2
done
@shesek
shesek / README.md
Created September 22, 2020 04:05
Rust - reproduible Windows exe builds - removing PE timestamps

For improved reproduciblity, you can build windows executables without the PE timestamps via mingw-w64 by setting:

RUSTFLAGS='-Clink-arg=-Wl,--no-insert-timestamp'

You may use something like this to conditionally set these flags for Windows builds only:

RUSTFLAGS="$RUSTFLAGS $([[ $platform != *"-windows-"* ]] || echo '-Clink-arg=-Wl,--no-insert-timestamp')" \
@shesek
shesek / index.pug
Last active February 18, 2019 10:40
Bitcoin address UTXO extractor based on Blockstream's API
.container.py-5
h2 Bitcoin address UTXO query
form.mt-3
.form-group
label(for='address') Bitcoin address
input.form-control#address(type='text', name='address')
input.btn.btn-primary(type='submit', value='Get UTXOs')
table.table.mt-5
thead: tr #[th txid:vout] #[th value] #[th block height] #[th block time]
@shesek
shesek / callable.coffee
Last active January 14, 2019 15:37
Decorate constructor functions, and have them return a callable object that delegates to a `callable()` method when invoked.
##########
### Moved to https://github.com/shesek/callable-klass
##########
"use strict"
# without strict mode, `this` defaults to window, so `(this?obj)`
# would always return window.
callable = (ctor) ->
@shesek
shesek / bitcoin-decoderawtransaction.coffee
Last active January 9, 2018 15:18
Decode Bitcoin raw transactions to bitcoinjs-lib's Transaction object with CoffeeScript
decode_raw_tx = do ->
{ Transaction, TransactionIn, TransactionOut } = Bitcoin
{ bytesToBase64 } = Crypto.util
# Parse an bytearray of length `size` as an integer
# Works for numbers up to 32-bit only
parse_int = (size) -> (bytes) ->
n = 0
n += (bytes.shift() & 0xff) << (8 * i) for i in [0...size]
@shesek
shesek / bitcoin-ATH.txt
Last active December 15, 2017 13:33
Bitcoin ATH
$ curl 'https://bitcoincharts.com/charts/chart.json?m=bitstampUSD&r=360&c=1&s=2017-01-01&e=2017-12-16' | jq -c '.[] | [(.[0]|strftime("%Y-%m-%d")),.[7]]' | tr -d '"[]' | awk -F, 'BEGIN{ath=0;total=0;aths=0;in20p=0}{total++;if ($2>ath*0.8) in20p++; if ($2>ath){print $1 " " $2; ath=$2; aths++ } } END { print "\nTotal "total" days\nATH in "aths" days (" (aths/total*100) "%)\n20% range from ATH in "in20p" days ("(in20p/total*100)"%)" }'
2017-01-01 987.468055790686
2017-01-02 1013.002448970431
2017-01-03 1020.555479651876
2017-01-04 1088.449474525684
2017-02-21 1104.602728943062
2017-02-22 1126.242226009392
2017-02-23 1153.559162275172
2017-02-24 1174.774405556085
@shesek
shesek / bower-lock-versions.sh
Last active September 16, 2017 23:12
Lock-down bower.json to the currently installed package versions (semi shrinkwrap)
cp bower.json bower.json.old
cat bower.json.old | \
jq "$(cat bower_components/*/.bower.json | \
jq -r '".dependencies[\"" + .name + "\"]=\"" + (._source+"#"+._resolution.commit) + "\"|.resolutions[\"" + .name + "\"]=\"" + ._resolution.commit + "\""' |paste -d'|' -s -)" \
> bower.json