Skip to content

Instantly share code, notes, and snippets.

View christophercrouzet's full-sized avatar

Christopher Crouzet christophercrouzet

View GitHub Profile
@christophercrouzet
christophercrouzet / multiprocessing.py
Created August 24, 2016 07:15
Python's asynchronous queues vs synchronous pipes.
#!/usr/bin/env python3
import logging
import multiprocessing
_LOGGER = multiprocessing.log_to_stderr()
_LOGGER.setLevel(logging.DEBUG)
@christophercrouzet
christophercrouzet / incrementindices.h
Created April 26, 2015 02:56
Compile-time multidimensional indices incrementer
#ifndef INCREMENTINDICES_H
#define INCREMENTINDICES_H
#include <cstddef>
#include <type_traits>
#include <m3ta/at>
#include <m3ta/concatenate>
#include <m3ta/integersequence>
#include <m3ta/popback>
@christophercrouzet
christophercrouzet / strides.h
Last active August 29, 2015 14:17
Compute the strides of a n-dimensional array either at compile or run time.
#ifndef STRIDES_H
#define STRIDES_H
#include <cstddef>
#include <m3ta/concatenateintegersequences>
#include <m3ta/integersequence>
#include <m3ta/reverseintegersequence>
@christophercrouzet
christophercrouzet / multidimensionalarray.h
Last active November 30, 2018 12:35
Nested initializer lists for multidimensional arrays in C++11.
#ifndef MULTIDIMENSIONALARRAY_H
#define MULTIDIMENSIONALARRAY_H
#include <array>
#include <cstddef>
#include <type_traits>
// https://github.com/christophercrouzet/m3ta
#include <m3ta/nestedinitializerlists>
#include <m3ta/pass>
@christophercrouzet
christophercrouzet / gist:b3e4567c4fd3a9fe9b8c
Last active August 29, 2015 14:11
Check if a function that can be called with a specific set of arguments exists.
#include <iomanip>
#include <iostream>
#include <string>
#include <type_traits>
#include <utility>
template<typename T>
struct Functions;
@christophercrouzet
christophercrouzet / distance.h
Last active April 16, 2024 13:02
Compute the distance in ulps between floating-point numbers in C++11.
#ifndef DISTANCE_H
#define DISTANCE_H
#include <algorithm>
#include <cassert>
#include <cmath>
#include <limits>
#include "floatingpointtraits.h"
@christophercrouzet
christophercrouzet / gist:49dcd547b766030ddd2d
Last active August 29, 2015 14:09
Uniform distribution of floating-point values in C++.
#include <algorithm>
#include <array>
#include <cmath>
#include <random>
#include <iomanip>
#include <ios>
#include <iostream>
@christophercrouzet
christophercrouzet / gist:1fea72d0d88e5a0dca16
Created August 16, 2014 03:03
OpenGL projection matrix to fit the content to the window while preserving the aspect ratio
int shorterSide = std::min(width, height);
GLfloat marginX = 1.0f + GLfloat(width - shorterSide) / (GLfloat)shorterSide;
GLfloat marginY = 1.0f + GLfloat(height - shorterSide) / (GLfloat)shorterSide;
glm::mat4 projection = glm::ortho(-marginX, marginX, -marginY, marginY);
@christophercrouzet
christophercrouzet / getmodulenamefrompath.py
Created August 5, 2014 13:18
Retrieves a module name from a path
import inspect
import os
def get_module_name_from_path(path):
if not os.path.exists(path):
raise ValueError("The path '%s' is not a valid path." % path)
path = os.path.abspath(path)
full_names = []
@christophercrouzet
christophercrouzet / shaders.cmake
Created August 5, 2014 13:00
Command to format GLSL shaders with CMake for inclusion in C++
separate_arguments(FILES)
foreach (file ${FILES})
if (LOAD_SHADERS_DYNAMICALLY)
file(
COPY ${SOURCE_DIR}/${file}
DESTINATION ${DESTINATION_DIR}
)
else()
set(filename ${SOURCE_DIR}/${file})