Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am erynofwales on github.
  • I am erynofwales (https://keybase.io/erynofwales) on keybase.
  • I have a public key whose fingerprint is 7BDF 859E 4100 1C15 1A9F 0B11 FF6C 66F5 E56D 0154

To claim this, I am signing this object:

@erynofwales
erynofwales / matrix.cc
Created August 8, 2014 17:44
Matrix multiplication in C++
#include <cstdio>
template<unsigned int N, unsigned int M>
struct Matrix
{
static const unsigned int sRows = N;
static const unsigned int sCols = M;
template <unsigned int P>
Matrix<N, P>
@erynofwales
erynofwales / gist:933248
Created April 20, 2011 22:39
Get absolute path of directory for running script
BASE=$(cd "$(dirname "$0")" && pwd)
@erynofwales
erynofwales / brew doctor
Created August 8, 2011 20:10
Homebrew ledger install error
2236 13:08:37 ~ % brew doctor
Your OS X is ripe for brewing.
Any troubles you may be experiencing are likely purely psychosomatic.
@erynofwales
erynofwales / rotates.c
Created September 8, 2011 06:43
Do bit rotations with bit shifts in C
/* Do bit rotations. x is the data to rotate, c is the number of bits to rotate */
#define ROTATE_R(x,c) (x) = ((x) >> c) | ((x) << (sizeof(x) - c))
#define ROTATE_L(x,c) (x) = ((x) << c) | ((x) >> (sizeof(x) - c))
@erynofwales
erynofwales / gist:1204469
Created September 8, 2011 19:46
Tell branch foo to track upstream/foo
git branch --set-upstream foo upstream/foo
@erynofwales
erynofwales / gist:1207439
Created September 9, 2011 21:56
Pipe output of a command, newline separated, through a loop. This only works on KSH derivatives, including ZSH.
command | while read x; do [some stuff on $x]; done
@erynofwales
erynofwales / gist:1207898
Created September 10, 2011 03:58
Creating temporary directories in Cocoa/Objective-C
// Create a unique temporary direction
// This procedure is safe from a number of potential problems including
// concurrency, file permission, security, and persistence issues
// Taken from http://cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html
NSString *tmpdirTemplate = [NSTemporaryDirectory()
stringByAppendingPathComponent:@"app.XXXXXX"];
const char *tmpdirTemplateCStr = [tmpdirTemplate fileSystemRepresentation];
char *tmpdirCStr = (char *) malloc(strlen(tmpdirTemplateCStr) + 1);
strcpy(tmpdirCStr, tmpdirTemplateCStr);
@erynofwales
erynofwales / gist:1233449
Created September 21, 2011 22:00
PowerShell: Get list of commands in a particular module
$module = 'name.of.module'
Get-Command | Where { $_.ModuleName -Eq $module }
@erynofwales
erynofwales / gist:1340439
Created November 4, 2011 20:45
Get all directories in current directory (except .)
find . -maxdepth 1 -type d -print | sed '/^.$/d'