Skip to content

Instantly share code, notes, and snippets.

Avatar

Miles Lacey hamsham

View GitHub Profile
@hamsham
hamsham / work_thread.cpp
Created Mar 31, 2018
Simple worker thread/task queue test.
View work_thread.cpp
/*
* Simple worker thread/task queue test.
*
* g++ -std=c++11 -Wall Werror -Wextra -pedantic-errors work_thread.cpp -lpthread -o work_thread
*/
#include <atomic>
#include <cassert>
#include <chrono> // std::seconds
@hamsham
hamsham / line_drawing.cpp
Last active Jan 6, 2018
Benchmark of different drawing algorithms. EFLA 5 wins.
View line_drawing.cpp
/*
* g++ --std=c++11 -O3 -DNUM_TEST_RUNS=50000 -pthread -Wall -Werror -Wextra -pedantic -pedantic-errors line_drawing.cpp -o line_drawing
*/
#include <cstdint> // uint8_t
#include <fstream> // std::ofstream
#include <iostream> // std::cout, std::cerr
#include <limits> // std::numeric_limits<>
#include <memory> // std::unique_ptr
@hamsham
hamsham / parse_args.c
Created Aug 5, 2017
Simple example of how to parse arguments from a single string, with quote-handling.
View parse_args.c
/*
* Test for parsing command-line arguments from a single string
*
* gcc -std=c11 -Wall -Werror -Wextra -pedantic -pedantic-errors parse_args.c -o parse_args
*/
#include <stdio.h> // printf(), fprintf()
#include <string.h> // strlen()
#include <stdbool.h> // bool, true, false
#include <ctype.h> // isspace()
@hamsham
hamsham / .emacs
Last active May 16, 2017
My Emacs Config
View .emacs
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
@hamsham
hamsham / align_nums.c
Created May 10, 2016
Get the next multiple of an unsigned integer to assist with memory allocations and data alignment.
View align_nums.c
/**
* Simple program to find the next multiple of a number (AMD, NVIDIA, & Intel share 16-byte alignments for cache lines).
*
* gcc -std=c11 -Wall -Wextra -Werror -pedantic-errors align_nums.c -o align_nums
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@hamsham
hamsham / glsl_regex.cpp
Created Feb 4, 2016
Test to retrieve GLSL outputs from a fragment shader.
View glsl_regex.cpp
/**
* Testing a parser to grab the outputs of a fragment shader
*
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic -pedantic-errors glsl_regex.cpp -o glsl_regex
*/
#include <iostream>
#include <string>
#include <vector>
@hamsham
hamsham / camera_clip.cpp
Last active Feb 3, 2016
FOV-based camera clipping in 3D
View camera_clip.cpp
bool is_point_in_fov(const ls::draw::Camera& cam, math::vec3 point, const float fovReduction = 1.f) {
// Get the local camera's absolute position and direction in world-space
const math::vec3&& eyePos = cam.get_abs_position();
const math::vec3&& eyeDir = math::normalize(cam.get_eye_direction());
// translate the input point using a model-view matrix (no projection
// matrix should be used).
const math::mat4&& mvMat = modelMatrix * cam.get_view_matrix();
const math::vec4&& temp = math::vec4{-point[0], -point[1],-point[2], 0.f} * mvMat;
@hamsham
hamsham / num_zeros.cpp
Created Jan 4, 2016
Count the number of leading and trailing zeroes in an integer.
View num_zeros.cpp
/**
* Count the number of leading and trailing zeroes in an integer
*
* g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors num_zeros.cpp -o num_zeros
*/
#include <iostream>
#include <cstdint>
@hamsham
hamsham / bn_strassen.cpp
Last active Jan 4, 2016
Bignum multiplication of numbers with arbitrary bases, using the Schönhage-Strassen algorithm.
View bn_strassen.cpp
/**
* Bignum multiplication of numbers with arbitrary bases, using the
* Schonhage-Strassen algorithm.
*
* g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors bn_strassen.cpp -o bn_strassen
*
* usage: bn_strassen.exe 123456789 987654321
*
* Sources:
@hamsham
hamsham / bn_karatsuba.cpp
Last active Jan 2, 2016
Bignum multiplication of numbers with arbitrary bases, using Karatsuba's algorithm.
View bn_karatsuba.cpp
/**
* Bignum multiplication of numbers with arbitrary bases, using Karatsuba's algorithm.
*
* g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors bn_karatsuba.cpp -o bn_karatsuba
*
* usage: bn_karatsuba.exe 123456789 987654321
*/
#include <algorithm>