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];
}
@gpakosz
gpakosz / gist:1128030
Created August 5, 2011 17:22
ARM NEON integer 16x8 dot product
# ------------------------------------------------------------------------------
# int32_t dotProduct_16x8_neon(int16_t const* __restrict u, int8_t const* __restrict v, int32_t size)
.globl _dotProduct_16x8_neon
.private_extern _dotProduct_16x8_neon
.no_dead_strip _dotProduct_16x8_neon
_dotProduct_16x8_neon:
# calling conventions:
#---------------------
// 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
" -- tabular settings ----------------------------------------------------------
nnoremap <silent> <Leader>a= :Tabularize /=<CR>
vnoremap <silent> <Leader>a= :Tabularize /=<CR>
nnoremap <silent> <Leader>a: :Tabularize /:\zs<CR>
vnoremap <silent> <Leader>a: :Tabularize /:\zs<CR>
" auto align on pipes
inoremap <silent> <Bar> <Bar><Esc>:call <SID>pipe_align()<CR>a
function! s:pipe_align()
@gpakosz
gpakosz / checkduplicatesymbols.sh
Created October 3, 2013 20:43
./checkduplicatesymbols.sh libFoo.a libBar.a
#!/bin/sh
# exit the script if any statement returns a non-true return value
set -e
# exit the script on dereferencing uninitialised variables
set -o nounset
self=$(basename $0)
origin=$(cd "$(dirname "$0")"; pwd)