Skip to content

Instantly share code, notes, and snippets.

View kconner's full-sized avatar
✍️

Kevin Conner kconner

✍️
View GitHub Profile
@kconner
kconner / manx.sh
Last active August 14, 2023 15:20
manx [section] <page>: Creates and opens a PDF for a manpage
# Tested on macOS 13.
function manx {
if [ "$1" = "" ]; then
echo "manx [section] <page>: Creates and opens a PDF for a manpage."
else
pdfpath="/tmp/$*.man.pdf"
man -t $* | pstopdf -o "$pdfpath"; open "$pdfpath"
fi
}
@kconner
kconner / macOS Internals.md
Last active May 6, 2024 22:20
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

Keyboard Shortcuts and Workflow Efficiencies

This is incomplete. It was inspired by a mutual exchange of eye-opening keyboard shortcuts.

Introduction

If you want to work creatively, it helps to remove interruptions and wait times. Using a computer is meant to be faster than doing things by hand, and creative work is one reason we use them. We know from experience what it's like to use an app that you have to wait for, versus an app that keeps up with you. The app that keeps up with you lets you do better work because you remain more focused, and it's more fun to use. But you, too, can either be fast or slow as a user. Computers spend most of their time waiting on us. So if you want to do your very best creative work with a computer, it will help if you and the computer get faster together.

Mac apps

@kconner
kconner / printData.swift
Created May 31, 2017 21:37
Print the bytes of a Data in hexadecimal
private func printData(_ data: Data) {
let hexBytes = data.map { byte in
String(format: "%02x", byte)
}
for (offset, hexByte) in hexBytes.enumerated() {
let terminator: String
switch offset % 8 {
case 7:
terminator = "\n"
E017 DO YOU EXPECT ME TO FIGURE THIS OUT?
E079 PROGRAMMER IS INSUFFICIENTLY POLITE
E099 PROGRAMMER IS OVERLY POLITE
E111 COMMUNIST PLOT DETECTED, COMPILER IS SUICIDING
E123 PROGRAM HAS DISAPPEARED INTO THE BLACK LAGOON
E127 SAYING ’ABRACADABRA’ WITHOUT A MAGIC WAND WON’T DO YOU ANY GOOD
E129 PROGRAM HAS GOTTEN LOST
E139 I WASN’T PLANNING TO GO THERE ANYWAY
E182 YOU MUST LIKE THIS LABEL A LOT!
E197 SO! 65535 LABELS AREN’T ENOUGH FOR YOU?
# .khdrc script for https://github.com/koekeishiya/khd
# lcmd + .OEU (Dvorak ESDF) = arrows
lcmd - o : /usr/local/bin/khd -p "- left"
lcmd - e : /usr/local/bin/khd -p "- down"
lcmd - 0x0e : /usr/local/bin/khd -p "- up"
lcmd - u : /usr/local/bin/khd -p "- right"
rcmd + lcmd - o : /usr/local/bin/khd -p "cmd - left"
rcmd + lcmd - e : /usr/local/bin/khd -p "cmd - down"
@kconner
kconner / GameViewController.swift
Last active February 7, 2017 01:10
Xcode 6.3 OpenGL Game template ported to Swift. (Add "-D DEBUG" to Other Swift Flags setting)
import GLKit
// Uniform index.
private enum Uniform {
case ModelViewProjectionMatrix, NormalMatrix
}
private var gUniforms: [Uniform: GLint] = [:]
extension GLKMatrix3 {
var array: [Float] {
@kconner
kconner / gist:eb1ef62edd0ff991a186
Created November 21, 2014 18:49
Currying, argument reordering, and partial function application in Swift
func curry<T, U, R>(binary: (T, U) -> R) -> T -> U -> R {
return { t in
return { u in
return binary(t, u)
}
}
}
func curry<T, U, V, R>(ternary: (T, U, V) -> R) -> T -> U -> V -> R {
return { t in
@kconner
kconner / gist:dfecaa5a26acf4c65f9b
Created November 14, 2014 18:52
Memoization in Swift
class Memo<T> {
private let closure: () -> T;
private var result: T?
var value: T {
if let value = result {
return value
} else {
let value = closure()
println("computed \(value)")
@kconner
kconner / monitor.sh
Created October 22, 2014 14:07
Monitor whether a given URL gives you a 200
#!/bin/bash
echo "Monitoring."
while true; do
if curl -s --head $1 | grep "200 OK" > /dev/null; then
echo "ok" $1
else
echo ":(" $1
fi