Skip to content

Instantly share code, notes, and snippets.

preshing / ManifoldGarden.asl
Last active Mar 2, 2020
Manifold Garden AutoSplit script
View ManifoldGarden.asl
// AutoSplit script for Manifold Garden
// Automatically starts the timer ~2.4 seconds after starting a new game, and splits the timer
// when transitioning between game levels. You must still reset the timer manually between runs.
// If you accidentally backtrack through a portal, causing an unwanted split, you'll have
// to undo it manually (default NumPad8 in LiveSplit).
// To compensate for the late start, you should delay your start timer by 2.4 seconds in LiveSplit.
// (Right-click -> Edit Splits -> Start timer at:)
preshing / gist:561dca75964f284b376b1610b11735fd
Created Apr 27, 2019
Testing range-based for loop over explicitly created std::initializer_list
View gist:561dca75964f284b376b1610b11735fd
Results of a few quick tests performed in response to:
// This is the original version that HAS the bug (garbage value encountered during iteration):
for (const AxisRay& faceRelVedge : std::initializer_list<AxisRay>{
{{0, 0, -1}, Axis3::YNeg},
{{0, 1, 0}, Axis3::ZPos},
{{-2, -1, 0}, Axis3::ZPos},
{{-1, -1, -1}, Axis3::XPos}}) {
preshing / main.cpp
Created Jan 3, 2018
Use SFINAE to call member function if present
View main.cpp
#include <iostream>
class Foo {
void bar() {
std::cout << "Foo::bar() called" << std::endl;
class Foo2 {
import datetime
import re
import os
badTimeStamp = datetime.datetime.strptime("2010-03-08 15:02:59 -0500", "%Y-%m-%d %H:%M:%S %z")
desiredTimeStamp = datetime.datetime.strptime("2017-08-28 11:15:59 -0400", "%Y-%m-%d %H:%M:%S %z")
delta = desiredTimeStamp - badTimeStamp
for line in open("../backup.log", "r"):
m = re.match("r(\\d+) \\| jeff \\| (.*) \(", line)
View spinlock-example.cpp
#include <atomic>
class SpinLock {
std::atomic<int> m_flag = 0;
void lock() {
int expected = 0;
while (!m_flag.compare_exchange_weak(expected, 1, std::memory_order_acquire)) {
expected = 0;
preshing / build_cross_gcc
Last active Apr 15, 2021
A shell script to download packages for, configure, build and install a GCC cross-compiler.
View build_cross_gcc
#! /bin/bash
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT
# This script will download packages for, configure, build and install a GCC cross-compiler.
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
# If you get an error and need to resume the script from some point in the middle,
# just delete/comment the preceding lines before running it again.
preshing / capped_spsc_queue.cpp
Created Oct 23, 2014
Generate benchmarks for three implementations of a wait-free queue using C++11 atomics
View capped_spsc_queue.cpp
// Generate benchmarks for the three queue implementations shown in
// Jeff Preshing's CppCon 2014 talk, "How Ubisoft Montreal Develops Games for
// Multicore - Before and After C++11".
// Slides:
#include <iostream>
#include <atomic>
preshing / math.rb
Created Oct 27, 2013
MathJax tags for Octopress
View math.rb
# MathJax tags for Octopress
# Put this in the plugins folder.
# Use a single "inlinemath" tag for inline math.
# Use a pair of "math/endmath" tags for math as a standalone paragraph.
# The "math" tag takes an optional size argument.
# You also need to include MathJax in the page header, for example by adding
# <script type="text/javascript" src=""></script>
# to source/_includes/custom/head.html
View gist:6663087
#include <mintomic/mintomic.h>
#include <time.h>
struct Message
clock_t tick;
const char* str;
void* param;
preshing /
Last active Jan 21, 2016
List the contents of folders recursively, sorted by modification time.
#! /usr/bin/env python
# License:
# See
import optparse
import os
import fnmatch
import time
# Parse options
parser = optparse.OptionParser(usage='Usage: %prog [options] path [path2 ...]')