Skip to content

Instantly share code, notes, and snippets.

View gpakosz's full-sized avatar

Grégory Pakosz gpakosz

View GitHub Profile
@gpakosz
gpakosz / rand.c
Created November 8, 2018 12:30
PCG32 based floating point random number generation
/**
* Generates a pseudorandom number, in the [0, 1[ interval.
* @param rng Pointer to the pseudorandom number generator.
*/
static inline float rand_f(pcg32_random_t* rng)
{
const uint32_t max = 1 << 24;
uint32_t r = pcg32_random_r(rng);
r &= max - 1;
return r * 1.0f / max;
@gpakosz
gpakosz / ln.sh
Created February 22, 2018 09:35
A shell ln() function that defers to mklink on Windows
case $(uname -s) in
*MINGW*)
ln() {
options="$1"
target="$2"
link="$3"
if ! [ -L "$link" ] && [ -d "$link" ]; then
link="$link/$(basename "$target")"
fi
@gpakosz
gpakosz / main.c
Created October 27, 2017 22:17
memcmp() and sizeof()
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
struct Foo
{
int i;
@gpakosz
gpakosz / main.cpp
Created March 7, 2017 12:55
uint64_t getChronometerTime() in ms
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
LARGE_INTEGER frequency; // init with QueryPerformanceFrequency(&frequency) e.g. at beginning of main()
#endif // or go wild and put that in the constructor of a dedicated static object
#ifndef _WIN32
#if defined (CLOCK_MONOTONIC)
#include <time.h>
#else
@gpakosz
gpakosz / NVIDIA-GeForce-GT-750M.txt
Created February 17, 2017 08:55
RealtchVR OpenGL Extension Viewer report for NVIDIA GeForce GT 750M (Late 2013 MacBook Pro)
Renderer: NVIDIA GeForce GT 750M OpenGL Engine
Vendor: NVIDIA Corporation
Memory: 2048 MB
Version: 4.1 NVIDIA-10.10.14 310.42.25f02
Device: MacBookPro11,3
Shading language version: 4.10
Max texture size: 16384 x 16384
Max vertex texture image units: 16
@gpakosz
gpakosz / array_length.hpp
Created January 5, 2017 21:46
C++98 array_length
#include <cstddef>
#define array_length(a) sizeof(impl::array_length_requires_array_argument(a))
namespace impl {
template<typename T, size_t N>
char (&array_length_requires_array_argument(T (&)[N]))[N];
}
// gcc -O3 -march=native -o simplehashing simplehashing.c
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <x86intrin.h>
// https://github.com/php/php-src/blob/PHP-7.1/Zend/zend_string.h#L325
@gpakosz
gpakosz / main.c
Created November 11, 2015 08:08
printf format string for size_t
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1800)
#define SIZET_FMT "%Iu"
#elif defined(__linux__) || (defined(_MSC_VER) && (_MSC_VER >= 1800))
#define SIZET_FMT "%zu"
#elif defined(__APPLE__)
#define SIZET_FMT "%zu"
#else
#define SIZET_FMT "%u"
#endif
@gpakosz
gpakosz / .gitconfig
Created October 8, 2015 12:14
My global .gitconfig
[user]
name = Gregory Pakosz
email = redacted
[color]
ui = auto
[core]
autocrlf = false
excludesfile = /Users/gregory/.gitignore
editor = vim
whitespace = cr-at-eol
@gpakosz
gpakosz / main.cpp
Created February 2, 2015 12:22
C++ array_length, reply to http://www.g-truc.net/post-0708.html
#include <cstddef>
#include <iostream>
#define array_length(a) sizeof(implementation::array_length_requires_array_argument(a))
namespace implementation {
template<typename T, size_t N>
char (&array_length_requires_array_argument(T (&)[N]))[N];
} // namespace implementation