Skip to content

Instantly share code, notes, and snippets.

#include <event2/event.h>
#include <event2/util.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct timeval tv;
size_t n = argc == 2 ? atoll(argv[1]) : 1<<20;
struct event_base *base = event_base_new();
for (size_t i = 0; i < n; ++i) {
@azat
azat / keybase.md
Last active April 22, 2019 20:28
keybase.md

Keybase proof

I hereby claim:

  • I am azat on github.
  • I am iamazat (https://keybase.io/iamazat) on keybase.
  • I have a public key whose fingerprint is 9E3A C83A 2797 4B84 D1B3 401D B860 8684 8EF8 686D

To claim this, I am signing this object:

// interspect libevent [807] issue:
// accept4() -> getnameinfo() -> uninitialized value
//
// [807]: https://github.com/libevent/libevent/issues/807
//
// Overcome compiler errors:
//
// error: 'asm goto' constructs are not supported yet
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
# overall
borg create --list --exclude-from excludes --one-file-system --dry-run srv:/location::name / |& grep ^- | cut -d' ' -f2- | python -c 'import os, sys; [ print(p.strip()) if not os.path.isdir(p.strip()) else None for p in sys.stdin ]' | tr '\n' '\0' | du -sch --files0-from=- | tail -1
# top
borg create --list --exclude-from excludes --one-file-system --dry-run srv:/location::name / |& grep ^- | cut -d' ' -f2- | python -c 'import os, sys; [ print(p.strip()) if not os.path.isdir(p.strip()) else None for p in sys.stdin ]' | tr '\n' '\0' | du -ch --files0-from=- | sort --human-numeric-sort | tail -n500
#include <iostream>
#include <thread>
#ifdef _WIN32
#include <WinSock2.h>
#endif
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
@azat
azat / replace-stdout-stderr.gdb
Last active November 22, 2019 14:42
replace process stdout (via gdb), in case of hang (someone stops reading from pipe/socket)
# Replace /dev/null with something meaningful
# but keep in mind that the file should exists, since here is O_RDWR(2) only
#
# Example:
# cat &
# gdb -p $(pgrep cat) -batch -ex 'source replace-stdout-stderr.gdb'
p (int)open("/dev/null", 2)
p (int)dup2($1, 1)
p (int)dup2($1, 2)
p (int)close($1)
@azat
azat / clog.py
Last active September 28, 2021 08:42
#!/usr/bin/env -S PYTHONHASHSEED=0 python3
# pylint: disable=line-too-long
# Highlight (thread, query_id, level) in the clickhouse logs,
# like the server/client does in case stdout is terminal.
#
# Usage example:
#
# clog.py < /var/log/clickhouse-server/clickhouse-server.log | less -R
// https://github.com/libevent/libevent/issues/984
#include <event2/event.h>
#include <event2/event_struct.h>
#include <unistd.h>
#include <cassert>
int main()
{
event_base* base = event_base_new();
// https://github.com/libevent/libevent/issues/984
#include <event2/event.h>
#include <assert.h>
void readcb(int fd, short events, void *arg)
{
printf("%s: fd=%i, events=%hi\n", __func__);
}
void closecb(int fd, short events, void *arg)