Skip to content

Instantly share code, notes, and snippets.

@TheBurnDoc
TheBurnDoc / Pipeline.h
Created June 3, 2014 09:52
A simple Pipeline template example, with Sequence and Filter implementations - Sequence simply chains together functions to be executed sequentially and Filter can be used to erase the contents of a standard container based on staged rule functions.
// Pipeline base class
template <typename T, typename F>
class Pipeline
{
public:
typedef std::function<F> Func;
Pipeline() = default;
@TheBurnDoc
TheBurnDoc / DynamicLibrary.cpp
Last active December 30, 2015 09:08
This gist demonstrates how to wrap the dynamic loading of DLLs/SOs using some C++11 techniques, including variadic templates and std::function. To load the library you just call lib.load() and then lib.callFunction<return_type>("FuncName", param1, param2 ...).
#include <cstdio>
#include <string>
#include <sstream>
#include <stdexcept>
#ifdef _MSC_VER
#include <Windows.h>
#include <direct.h>
#else
#include <dlfcn.h>
@TheBurnDoc
TheBurnDoc / AutoHotkey.ahk
Created October 29, 2013 17:05
Example AutoHotkey script that essentially makes Windows act like OS X Lion (significantly, it inverts the scroll direction of the trackpad)
; Increase maximum hotkeys (needed for scrolling to work)
#HotkeyInterval 250
; Alt-3 for Hash/Pound
!3::
Send {#}
Return
; Invert scrolling direction (OS X Lion behaviour)
WheelUp::
@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
@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 / 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 / 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 / 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 / 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 / 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>