Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Wisenbaker macshome

View GitHub Profile
View TheWisdomOfQuinn.md

This page is now depreacted!

Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.

The Wisdom of Quinn

Informative DevForum posts from everyone's favorite DTS member.

(Arranged newest to oldest)

@macshome
macshome / day2.swift
Created Dec 5, 2019
Advent of Code 2019 Day 2 - The Ugliness
View day2.swift
import Cocoa
typealias IntcodeProgram = [Int]
func loadInput() throws -> IntcodeProgram {
do {
let inputFile = URL(fileReferenceLiteralResourceName: "input.txt")
let rawInput = try String(contentsOf: inputFile)
let splitFile = rawInput.components(separatedBy: .punctuationCharacters)
return splitFile.compactMap { Int($0) }
@macshome
macshome / day1.swift
Last active Dec 4, 2019
Advent of Code 2019 - Day 1
View day1.swift
import Foundation
// Code-golf version
let inputFile = URL(fileReferenceLiteralResourceName: "input.txt")
print(try! String(contentsOf: inputFile).components(separatedBy: .newlines).compactMap { Float($0) }.map { Int(($0 / 3).rounded(.down) - 2) }.reduce(0, +))
// Fancy version
typealias ModuleHopper = [Module]
typealias MassCalculations = [Float]
@macshome
macshome / uptime.swift
Created Jan 31, 2019
Function to get the uptime in seconds on Apple platforms
View uptime.swift
func getUptime() -> Int {
let nanoseconds = DispatchTime.now()
return Int(nanoseconds.rawValue / 1000000000)
}
@macshome
macshome / StoryboardExtensionsBeta4Fix.swift
Created Jul 29, 2014
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.
View StoryboardExtensionsBeta4Fix.swift
//
// 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 Jan 9, 2014
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…
View SKPhyscisBody speed limiter
// 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 Apr 26, 2012
Super Simple MC Simulation on OS X 10.7. No error checking or anything like that…
View gist:2500721
#import <Foundation/Foundation.h>
#define ARC4RANDOM_MAX 0x100000000
int main(int argc, const char * argv[])
{
@autoreleasepool {
long double hit = 0;