Skip to content

Instantly share code, notes, and snippets.

/*
This is an example of how to hook up evhttp with bufferevent_ssl
It just GETs an https URL given on the command-line and prints the response
body to stdout.
Actually, it also accepts plain http URLs to make it easy to compare http vs
https code paths.
Loosely based on le-proxy.c.
@azat
azat / cat.gdb
Created November 27, 2016 08:31
#
# replace binary with cat(1),
# so that if this program runs in pipe it will not fail the pipe
#
p open("/dev/null", 2)
p dup2($1, 1)
p dup2($1, 2)
p close($1)
p calloc(sizeof(char *), 2)
p strdup("/bin/cat")
# re-export bash settings into container from host
lxc.mount.entry = /etc/bash.bashrc etc/bash.bashrc none ro,bind,create=file 0 0
lxc.mount.entry = /etc/bash.d etc/bash.d none ro,bind,create=dir 0 0
lxc.mount.entry = /etc/bash_completion.d etc/bash_completion.d none ro,bind,create=dir 0 0
@azat
azat / lxc.container.conf
Created December 4, 2016 12:48
Confintainer config with guest=debian and host=archlinux (that shares some configs)
# host: archlinux
# Distribution configuration
lxc.include = /usr/share/lxc/config/debian.common.conf
lxc.arch = x86_64
# Container specific configuration
lxc.cgroup.cpuset.cpus = 0
# Network configuration
lxc.network.type = veth
lxc.network.flags = up
#!/usr/bin/env bash
if [[ "$*" =~ "--output" ]]; then
prev=$#
let --prev
output="${@:$prev:1}"
url="${@:$#}"
# to fix vagrant download issues
#include <stdio.h>
#include <stdlib.h>
#include <event2/event.h>
#include <event2/bufferevent.h>
struct arg
{
int i;
int *i_ptr;
};
#!/usr/bin/env bash
tr -cd 'a-z' < /dev/urandom | dd iflag=fullblock of=test bs=1M count=100
tail -c+$((1 + 8192)) test | head -c100; echo
off=$(filefrag -v test | tail -n+4 | head -1 | awk '{print $4}' | tr -d .)
sudo dd iflag=direct if=/dev/sda1 bs=4K skip=$((off + 2)) count=1 2>/dev/null | head -c100; echo
sudo dd oflag=direct of=/dev/sda1 if=/dev/zero bs=4K seek=$((off + 2)) count=1
tail -c+$((1 + 8192)) test | head -c100; echo
sudo dd iflag=direct if=/dev/sda1 bs=4K skip=$((off + 2)) count=1 2>/dev/null | head -c100; echo
#!/usr/bin/env awk
# strace -ttt parser (speed ~ 10MB/s)
function inc(pid, time, syscall)
{
# per-thread elapsed
if (threads[pid]) {
e = time - threads[pid];
}
@azat
azat / libevent-issue-560.c
Last active September 25, 2017 08:58
libevent-issue-560.c
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <event2/event.h>
#include <event2/event_compat.h>
@azat
azat / libevent-pecl-event_init.patch
Created September 26, 2017 21:14
libevent-pecl-event_init.patch
diff --git a/libevent.c b/libevent.c
index 97e8210..467346f 100644
--- a/libevent.c
+++ b/libevent.c
@@ -1392,6 +1392,8 @@ static PHP_MINIT_FUNCTION(libevent)
le_event = zend_register_list_destructors_ex(_php_event_dtor, NULL, "event", module_number);
le_bufferevent = zend_register_list_destructors_ex(_php_bufferevent_dtor, NULL, "buffer event", module_number);
+ event_init();
+