Skip to content

Instantly share code, notes, and snippets.

View incoming_cpu.c
#define _GNU_SOURCE
#include <assert.h>
#include <limits.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
View areas.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH (99 * 40)
#define HEIGHT (99 * 25)
static double timespec2d(struct timespec *ts)
{
@kazuho
kazuho / git-blame-pr.pl
Last active Jun 28, 2022
git-blame by PR #
View git-blame-pr.pl
#! /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 / fusionbench.c
Last active May 10, 2022
Tiny benchmark program for picotls-fusion
View fusionbench.c
/*
* Copyright (c) 2020 Fastly, Kazuho Oku
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@kazuho
kazuho / sockaddr_cmp.c
Last active Apr 9, 2022
compare sockaddr
View sockaddr_cmp.c
/*
* As of May 25 2021, this code is provided as CC0 / public domain (Kazuho Oku)
*
* Copyright (c) 2014 Kazuho Oku
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
View injectaddr.so.c
/*
* NAME: injectaddr.so
*
* SYSOPSIS:
* % gcc -shared -fPIC injectaddr.c -ldl -o injectaddr.so
*
* -- inject 1s delay, then connect to 127.0.0.1:8888
* % LD_PRELOAD=injectaddr.so \
* curl http://d1000.p8888.4127-0-0-1.inject.example.com/
*
View runall.pl
use strict;
use warnings;
use File::Temp qw(tempdir);
use Getopt::Long;
use POSIX qw(:sys_wait_h);
my $jobs = 1;
GetOptions(
"jobs=i" => \$jobs,
View rpick.pl
#! perl
use strict;
use warnings;
my $lines_to_pick = 5; # 何行選ぶか
my $lines_total = 0;
my @picked;
@kazuho
kazuho / cloexec-posix-spawn.c
Created Nov 16, 2021
Command hangs on macOS 11.5 if O_CLOEXEC is used
View cloexec-posix-spawn.c
#include <errno.h>
#include <fcntl.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define USE_O_CLOEXEC 1
@kazuho
kazuho / thundering-herd.pl
Last active Oct 4, 2021
thundering herd checker for select-accept pattern
View thundering-herd.pl
#! /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;