Skip to content

Instantly share code, notes, and snippets.

View macshome's full-sized avatar

Josh Wisenbaker macshome

View GitHub Profile
@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 / 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;
@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 / 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 / day1.swift
Last active December 4, 2019 00:09
Advent of Code 2019 - Day 1
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 / day2.swift
Created December 5, 2019 00:58
Advent of Code 2019 Day 2 - The Ugliness
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 / gist:504ad02e852a125abaab6ab49b503a19
Created June 16, 2022 15:20
Shell aliases to make working with Anka Clusters simpler
alias anka='sudo /usr/local/bin/anka'
alias ankacluster='sudo /usr/local/bin/ankacluster'
alias clusterjoin='sudo ankacluster join http://<YOUR_CONTROLLER> -m 3 -H `hostname`'
alias clusterdisjoin='sudo ankacluster disjoin'
alias lsvm='sudo anka list'

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 / adlookups.sh
Last active December 8, 2022 14:37
Simple shell script to lookup service records in an AD domain on macOS.
#!/bin/zsh
zparseopts -E -D -- D:=DOMAIN -domain:=DOMAIN d=DNS -dns=DNS
DOMAIN=$DOMAIN[2]
DNS=$DNS
if [[ -z $DOMAIN ]]; then
echo "adlookupos.sh: Troubleshoot DNS service records needed for AD."
echo "\nUsage: adlookups.sh [-d] [-D domain]"
@macshome
macshome / MemoryLayout.swift
Created April 3, 2023 19:20
Swift playground for exploring memory layout
import Foundation
// Playground for exploring memory layout in Swift.
// A simple struct
struct Foo {
let a: Int?
let b: Int?
var isTrue = true
}