Skip to content

Instantly share code, notes, and snippets.

@errzey
errzey / abstract
Last active August 29, 2015 14:01
Writing efficient parsers for streaming data in C
C is known as one of the worst languages to write any type of parsers.
Developers usually take one of three roads for parsing data:
1. Lexical Analysis & LALR (lex / yacc) utilizing a BNF syntax input.
2. Gobs of strstr, strtok, strcmp, and loads of conditionals.
3. Regular expressions, which usually involve the same logic in #2
Utilizing Lex & Yacc can be one of the more strict and specific methods of
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <inttypes.h>
#include <evhtp.h>
static evhtp_res print_data(evhtp_request_t * req, struct evbuffer * buf, void * arg);
static evhtp_res print_new_chunk_len(evhtp_request_t * req, uint64_t len, void * arg);
@errzey
errzey / gist:191be50d235ee01e0d1f
Created August 21, 2014 14:57
sample tsauditd filter
function Set(list)
local set = {}
for _, l in ipairs(list) do
set[l] = true
end
return set
end
@errzey
errzey / CMakeLists.txt
Created September 12, 2014 23:22
build better gcc on CentOSucks
cmake_minimum_required(VERSION 2.4)
add_custom_target(do_always ALL COMMAND yum -y install cmake git gcc gcc-c++ openssl-devel libtool autoconf flex bison zip)
include (ExternalProject)
ExternalProject_add(gmp
URL http://packages.strcpy.net/gmp-5.1.3.tar.bz2
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
@errzey
errzey / MOTD001.md
Last active August 29, 2015 14:13
@strcpy's "Macro of the Day" gistified.

Original tweet that started it all

While small and simplistic, it has a huge impact for many reasons

#define lz_safe_free(_var, _freefn) do { \
        _freefn((_var));                 \
        (_var) = NULL;                   \
}  while (0)

Keybase proof

I hereby claim:

  • I am ellzey on github.
  • I am strcpy (https://keybase.io/strcpy) on keybase.
  • I have a public key whose fingerprint is D0D6 688E 39FC E3B9 D575 8531 E8DF 9CA0 8131 CBFF

To claim this, I am signing this object:

#!/usr/bin/env bash
C_RST='\e[0m'
C_BLUE='\e[0;34m'
C_RED='\e[0;31m'
C_BRED='\e[1;31m'
C_BGREEN='\e[1;32m'
C_BBLUE='\e[1;34m'
C_BMAGENTA='\e[1;35m'
evhtpexp app = express();
express_cb_s foocb = onGet(app, "/foo",
func void(evreq r, void * a) {
reply(r, "FOOO");
});
express_cb_s barcb = onGet(app, "/bar",
func void(evreq r, void * a) {
reply(r, "BARRR");
@errzey
errzey / gist:472ac7c6c6f3ca09ca94
Created April 12, 2015 17:34
psuedocode for kernelcorn
struct query {
struct event * r_pipe_ev;
int r_pipe; /* response pipe */
int q_pipe; /* query pipe */
int response[256];
};
static void
read_response(int sock, short events, void * arg) {
struct query * q = (struct query *)arg;
@errzey
errzey / AREADME.md
Last active August 29, 2015 14:20
Using the libevhtp thrift module

Using the libevhtp thrift module

Just copy all this stuff to a directory (compile thrift with the libevhtp module of course first)

mkdir build; cd build; cmake .. ; make
./evhtp_thrift_server &
# if you have SO_REUSEPORT support, you can run multiple times.
./test1_client