Skip to content

Instantly share code, notes, and snippets.

@alexeiz
alexeiz / check_badweakptr.cpp
Created July 25, 2013 03:21
Determine the existence of a class (bad_weak_ptr) in a namespace (std).
#include <memory>
#include <exception>
#include <iostream>
namespace inject
{
struct bad_weak_ptr : std::exception
{
virtual char const * what() const _GLIBCXX_USE_NOEXCEPT
{
@alexeiz
alexeiz / scope_exit.cpp
Last active December 21, 2015 01:09
Simple "scope exit" macro for C++03, which supports arbitrary actions on scope exit.
#include <iostream>
using namespace std;
#define JOIN(a, b) JOIN_(a, b)
#define JOIN_(a, b) a ## b
#define ARG_COUNT(...) ARG_COUNT_IMP(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#define ARG_COUNT_IMP( _1,_2,_3,_4,_5,_6,_7,_8,_9, N, ...) N
@alexeiz
alexeiz / interfaceptr.cpp
Last active December 21, 2015 21:39
interface_ptr
#include "interfaceptr.hpp"
#include <cassert>
struct Interface1 {};
struct Interface2 {};
struct Interface3 {};
struct Class1 : Interface1, Interface2 {};
struct Class2 : Interface2, Interface3 {};
@alexeiz
alexeiz / result.hpp
Created September 9, 2013 15:41
`result` class is a discriminated union that combines a result of a function call with an exception that a function throws on error that allows to pass the full result of a function execution to code that doesn't allow exceptions.
#ifndef RESULT_H__
#define RESULT_H__
#include <stdexcept>
#include <algorithm>
#include <boost/variant.hpp>
namespace lib
{
@alexeiz
alexeiz / multiplex_pipe.cpp
Last active December 26, 2015 01:49
Multiplexing IO from a pipe.
#include <iostream>
#include <fstream>
#include <thread>
#include <stdexcept>
#include <memory>
#include <vector>
#include <cstring>
#include <unistd.h>
#include <fcntl.h>
@alexeiz
alexeiz / file_notify.cpp
Created February 11, 2014 05:21
Watch for inode changes with <sys/inotify.h>.
#include <boost/exception/all.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator.hpp>
#include <exception>
#include <string>
#include <iostream>
#include <array>
#include <tuple>
@alexeiz
alexeiz / timeit.cpp
Created July 17, 2014 14:42
A simple macro to time execution of a block of code.
#include <boost/timer/timer.hpp>
struct timeit_obj
{
template <typename F>
auto operator+(F && func) -> decltype(func()) const
{
boost::timer::auto_cpu_timer t;
return func();
}
@alexeiz
alexeiz / tmux-uptime.sh
Created November 14, 2014 06:22
Show uptime load averages in the tmux status line.
#!/bin/sh
uptime | gawk 'BEGIN{FS="[:,] "}{printf "%s %s %s", $(NF-2), $(NF-1), $NF}'
# source into bashrc, zshrc
# ssh-agent management functions for cygwin/msys2
export _SSH_AGENT_LOCK=/tmp/ssh-agent.lock
start_ssh_agent() {
if [ -e $_SSH_AGENT_LOCK ]; then
use_ssh_agent
else
eval `ssh-agent`
@alexeiz
alexeiz / sysjitter.md
Created February 26, 2016 19:13
Sysjitter documentation

Sysjitter

The Solarflare sysjitter utility measures the extent to which the system introduces jitter and so impacts on the user‐level process. Sysjitter runs a thread on each processor core and when the thread is de‐scheduled from the core it measures for how long. Sysjitter produces summary statistics for each processor core. The sysjitter utility can be downloaded from www.openonload.org

Sysjitter should be run on a system that is idle. When running on a system with cpusets enabled ‐ run sysjitter as root.