Skip to content

Instantly share code, notes, and snippets.

View mayoff's full-sized avatar
😷
status messages are fun

Rob Mayoff mayoff

😷
status messages are fun
View GitHub Profile
@mayoff
mayoff / !README.md
Last active August 14, 2023 15:09
Debugging Objective-C blocks in lldb

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 December 23, 2017 06:43
Hello, Triangle! (MetalKit + Swift 4)
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!
@mayoff
mayoff / convert.swift
Last active June 16, 2021 23:07
How to convert from DispatchData to Data without copying the bytes
import Dispatch
import Foundation
var x = 7
let dd = withUnsafeBytes(of: &x, { DispatchData.init(bytes: $0) })
print(dd as? Data) // Case 1: nil
print(dd as? NSData) // Case 2: nil
print(dd as Any as? Data) // Case 3: nil
print(dd as Any as? NSData) // Case 4: .some
print(dd as Any as? NSData as Data?) // Case 5: .some
@mayoff
mayoff / StrokedPath.swift
Created July 17, 2017 04:10
stroked path playground
import UIKit
import ImageIO
import MobileCoreServices
import PlaygroundSupport
let documentFolderUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
print(documentFolderUrl)
class ShapeView: UIView {
override class var layerClass: AnyClass { return CAShapeLayer.self }
@mayoff
mayoff / step1.sh
Created June 20, 2017 22:39
Services menu item to toggle Finder's desktop icons
if [[ $(defaults read com.apple.Finder CreateDesktop 2>/dev/null) = YES ]]; then
defaults write com.apple.Finder CreateDesktop NO
else
defaults write com.apple.Finder CreateDesktop YES
fi
@mayoff
mayoff / finder_icons.sh
Created June 20, 2017 15:24 — forked from chockenberry/finder_icons.sh
A simple shell script to turn the Finders desktop icons on and off
#!/bin/sh
defaults read com.apple.finder CreateDesktop > /dev/null 2>&1
enabled=$?
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
defaults write com.apple.finder CreateDesktop false
osascript -e 'tell application "Finder" to quit'
open -a Finder
@mayoff
mayoff / main.m
Created May 31, 2017 15:43
adding objc_boxable to CoreGraphics structs
@import Foundation;
@import CoreGraphics;
typedef struct __attribute__((objc_boxable)) CGPoint CGPoint;
typedef struct __attribute__((objc_boxable)) CGSize CGSize;
typedef struct __attribute__((objc_boxable)) CGRect CGRect;
typedef struct __attribute__((objc_boxable)) CGVector CGVector;
int main(int argc, const char * argv[]) {
@autoreleasepool {