Skip to content

Instantly share code, notes, and snippets.

@louisdx
louisdx / gist:1076849
Created July 11, 2011 21:34
Full SFINAE type trait for containers
#include <vector>
#include <string>
#include <utility>
#include <iostream>
template<typename T>
struct has_const_iterator
{
private:
typedef char one;
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <utility>
#include <string>
#include <sstream>
#ifndef H_PRETTY_PRINT
#define H_PRETTY_PRINT
#define HAVE_VARIADIC_TEMPLATES 0
#define HAVE_TEMPLATE_ALIASES 0
#include <iostream>
#include <iterator>
#include <utility>
#include <tuple>
@louisdx
louisdx / gist:998257
Created May 29, 2011 23:56
libpng demo
#include <png.h>
#include <stdio.h>
#include <errno.h>
#define PNG_SUCCESS 0
#define PNG_ERR_INVALID_HEADER 1
#define PNG_ERR_INIT 2
int read_png(FILE * fp)
{
if (pos < path.length())
{
try
{
out += path.substr(pos);
}
catch (const std::exception & e)
{
std::cerr << "Exception: " << e.what() << std::endl;
out = "INVALID_STATE";
@louisdx
louisdx / gist:923051
Created April 16, 2011 11:16
cmake settings
# Set compiler specific build flags
IF (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-W -Wall -Wno-unused -pedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g")
set(CMAKE_CXX_FLAGS_PROFILE "-DDEBUG -g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s -DNDEBUG")
ENDIF()
IF (MSVC_IDE)
@louisdx
louisdx / gist:919304
Created April 14, 2011 11:33
Plugin system
/// Current plug-ing system, schematically:
std::vector<Block*> BlockCB; // Dirt, Stone, Stairs, Torch, ...
PacketHandler::player_does_something()
{
int16_t block_type = figureOutAffectedBlockType();
for ( each Block* blockcb in BlockCB)
{
@louisdx
louisdx / gist:919303
Created April 14, 2011 11:32
Plugin system
/// Current plug-ing system, schematically:
std::vector<Block*> BlockCB; // Dirt, Stone, Stairs, Torch, ...
PacketHandler::player_does_something()
{
int16_t block_type = figureOutAffectedBlockType();
for ( each Block* blockcb in BlockCB)
{
@louisdx
louisdx / gist:915900
Created April 12, 2011 16:51
Progress dd
#/bin/sh
# Credits for the idea: http://linuxcommando.blogspot.com/2008/06/show-progress-during-dd-copy.html
# Written by Louis Delacroix
dd if=/dev/zero of=/dev/null bs=512 count=3000000 &
PID=$!