Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / conversion.php
Created October 11, 2023 08:07
Round-trip conversion between Shift_JIS (CP932) and Unicode
<?php
count_unsafe_chars('cp932');
function roundtrip($char, $enc) {
return mb_convert_encoding(mb_convert_encoding($char, 'utf-8', $enc), $enc, 'utf-8');
}
function tohexupper($char) {
return strtoupper(bin2hex($char));
<?php
function benchmark(array $callables, int $repeat = 100000): array
{
$ret = [];
$save = $repeat;
foreach ($callables as $key => $callable) {
@masakielastic
masakielastic / error.md
Last active March 15, 2018 21:08
Zap の起動を続けていると起きるエラーメッセージ

A JavaScript error occurred in the main process

Uncaught Exception: Error: Object has been destroyed at BrowserWindow.send (/Applications/Zap.app/Contents/Resources/electron.asar/browser/api/browser-window.js:167:16) at ClientReadableStream.n.on (/Applications/Zap.app/Contents/Resources/app.asar/webpack:/app/lnd/subscribe/channelgraph.js:5:59) at emitOne (events.js:96:13) at ClientReadableStream.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18) at ClientReadableStream.Readable.push (_stream_readable.js:134:10)

@masakielastic
masakielastic / error.txt
Created February 15, 2018 22:26
nohup で lightningd をバックグラウンドで動かしたときのログ。lightning-cli fundchannel を実行するとエラーになる。
> cli/lightning-cli fundchannel 02f6725f9c1c40333b67faea92fd211c183050f28df32cac3f9d69685fe9665432 10000
{ "code" : -1, "message" : "Error packet: channel aa11668b2c7c07e4f57d3d7222360345fc05698cdc34e9b376d4e319f7cb034d: Unknown chain-hash 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" }
$ cli/lightning-cli help
command=dev-blockheight
description=Show current block height
command=dev-setfees
description=Set feerate in satoshi-per-kw for {immediate}, {normal} and {slow} (each is optional, when set, separate by spaces) and show the value of those three feerates
command=listnodes
description=Show all nodes in our local network view
command=getroute
bitcoin@ubuntu-bitcoin:~$ tail -f /mnt/blockstorage/Bitcoin/debug.log
2018-02-08 04:58:05 Opening LevelDB in /mnt/blockstorage/Bitcoin/blocks/index
2018-02-08 04:58:05 scheduler thread start
2018-02-08 04:58:06 Corruption: missing start of fragmented record(2)
2018-02-08 04:58:06 Database corrupted
2018-02-08 04:58:06 : Error opening block database.
Please restart with -reindex or -reindex-chainstate to recover.
2018-02-08 04:58:06 Aborted block database rebuild. Exiting.
2018-02-08 04:58:06 scheduler thread interrupt
2018-02-08 04:58:06 Shutdown: In progress...
@masakielastic
masakielastic / error.md
Created February 1, 2018 01:46
Lisk Core をインストール後のエラーメッセージ

√ Blockchain restored successfully. fs.js:796 return binding.writeBuffer(fd, buffer, offset, length, position); ^

Error: ENOSPC: no space left on device, write at Error (native) at Object.fs.writeSync (fs.js:796:20) at SyncWriteStream._write (fs.js:2243:6) at doWrite (_stream_writable.js:333:12)

@masakielastic
masakielastic / test.md
Last active January 11, 2018 02:39
脚注のテスト

タイトル

見出し1

本文。[1]

見出し2

次の文。[2]

1 脚注その1

@masakielastic
masakielastic / test.php
Last active September 19, 2017 16:36
0x0 から 0xff の範囲のバイトに対して mb_convert_encoding が無効なバイトをどのように置き換えるのかを確認します。
<?php
$enc = "cp932";
for ($cp = 0; $cp < 0x100; $cp++) {
$c = chr($cp);
$ret = mb_convert_encoding($c, $enc, $enc);
echo
bin2hex($c), " ",
@masakielastic
masakielastic / diff.rb
Last active October 2, 2017 06:39
ラウンドトリップが保障されない文字を調べます。
def chr_unsafe(cp, enc)
[cp.to_s(16)].pack("H*").force_encoding(enc)
end
enc = 'cp932'
count = 0
count2 = 0
(0x8000..0xffff).each do |cp|
begin