Skip to content

Instantly share code, notes, and snippets.

View nickrolfe's full-sized avatar

Nick Rolfe nickrolfe

  • GitHub Staff
  • Oxford, UK
  • X @nckrlf
View GitHub Profile
@nickrolfe
nickrolfe / unit.c
Created January 31, 2018 22:01
C unit test auto-discovery
#include <stdbool.h>
#include <stdio.h>
//------------------------------------------------------------------------------
// The code we're testing
int add_one(int x) {
return x + 1;
}
int multiply(int x, int y) {
//----------------------------------------------------------------------
// in opengl.h
XX(PFNGLACTIVETEXTUREPROC, glActiveTexture)
XX(PFNGLATTACHSHADERPROC, glAttachShader)
XX(PFNGLBINDBUFFERPROC, glBindBuffer)
// etc.
//----------------------------------------------------------------------
// in a C file
// Define all the OpenGL function pointers
@nickrolfe
nickrolfe / windows_modern_opengl_context.c
Last active April 24, 2024 13:00
Sample code showing how to create a window using a modern OpenGL core profile context without any libraries other than the standard Win32 wglXXX calls.
// Sample code showing how to create a modern OpenGL window and rendering context on Win32.
#include <windows.h>
#include <gl/gl.h>
#include <stdbool.h>
typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext,
const int *attribList);
wglCreateContextAttribsARB_type *wglCreateContextAttribsARB;
/* A simple dictionary implementation in Rust, using a hash table with
* chaining and table doubling.
*
* Tested with Rust nightly 2014-06-27
*/
extern crate collections;
use std::hash;
use std::hash::Hash;
-- Compute all n! permutations of a list of n objects
--
-- The algorithm is Method 1 from Knuth's The Art of Computer Programming
-- Volume 1, Chapter 1, Section 1.2.5 Permutations and Factorials.
-- Given an object x and a list of objects ys of length n, insert will return a
-- list of n+1 lists by inserting x in all posssible places in ys.
-- e.g. insert 1 [2,3,4] returns the following:
-- [[1,2,3,4], [2,1,3,4], [2,3,1,4], [2,3,4,1]]