Skip to content

Instantly share code, notes, and snippets.

View mpapierski's full-sized avatar

Michał Papierski mpapierski

View GitHub Profile
@mpapierski
mpapierski / sendfile.py
Created February 12, 2014 18:13
Python Twisted + sendfile(2)
# coding: utf-8
import os
import sys
from cffi import FFI
from twisted.internet.defer import Deferred
from twisted.internet import reactor
from twisted.python import log
@mpapierski
mpapierski / defer.cpp
Created November 27, 2013 21:51
Golang-like defer {}; syntax
#include <iostream>
#include <cassert>
template <typename Func>
class impl
{
private:
impl(const impl &) = delete;
impl & operator=(const impl &) = delete;
public:
@mpapierski
mpapierski / async_io.cpp
Created October 27, 2013 22:37
asynchronous I/O?
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/select.h>
int
async_open(const char * filename, int flags)
{
// create pipe
@mpapierski
mpapierski / asio_sendfile.cpp
Last active November 7, 2021 19:36
boost.asio + sendfile(2)
// how to use boost.asio + sendfile(2)
// Michał Papierski <[email protected]>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/ref.hpp>
#include <boost/bind.hpp>
#include <boost/enable_shared_from_this.hpp>
@mpapierski
mpapierski / CMakeLists.txt
Created August 27, 2013 18:18
cgicc 3.2.10 cmakified.
#
# cgicc 3.2.10 cmakified
# by Michal Papierski <[email protected]>
#
cmake_minimum_required (VERSION 2.8.7)
project (cgicc)
set (VERSION "3.2.10")
execute_process (COMMAND "(hostname || uname -n) 2>/dev/null | sed 1q"
RESULT_VARIABLE HOST)
@mpapierski
mpapierski / linq.cpp
Created August 10, 2013 15:57
sql-like syntax for standard library containers
#include <iostream>
#include <string>
#include <boost/tuple/tuple.hpp>
#include <boost/utility.hpp>
#include <vector>
#include <boost/typeof/typeof.hpp>
#include <boost/foreach.hpp>
struct person
{
#include <stdexcept>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
class binstream
{
public:
struct str
{
inline str(char * & output, std::size_t length)
@mpapierski
mpapierski / gist:5687079
Created May 31, 2013 18:49
this is how libxml++ should look like
#include <iostream>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/HTMLtree.h>
struct xml_attribute
{
xmlNodePtr node_;
std::string key_;
xml_attribute(xmlNodePtr node, std::string const & key)
@mpapierski
mpapierski / gist:5653957
Created May 26, 2013 20:43
im not sure why i wrote this
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdexcept>
struct policy
{
};
struct allocator: policy
@mpapierski
mpapierski / 99bottles.cpp
Created May 18, 2013 23:33
having fun with C++ metaprogramming and 99 bottles of beer.
#include <cstdlib>
#include <cstdio>
template <int N>
struct bottles;
template <>
struct bottles<100>
{
};