Skip to content

Instantly share code, notes, and snippets.

Rob Mayoff mayoff

Block or report user

Report or block mayoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mayoff
mayoff / decode-dyn-uti.swift
Created Mar 14, 2019
Swift command-line script to decode dynamic UTIs
View decode-dyn-uti.swift
#!/usr/bin/xcrun swift
// http://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
extension String {
static let bitsForCodeUnit: [Character: [UInt8]] = {
var dict = [Character: [UInt8]]()
for (i, ch) in "abcdefghkmnpqrstuvwxyz0123456789".enumerated() {
let bits = Array((0 ..< 5).map({ UInt8((i >> $0) & 1) }).reversed())
dict[ch] = bits
@mayoff
mayoff / unowned-safety-dance.swift
Created Feb 23, 2019
test Swift unowned safety
View unowned-safety-dance.swift
class MyObject { }
var o = MyObject()
print("strong o = \(o)")
unowned let u = o
print("unowned u = \(u)")
o = MyObject()
@mayoff
mayoff / main.m
Created Feb 11, 2019
Set pHYs chunk (DPI) of PNG
View main.m
@import AppKit;
@import ImageIO;
@import CoreServices;
#define fromCF (__bridge id)
#define toCF (__bridge CFTypeRef)
int main(int argc, const char * argv[]) {
@autoreleasepool {
CGRect rect = CGRectMake(0, 0, 100, 100);
@mayoff
mayoff / wedges-with-gaps.swift
Created Dec 27, 2018
Simon game wedges in iOS
View wedges-with-gaps.swift
import UIKit
import PlaygroundSupport
typealias Radians = CGFloat
extension UIBezierPath {
static func simonWedge(innerRadius: CGFloat, outerRadius: CGFloat, centerAngle: Radians, gap: CGFloat) -> UIBezierPath {
let innerAngle: Radians = CGFloat.pi / 4 - gap / (2 * innerRadius)
let outerAngle: Radians = CGFloat.pi / 4 - gap / (2 * outerRadius)
@mayoff
mayoff / Decimal.py
Created Oct 10, 2018
Decimal / NSDecimal support for lldb
View Decimal.py
# Decimal / NSDecimal support for lldb
#
# Put this file somewhere, e.g. ~/.../lldb/Decimal.py
# Then add this line to ~/.lldbinit:
# command script import ~/.../lldb/Decimal.py
import lldb
def stringForDecimal(sbValue, internal_dict):
from decimal import Decimal, getcontext
View Main.storyboard
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina3_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@mayoff
mayoff / !README.md
Last active May 7, 2019
Debugging Objective-C blocks in lldb
View !README.md

The attached lldb command pblock command lets you peek inside an Objective-C block. It tries to tell you where to find the source code for the block, and the values captured by the block when it was created.

Consider this example program:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

@implementation Foo
@mayoff
mayoff / minimal-metal.swift
Created Dec 23, 2017
Hello, Triangle! (MetalKit + Swift 4)
View minimal-metal.swift
import Cocoa
import MetalKit
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, MTKViewDelegate {
weak var window: NSWindow!
weak var metalView: MTKView!
let device = MTLCreateSystemDefaultDevice()!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
You can’t perform that action at this time.