Skip to content

Instantly share code, notes, and snippets.

Avatar

John Bartholomew johnbartholomew

View GitHub Profile
@johnbartholomew
johnbartholomew / RomanNumerals.hs
Created Jan 15, 2012
A solution to John D. Cook's roman numerals puzzle
View RomanNumerals.hs
-- written for a puzzle presented by John D. Cook:
-- http://www.johndcook.com/blog/2012/01/14/roman-numeral-puzzle/
--
-- Copyright (C) 2012, John Bartholomew.
-- You may use this code for any purpose, WITHOUT WARRANTY.
module Main where
import Control.Monad
import Data.Char
@johnbartholomew
johnbartholomew / screencap.sh
Created Feb 19, 2012
ffmpeg screen recording
View screencap.sh
#!/bin/bash
# codec configuration from
# http://code.google.com/p/bencos/source/browse/trunk/out/presets/libx264-lossless_ultrafast.ffpreset?r=156
cat > libx264-lossless_ultrafast.ffpreset <<EOF
coder=0
flags=+loop
cmp=+chroma
partitions=-parti8x8-parti4x4-partp8x8-partp4x4-partb8x8
View StateCapturer.h
// simplest version
struct StateCapturer {
StateCapturer() {
glPushAttrib(...);
glPushMatrix(...);
glPushTheWholeDamnWorld();
}
~StateCapturer() {
@johnbartholomew
johnbartholomew / byte-order-test.c
Created Apr 4, 2012
compiler smarts: recognising shifts and ors as a load or byte-swap
View byte-order-test.c
#include <string.h>
#include <stdint.h>
/* compiled with:
* {gcc,clang} -std=c89 -pedantic -Wall -Wextra -O3 -S -c byte-order-test.c
*
* Built on and for an x86-64 system.
* The full assembly output from both compilers is embedded at the bottom.
*
* Summary:
@johnbartholomew
johnbartholomew / gist:3969948
Created Oct 28, 2012
Some git instructions
View gist:3969948

This assumes you have no changes loose in your working copy.

At any point you can run gitk to view the commit history. I use gitk all the time, to view and search through the commit history, find the SHA1 hash of a particular commit, and check the commit graph.

First, make sure master is up to date (it most likely already is, but no harm in checking)

git checkout master
git fetch upstream
View gist:3992010
template <typename T> struct ForceConstRef { typedef const T& type; };
template <typename T> struct ForceConstRef<const T&> { typedef const T& type; };
template <typename T> struct ForceConstRef<const T> { typedef const T& type; };
template <typename T> struct ForceConstRef<T&> { typedef const T& type; };
template <typename T0, typename T1>
class LuaSignalTrampoline : public LuaSignalTrampolineBase {
public:
typedef typename ForceConstRef<T0>::type type0;
typedef typename ForceConstRef<T1>::type type1;
View cheatMission.lua
Translate:Add({
English = {
cheats = 'Cheats!',
}
})
local ui = Engine.ui
local t = Translate:GetTranslator()
local cheatMission = function (loaded)
@johnbartholomew
johnbartholomew / test.cpp
Created Dec 16, 2012
Checking overloads for sin and cos functions in C++11
View test.cpp
#include <cmath>
#include <type_traits>
static_assert(std::is_same<float, decltype(std::sin(3.1f))>::value,
"std::sin not overloaded for float");
static_assert(std::is_same<double, decltype(std::sin(3.1))>::value,
"std::sin not overloaded for double");
static_assert(std::is_same<long double, decltype(std::sin(3.1l))>::value,
"std::sin not overloaded for long double");
View FindImportExport.lua
function MinMaxCommodity(sys)
sys = sys or Game.system
if sys:isa('SystemPath') then
sys = sys:GetStarSystem()
end
local alt = sys:GetCommodityBasePriceAlterations()
local minPrice = math.huge
local maxPrice = -math.huge
local minCargo, maxCargo
View streams.lua
function numbered_keys(step, context, position)
local k = position
local f = function(s, i)
local v
k,v = step(s, k)
if k ~= nil then
return (i+1), v
end
end