Skip to content

Instantly share code, notes, and snippets.

@TheBurnDoc
TheBurnDoc / gtest_html_report.xsl
Created October 20, 2013 12:35
XSL transform to produce a human readable HTML page from Google Test XML output
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Google Test Report</title>
</head>
<body>
<table cellpadding="2" cellspacing="0" width="100%" border="1">
@TheBurnDoc
TheBurnDoc / ForkedTest.cc
Created October 20, 2013 12:39
A method of using Posix fork to 'catch' and report seg faults in Google Test. To take advantage of it, use the ForkedTest class as your base test case class and remember to call its SetUp and TearDown in the derived classes' SetUp and TearDown.
#include <iostream>
#include <gtest/gtest.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <resource.h>
#include "ForkedTest.h"
@TheBurnDoc
TheBurnDoc / thread.cc
Created October 20, 2013 13:00
Minimal pthread wrapper classes, including the thread class itself and the mutex and lock_guard counterparts. Inherit from this class and override the thread_main pure virtual function to define the thread's entry point.
#include <cstring>
#include <sched.h>
#include <pthread.h>
#include "thread.h"
thread::thread() : _running(false)
{
}
@TheBurnDoc
TheBurnDoc / tcp.cc
Last active December 26, 2015 02:49
This Gist shows an example C++ TCP client/server transport architecture using raw sockets. The server listens on a separate thread and utilises the select call, which is arguably old and out of date, but it is well supported and serves its purpose in this example. This Gist depends on a custom thread class (or the pthreads one in one of my other…
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <string>
#include <sstream>
#include <stdexcept>
#include <sys/socket.h>
#include <unistd.h>
@TheBurnDoc
TheBurnDoc / build.sh
Last active December 26, 2015 02:58
A simple CMake shell script wrapper script. The script performs an out-of-source build and is designed to cope with debug and release build configurations.
#!/bin/bash
usage ()
{
echo "CMake build script wrapper..."
echo " Usage: $0 [-h -t <debug/release> -c]"
echo
echo " -h : Display this message"
echo " -t : Specify build configuration (default: debug)"
echo " -c : Perform clean of configuration specified in the -r parameter"
@TheBurnDoc
TheBurnDoc / protobuf.cmake
Created October 21, 2013 11:17
This Gist demonstrates how to integrate the compilation of Protocol Buffer files into your CMake project
# Protobuf setup, these should be set to your project's directories, and currently assumes
# that everything is relative to CMAKE_SOURCE_DIR (the directory CMake is run from)
set (PROTO_IN_DIR ${CMAKE_SOURCE_DIR}/proto)
set (PROTO_OUT_DIR ${CMAKE_SOURCE_DIR}/build/proto)
set (PROTOC_BIN ${CMAKE_SOURCE_DIR}/thirdparty/protobuf/bin/protoc)
set (PROTOC_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/protobuf/include)
set (PROTOC_LIB_DIR ${CMAKE_SOURCE_DIR}/thirdparty/protobuf/lib
# Protobuf files
set (PROTO_FILES
@TheBurnDoc
TheBurnDoc / doxygen.cmake
Created October 21, 2013 11:22
This Gist shows how to integrate Doxygen HTML doc generating into your CMake project. It assumes that a file called Doxyfile.cmake exists in the project, from which it generates the final Doxyfile (which means you can embed CMake variables such as directories in Doxyfile.cmake rather than hard-coding them)
# Use -DBUILD_DOCUMENTATION=ON to enable Doxygen at build-time
option (BUILD_DOCUMENTATION
"Use Doxygen to create the HTML based API documentation" OFF)
# Build Doxygen HTML docs
if (BUILD_DOCUMENTATION)
FIND_PACKAGE(Doxygen)
if (NOT DOXYGEN_FOUND)
message (FATAL_ERROR
"Doxygen not found on system, cannot build documentation")
@TheBurnDoc
TheBurnDoc / juliaset.cu
Created October 21, 2013 12:42
A Gist that demonstrates how to set up and call a CUDA C kernel that generates a Julia set fractal.
#include <cstdio>
#include <cassert>
#include <cuda.h>
#include <cuda_profiler_api.h>
#include "juliaset.h"
// Zn + 1 = Zn^2 * C
// Helper function
static __device__ float julia(uint16_t x, uint16_t y, uint16_t w, uint16_t h, float cr, float ci)
@TheBurnDoc
TheBurnDoc / base.sublime-project
Last active December 26, 2015 03:19
Template Sublime Text 3 C++ project configuration, with supporting script files. The custom build system depends on CMake 2.8 and assumes GCC 4.8+ or Visual Studio 2012 Nov 2012 CTP for the best C++11 support available at the time. Also these files only build 64-bit debug configurations at present.
{
"folders":
[
{
"path": "src",
"name": "Source",
},
{
"path": ".",
"name": "Miscelaneous",
@TheBurnDoc
TheBurnDoc / proj.sh
Created October 21, 2013 17:53
Shell code which provides a rudimentary project management command ('proj'). Set PROJ_ROOT to your projects parent directory and, assuming this file has been sourced, type 'proj' to get going.
# Project management (proj command)
export PROJ_ROOT=$HOME/projects
export PROJ_CONF=.proj.conf
_proj_complete ()
{
local suggest=$(compgen -d $PROJ_ROOT/${COMP_WORDS[COMP_CWORD]} | awk -F "/" '{print $NF}')
if [[ $(echo $suggest | wc -w | grep -o '[0-9]') == 1 && -d $PROJ_ROOT/$suggest ]]; then
COMPREPLY=$suggest
else
unset COMPREPLY