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
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: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
@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 = [];
...

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 / 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
@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 / 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)]];
}