Skip to content

Instantly share code, notes, and snippets.

View macshome's full-sized avatar

Josh Wisenbaker macshome

View GitHub Profile
@macshome
macshome / GetProcessList.swift
Last active April 29, 2024 05:33
Swift Playground to get all running processes on macOS
import Darwin
func getProcessList() {
// Requesting the pid of 0 from systcl will return all pids
var mib = [CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0]
var bufferSize = 0
// To find the needed buffer size you call sysctl with a nil results pointer.
// This sets the size of the buffer needed in the bufferSize pointer.
if sysctl(&mib, UInt32(mib.count), nil, &bufferSize, nil, 0) < 0 {
@macshome
macshome / swift-format-defaults.md
Last active October 30, 2023 17:27
The default settings for swift-format

swift-format Default Settings

Since I've not found anywhere that describes the default settings of swift-format other than the code, I've pulled those settings out and presented them here.

Rules that are opt-in are marked as such.

Formating-Only Rules

(Most of these rules are defined in the default config, not the rules folder.)

  1. maximumBlankLines = 1
  2. lineLength = 100
  3. tabWidth = 8
@macshome
macshome / defang.md
Last active April 24, 2024 18:31
How to defang system protections on macOS

How to Defang macOS System Protections

If you want to change things on the root drive of a Mac you will need to take some steps to disable the built in security of the system. Most of these steps are the same regardless if you are on Intel or Apple Silicon. If there is a difference it is noted.

Note that all of these things put a Mac into an unsupported and less secure state.

Make sure you either perform these steps in a VM or that you reset the protections after you are done poking around

Protections and Terms

(This list is not exahustive on the details of each. Check the links at the end for more info.)

@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 / 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 / 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 / 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 / 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.