Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / h2frames.php
Last active July 7, 2024 20:21
HTTP/2 frames test data
<?php
function dump($chunk, $name) {
var_dump(
$name,
[
'size' => strlen($chunk),
'hex' => bin2hex($chunk)
]
);
Output (Go 1.22.3)
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4
D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9
EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
@masakielastic
masakielastic / ffi_example.php
Last active May 3, 2024 23:11
PHP FFI example
<?php
$x = FFI::new('int');
$x->cdata = 5;
var_dump(
5 === $x->cdata
);
@masakielastic
masakielastic / hpack.c
Last active May 1, 2024 10:47
PHP エクステンションで nghttp2 による HPACK エンコードの例です
/* hpack extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_hpack.h"
#include "hpack_arginfo.h"
@masakielastic
masakielastic / hpack_encode.c
Last active May 1, 2024 10:21
nghttp2 の HPACK エンコードの例です
#include <stdio.h>
#include <nghttp2/nghttp2.h>
// https://nghttp2.org/documentation/tutorial-hpack.html
#define MAKE_NV(K, V) \
{ \
(uint8_t *)K, (uint8_t *)V, sizeof(K) - 1, sizeof(V) - 1, \
NGHTTP2_NV_FLAG_NONE \
}
@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) {
$start = hrtime(true);
@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