Skip to content

Instantly share code, notes, and snippets.

@ph1ee
ph1ee / netmon.cc
Created July 3, 2015 05:27
Network State Monitor with Netlink
/**
* g++ -std=c++11 netmon.cc -lpthread
*/
#include <linux/rtnetlink.h>
#include <netdb.h>
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include <unistd.h>
@ph1ee
ph1ee / common.h
Created July 9, 2015 02:01
Use boolean values in C
// -std=c99
#ifndef __cplusplus
#include <stdbool.h>
#endif
@ph1ee
ph1ee / dpipe.c
Last active October 9, 2015 06:04
Delay Pipe: Read a block of data from stdin, write it to stdout with random delay
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define PIPE_PROGRESS_SIZE 4096
#define min(a, b) \
({ \
__typeof__(a) _a = (a); \
@ph1ee
ph1ee / loop-unrolling.cc
Last active August 29, 2015 14:26
Loop Unrolling in C++ TMP
// Generative Programming: Methods, Techniques and Applications
// Ch.8 Static Metaprogramming in C++
#include <iostream>
using namespace std;
template <int i>
struct aStatement {
enum { n = i };
@ph1ee
ph1ee / soduku.cc
Created July 31, 2015 10:39
A Soduku Puzzle Solver
#include <vector>
#include <set>
#include <algorithm>
#include <ctime>
#include <iostream>
const int UNASSIGNED = 0;
const int N = 9;
class Grid {
@ph1ee
ph1ee / ht2.c
Last active August 29, 2015 14:27
Mihalis Tsoukalos's hash table in '15 Aug Linux Journal
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define TABLESIZE 5
// Linked List
typedef struct node {
char *data;
@ph1ee
ph1ee / boost-asio-https.cc
Created September 14, 2015 09:26
An HTTPS client that connects to Yahoo using Boost.Asio
// g++ % -lboost_system -lpthread $(pkg-config --libs openssl)
#include "boost/asio.hpp"
#include "boost/asio/ssl.hpp"
#include <string>
using namespace boost::asio;
int main(int argc, char *argv[]) {
io_service service;
@ph1ee
ph1ee / extract-multipart.cc
Last active September 25, 2015 05:57
Extract multipart messages from raw HTTP captures into individual files
/**
* extract-multipart.cc
*
* This program extracts multipart messages from raw HTTP captures into
* individual files.
*
* Usage: a.out <file ...>
*/
#include <iostream>
#include <fstream>
@ph1ee
ph1ee / mserv.py
Created September 25, 2015 11:33
Simple Bottle MJPEG Streamer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Inspired by:
* http://weeklybuild.com/2014/07/07/mjpeg-bottle-gstreamer/
* http://www.ridgesolutions.ie/index.php/2014/11/24/streaming-mjpeg-video-with-web2py-and-python/
* https://gist.github.com/n3wtron/4624820
'''
@ph1ee
ph1ee / inspect_open.c
Created October 8, 2015 06:06
Detect file opening with LD_PRELOAD
/**
* Detect file opening with LD_PRELOAD
*
* gcc -shared -fPIC inspect_open.c -o inspect_open.so -ldl
* LD_PRELOAD=$PWD/inspect_open.so gnome-calculator
*
* See:
* https://www.tomaz.me/2014/01/08/detecting-which-process-is-creating-a-file-using-ld-preload-trick.html
*
*/