Instantly share code, notes, and snippets.

View bc_b128.rb
#!/usr/bin/env ruby
# Bitcoin Core Base128 Serializer
# https://github.com/bitcoin/bitcoin/blob/v0.16.3/src/serialize.h#L317
def b128_encode( n )
puts (n).to_s(2)
tmp = []
while true do
tmp.push( ((n & 0x7F) | (tmp.length>0 ? 0x80 : 0x00) ).chr )
View simple_uleb128.rb
#!/usr/bin/env ruby
# Unsigned LEB128 Converter
# https://en.wikipedia.org/wiki/LEB128
def leb128_encode( n )
tmp = []
while true do
tmp.push( ((n & 0x7F) | 0x80 ).chr )
if n <= 0x7F
View bc_amount_compression.rb
#!/usr/bin/env ruby
# Bitcoin Core Amount compression
# https://github.com/bitcoin/bitcoin/blob/v0.16.3/src/compressor.cpp#L133
def compress_amount(n)
if n == 0
return 0
end
e = 0
View leb128.rb
#!/usr/bin/env ruby
# Unsigned LEB128 Converter
# https://en.wikipedia.org/wiki/LEB128
def encode( num, with_hex=false)
bs_n = num.to_s(2)
len = bs_n.length
# 0 padding for 7-bit
padding_len = (len / 7 + ( len % 7 > 0 ? 1 : 0 )) * 7
View radiko.sh
#!/bin/bash
# https://mtunn.wordpress.com/odroid-u2★セットアップ/radikoの録音・再生(archlinux)/
pid=$$
wkdir='/var/tmp'
playerurl=http://radiko.jp/apps/js/flash/myplayer-release.swf
playerfile="${wkdir}/player.swf"
keyfile="${wkdir}/authkey.png"
auth1_fms="${wkdir}/auth1_fms_${pid}"
auth2_fms="${wkdir}/auth2_fms_${pid}"
View samba_backup.sh
#!/bin/sh
#
# Copyright (C) Matthieu Patou <mat@matws.net> 2010-2011
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
View S3Buckup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tarfile,gzip,os
from time import time,strftime
from boto.s3.connection import S3Connection
from boto.s3.key import Key
class S3Backup:
bucket=None
View conv4kindle.sh
#!/bin/bash
pdf=$(echo $1|sed 's/.pdf//g')
# 変換
convert -density 150 -geometry 800x600 +antialias \
-rotate 90 -type GrayScale ${pdf}.pdf pdfpage_%02d.jpg
# 圧縮
zip ${pdf}.zip pdfpage_*.jpg