Skip to content

Instantly share code, notes, and snippets.

/**
* Pull request #651 (https://github.com/h2o/quicly/pull/651) introduced an extra parameter called `payload` that specifies the
* location of the payload to be encrypted (i.e., out-of-place encryption). Custom encryption callbacks can either adopt the new
* API directly, or use a wrapper function that copies the out-of-place payload then calls the original function.
*
* The function below is an example of such a wrapper function.
*/
void new_encrypt_packet(struct st_quicly_crypto_engine_t *engine, quicly_conn_t *conn, ptls_cipher_context_t *header_protect_ctx,
ptls_aead_context_t *packet_protect_ctx, ptls_iovec_t datagram, size_t first_byte_at,
size_t payload_from, const void *payload, uint64_t packet_number, int coalesced)
@kazuho
kazuho / git-blame-pr.pl
Last active December 15, 2025 09:47
git-blame by PR #
#! /usr/bin/perl
#
# Written in 2017 by Kazuho Oku
#
# To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
#
use strict;
use warnings;
@kazuho
kazuho / thundering-herd.pl
Last active November 25, 2025 13:21
thundering herd checker for select-accept pattern
#! /usr/bin/perl
#
# to test:
# 1) run this script with either "accept" or "select-accept" as the argument
# (the script listens to 127.0.0.1:12345)
# 2) telnet localhost 12345
# 3) if you see "accept failed", there is the thundering herd problem
#
#
use strict;
diff --git a/t/50connect-eyeballs.t b/t/50connect-eyeballs.t
index 832c1b051..717ac0729 100644
--- a/t/50connect-eyeballs.t
+++ b/t/50connect-eyeballs.t
@@ -1,5 +1,6 @@
use strict;
use warnings;
+use File::Temp qw(tempdir);
use IO::Socket::IP;
use Test::More;
#include <stdint.h>
#include <stdio.h>
#include <openssl/engine.h>
#include <openssl/provider.h>
#include "picotls.h"
#include "picotls/openssl.h"
int main(int argc, char **argv)
{
OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
@kazuho
kazuho / quest3-termux.md
Last active September 3, 2025 01:17
Meta Quest 3のlinuxセットアップ

想定読者

  • linuxに関する基本的な知識があるソフトウェアエンジニアもしくはヘビーユーザで、Quest 3のlinuxをGUI環境で使いたい人
  • apkのインストールとか説明しませんが、Quest 3に入れたやつは、アプリ一覧からカテゴリでUntrusted Sourcesみたいなのを選ぶと出てきます
  • termuxの上にlinux distroを載せるのは、遅いのでやりません(下記ベンチマーク参照)。prefixed-rootだろうがシングルユーザだろうがmusl libcだろうが我々なら大丈夫だ!
  • linuxアプリのインストールは特記事項ない限り省略します。勝手にpkg installとかして

ベンチマーク

@kazuho
kazuho / llmproxy.js
Last active May 9, 2025 01:36
proxy that adds function call capabilities to llama.cpp server
// proxy.js
// Express server wrapping llama.cpp server with OpenAI function-calling semantics
// Logs client requests/responses and model requests/responses to console
const express = require('express');
const axios = require('axios');
const bodyParser = require('body-parser');
const { v4: uuidv4 } = require('uuid');
const { spawn } = require('child_process');
@kazuho
kazuho / addmib.pl
Last active March 1, 2025 06:57
tiny memory load generator
#! /usr/bin/perl
use strict;
use warnings;
while (my $l = <STDIN>) {
chomp $l;
if ($l !~ /MiB/ and $l =~ /([0-9]+,[0-9,]+)/) {
$l .= toMiB($1);
}
diff --git a/src-main/context.c b/src-main/context.c
index d84858c..08a0de5 100644
--- a/src-main/context.c
+++ b/src-main/context.c
@@ -594,7 +594,7 @@ anthy_save_history(const char *fn, struct anthy_context *ac)
dprintf(fd, "\n");
/**/
errno = 0;
- if (fchmod(fd, S_IREAD | S_IWRITE)) {
+ if (fchmod(fd, S_IRUSR | S_IWUSR)) {
@kazuho
kazuho / markdown.md
Last active November 8, 2024 03:32
Linuxカーネルのreadahead、うまく動いてないケースがあるのかも

大きなテキストファイルをawkで処理するときにcatで投げ込むと速い理由のような事象が発生する原因についての推察。

自信はあまりない!

Linuxカーネルのreadahead実装についての理解

  • __do_page_cache_readaheadは、次にreadaheadを実行すべきページについてのみReadaheadフラグをたてる
  • 次にreadaheadを実行すべきページ「以降の全てのページ」ではない
  • do_generic_file_readはReadaheadフラグの立っているページをreadするタイミングでpage_cache_async_readaheadを呼ぶ
  • page_cache_async_readaheadはBDI_sync_congestedが立っている場合はreadaheadしない