Skip to content

Instantly share code, notes, and snippets.

View garymacindoe's full-sized avatar

Gary Macindoe garymacindoe

View GitHub Profile
#!/bin/bash
#
# Converts mercurial repostories to git repositories.
# Requires git-remote-hg from https://github.com/felipec/git-remote-hg.
#
if [ $# -lt 2 ] || [ $# -gt 3 ]
then
echo "Usage: ${0} <url> <local_directory> [user_map]"
echo "Where"
@garymacindoe
garymacindoe / woo.cpp
Created August 12, 2015 15:16
Implementation of voxel traversal algorithm from "A Fast Voxel Traversal Algorithm for Ray Tracing" (Amanatides and Woo)
/*
* Implementation of voxel traversal algorithm from "A Fast Voxel Traversal
* Algorithm for Ray Tracing" (Amanatides and Woo).
*/
#include <iostream>
#include <iterator>
#include <tuple>
#include <limits>
#include <algorithm>
@garymacindoe
garymacindoe / vtable.cpp
Created July 29, 2015 13:55
Calling a private method through the vtable
#include <iostream>
class A {
virtual void function() const {
std::cout << "You bastard!" << std::endl;
}
};
int main() {
A a;
@garymacindoe
garymacindoe / nextpow2.hpp
Created June 18, 2015 14:44
Round up to the next highest power of 2 using C++11 compile-time templates
#include <type_traits>
#include <limits>
template <typename UIntType, UIntType v, unsigned int n>
struct set_lower_bits : public std::integral_constant<UIntType, v | (v >> n) | set_lower_bits<UIntType, v | (v >> n), (n >> 1)>::value> {};
template <typename UIntType, UIntType v>
struct set_lower_bits<UIntType, v, 1> : public std::integral_constant<UIntType, v | (v >> 1)> {};
template <typename UIntType, UIntType v>
@garymacindoe
garymacindoe / check-world
Created May 6, 2015 12:48
Checks for invalid/obsolete entries in Gentoo Portage's world file
#!/bin/bash
#
# Author: Gary Macindoe
# Date: May 2015
WORLD_FILE=/var/lib/portage/world
while read package;
do
DEPS=$(grep -l ${package} /var/db/pkg/*/*/{,R}DEPEND | cut -d'/' -f5,6 | sort -u);
@garymacindoe
garymacindoe / upgrade-kernel
Last active November 25, 2018 19:08
Compiles and installs two versions of a new kernel source - one with an EFI stub loader and one without - using the running kernel's config as a template (requires /proc/config.gz)
#!/bin/bash
#
# Author: Gary Macindoe
# Date: November 2014
set -eu
EFI_KEYS="/root/efi"
LINUX_SOURCE="/usr/src/linux"
@garymacindoe
garymacindoe / check-use
Created April 15, 2015 12:14
Checks for invalid/obsolete entries in Gentoo Portage's package.use files
#!/bin/bash
#
# Author: Gary Macindoe
# Date: May 2013
files="/etc/portage/package.use"
if [ -d "${files}" ]
then
files="${files}/*"
fi
@garymacindoe
garymacindoe / check-keywords
Created April 15, 2015 12:13
Checks for invalid/obsolete keywords in Gentoo Portage's packages.accept_keywords files
#!/bin/bash
#
# Author: Gary Macindoe
# Date: May 2013
files="/etc/portage/package.accept_keywords /etc/portage/package.keywords"
fs=""
for f in ${files}
do
if [ -d "${f}" ]