Skip to content

Instantly share code, notes, and snippets.


John Bartholomew johnbartholomew

View GitHub Profile
View test.c
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
static void check_access(const char *path) {
int ret = access(path, F_OK);
if (ret == -1) {
int e = errno;
printf("access '%s' failed: %s\n", path, strerror(e));

Some definitions:

  • A "safe" transformation is a transformation of a path A into a path B such that any file system operation on path A will produce the same behaviour if given path B.

  • "normalize" means remove redundant directory separators (including trailing separators) and replace non-canonical separators with canonical separators (on Windows, backslash is the canonical separator, but forward slashes are also recognised as separators. On POSIX, forward slash is the only separator character and is canonical). Normalization is trivially "safe"; it doesn't add or remove any path components,

johnbartholomew / gist:6811245
Last active Dec 24, 2015
Creating statically linkable C "packages"
View gist:6811245
#define PACKAGE_PRIVATE __attribute__((__visibility__("hidden")))
#define PACKAGE_PUBLIC __attribute__((__visibility__("default")))
/* -------- a.c -------- */
static int the_thing = 42;
PACKAGE_PRIVATE int compute_thing(void) {
return the_thing;
View text.glsl
// ---- text.vert.glsl
#version 150
uniform vec2 text_offset;
uniform vec2 rcp_screen_size;
in vec2 v_screen_pos;
in vec2 v_uv;
out vec2 f_uv;
johnbartholomew / ClangWarnGlobals.cpp
Created May 28, 2013
A Clang plugin to generate warnings for non-const global variables.
View ClangWarnGlobals.cpp
// -Wglobals Clang plugin
// Based on example plugins and searching Clang's API documentation.
// BEWARE! This is my first ever attempt at a Clang plugin.
// Makefile
#if 0 WarnGlobals.cpp
clang++ -std=c++98 -shared -fPIC $$(llvm-config --cflags --libs support mc) -o "$@" $^ -L/usr/lib/llvm/ -lclang
johnbartholomew / TestJourney.lua
Created May 14, 2013
Pioneer autopilot test script
View TestJourney.lua
RepeatJourney = true
local journeys = {}
Event.Register('onGameStart', function ()
journeys = {}
Event.Register('onShipDocked', function (ship, station)
local journey = journeys[ship]
View test.cpp
// build with: g++ -std=c++98 -Wall -ocheck test.cpp
#include <iostream>
#include <string>
#include <sstream>
int parse_int(const char *x) {
std::istringstream ss(x);
int y;
ss >> y;
johnbartholomew / gist:5434034
Last active Dec 16, 2015
Pioneer approximate code style conventions
View gist:5434034
Classes, namespaces and methods are LikeThis.
Non-public member variables are m_likeThis.
Local variables and local constants are likeThis.
Public member variables are likeThis, but you should think about making them non-public and providing an accessor instead.
Accessors are called GetFooBar() and SetFooBar(), but you should think about whether you really want to provide SetFooBar() or if you want to provide nicer verb methods (e.g., Missile provides Arm() and Disarm(), rather than SetArmed()).
View GetNearbyStations.lua
-- Gets a list of stations in nearby systems that match some criteria.
-- Example:
-- local orbital_ports = Game.system:GetNearbyStationPaths(
-- 30, nil, function (station) return station.type == 'STARPORT_ORBITAL' end, true)
-- for i = 1, #orbital_ports do
-- local path = orbital_ports[i]
-- print(path, ' -- ', path:GetSystemBody().name, ' in system ', path:GetStarSystem().name)
View declare_file_struct.h
#if 0 /* example use: */
/* if EMIT_FIXUP_DEFINITIONS is 0 or undefined then
* only the struct declaration will be emitted
* typically you want to only emit fixup function
* definitions in a single translation unit.