Skip to content

Instantly share code, notes, and snippets.

View tomgco's full-sized avatar
☠️
Building stuff

Tom Gallacher tomgco

☠️
Building stuff
View GitHub Profile
@tomgco
tomgco / ordinal date suffix
Created June 12, 2011 12:05
Generate a ordinal suffix for a given int in Objective-C
- (NSString*)getOrdinalSuffix: (int)number {
NSArray *suffixLookup = [NSArray arrayWithObjects:@"th",@"st",@"nd",@"rd",@"th",@"th",@"th",@"th",@"th",@"th", nil];
if (number % 100 >= 11 && number % 100 <= 13) {
return [NSString stringWithFormat:@"%d%@", number, @"th"];
}
return [NSString stringWithFormat:@"%d%@", number, [suffixLookup objectAtIndex:(number % 10)]];
}
@tomgco
tomgco / XboxControllerOnMac.m
Created August 27, 2011 21:37
Xbox Controller Methods in My ArduinoCopter Project.
- (void) RCTriggerRT:(DDHidJoystick *)joystick valueChanged:(NSNumber *)value {
// To use for Throttle;
}
- (void) RCRightJoystickX:(DDHidJoystick *)joystick valueChanged:(NSNumber *)value {
// Trim
}
- (void) RCRightJoystickY:(DDHidJoystick *)joystick valueChanged:(NSNumber *)value {
// Pitch
@tomgco
tomgco / smokeping-avg-loss
Created December 2, 2011 14:03
Get the average packet loss from a smokeping rrd.
rrdtool graphv "-" DEF:a="TomMacMini.rrd":loss:AVERAGE CDEF:ploss=a,100,*,20,/ PRINT:ploss:AVERAGE:"Average\:%.2lf %% avg" --end now --start end-1200

dis.io

What is dis.io

dis.io is a distributed computing platform that utilises idle CPU cycles from within a web browser or the command line, built purely on JavaScript and node.js.

The name dis.io descends from two origins. The first is that is was built as part of my Dissertation for my Degree in Computing BSc at Bournemouth University, however the other origin, which I personally think it is much better at describing the project is because it is a distributed computing platform.

Installation

@tomgco
tomgco / gist:1799570
Created February 11, 2012 14:10
Inheritance without module pattern and no use of __proto__
// define a new type SkinnedMesh and a constructor for it
function SkinnedMesh(geometry, materials) {
// call the superclass constructor
THREE.Mesh.call(this, geometry, materials);
// initialize instance properties
this.identityMatrix = new THREE.Matrix4();
this.bones = [];
this.boneMatrices = [];
...
@tomgco
tomgco / gist:1951303
Created March 1, 2012 16:50
Set wallpaper on osx
tell application "Finder"
set desktop picture to {
"Your HD:Users:YourUserName:desktops:" & situation & ".jpg"
} as alias
end tell
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); //run event handler on the default global queue
dispatch_time_t now = dispatch_walltime(DISPATCH_TIME_NOW, 0);
dispatch_source_set_timer(timer, now, 140ull * NSEC_PER_MSEC, 5000ull);
dispatch_source_set_event_handler(timer, ^{
[self sendPacket:CHANNEL1 yaw:[yaw intValue] pitch:[pitch intValue] throttle:[throttleJoystick intValue] trimAdjust:[trim intValue]];
// NSLog(@"%d %d %d %d", [yaw intValue], [pitch intValue], [throttleJoystick intValue], [trim intValue]);
if ([[NSApp delegate] isSerialPortConnected] == YES) {
@tomgco
tomgco / gist:2029979
Created March 13, 2012 17:15
Match TV Show Pattern
.*((S)[0-9]{2,}(E)[0-9]{2,}|[0-9]{1,}(x)[0-9]{1,}).*
\documentclass[11pt,a4paper]{article}
% for images.
\usepackage{graphicx}
\usepackage{setspace}
% for code blocks
\usepackage{listings}
% referencing using surname first
\usepackage{natbib}
@tomgco
tomgco / BULaTeX.bst
Created April 24, 2012 23:39
Bournemouth Uni LaTeX Reference style
%% File: `BULaTeX.bst'
%% A modification of `plain.bst' for use with natbib package by Tom Gallacher,
%% Orders by Last Name, with last name first.
%% Abbreviations for first names.
%% added last modified for urls
%% Reference: http://www.bournemouth.ac.uk/library/citing_references/docs/Citing_Refs.pdf
%%
%% Copyright 1993-2007 Patrick W Daly
%% Max-Planck-Institut f\"ur Sonnensystemforschung
%% Max-Planck-Str. 2