Skip to content

Instantly share code, notes, and snippets.

View macshome's full-sized avatar

Josh Wisenbaker macshome

View GitHub Profile
@macshome
macshome / uptime.swift
Created January 31, 2019 15:47
Function to get the uptime in seconds on Apple platforms
func getUptime() -> Int {
let nanoseconds = DispatchTime.now()
return Int(nanoseconds.rawValue / 1000000000)
}
@macshome
macshome / StoryboardExtensionsBeta4Fix.swift
Created July 29, 2014 15:26
NSTabView and NSSplitView are busted in beta 4 of Xcode 6 when using OS X Storyboards. If you are using Swift you can drop this file into your project to get them working until there is a fix.
//
// StoryboardExtensionsBeta4Fix.swift
//
// A workaround so that you can use SplitView
// and TabView items in OS X Storyboards on
// 10.10. Just drop this in your Swift project.
//
// Hopefully the need for this goes away in soon
// as it used to work.
@macshome
macshome / SKPhyscisBody speed limiter
Created January 9, 2014 17:13
In my asteroids-style game I was looking for a way to limit the speed of the ship so that it didn't get too fast or outrun the missiles it fires. I call this with the update: method on the scene and it just checks the dx and dy values to make sure they are all inside the speed I want to set. In real code I would use a static or value loaded from…
// Speed limiter
- (void)shipSpeedLimit {
// Check the x velocity
if (self.ship.physicsBody.velocity.dx > 500) {
self.ship.physicsBody.velocity = CGVectorMake(500, self.ship.physicsBody.velocity.dy);
} else if (self.ship.physicsBody.velocity.dx < -500) {
self.ship.physicsBody.velocity = CGVectorMake(-500, self.ship.physicsBody.velocity.dy);
}
@macshome
macshome / gist:2500721
Created April 26, 2012 16:23
Super Simple MC Simulation on OS X 10.7. No error checking or anything like that…
#import <Foundation/Foundation.h>
#define ARC4RANDOM_MAX 0x100000000
int main(int argc, const char * argv[])
{
@autoreleasepool {
long double hit = 0;