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 / minimal-metal.swift
Created Dec 23, 2017
Hello, Triangle! (MetalKit + Swift 4)
View minimal-metal.swift
import Cocoa
import MetalKit
class AppDelegate: NSObject, NSApplicationDelegate, MTKViewDelegate {
weak var window: NSWindow!
weak var metalView: MTKView!
let device = MTLCreateSystemDefaultDevice()!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
mayoff / convert.swift
Last active Jun 17, 2019
How to convert from DispatchData to Data without copying the bytes
View convert.swift
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 / StrokedPath.swift
Created Jul 17, 2017
stroked path playground
View StrokedPath.swift
import UIKit
import ImageIO
import MobileCoreServices
import PlaygroundSupport
let documentFolderUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
class ShapeView: UIView {
override class var layerClass: AnyClass { return CAShapeLayer.self }
mayoff /
Created Jun 20, 2017
Services menu item to toggle Finder's desktop icons
if [[ $(defaults read CreateDesktop 2>/dev/null) = YES ]]; then
defaults write CreateDesktop NO
defaults write CreateDesktop YES
mayoff /
Created Jun 20, 2017 — forked from chockenberry/
A simple shell script to turn the Finders desktop icons on and off
defaults read CreateDesktop > /dev/null 2>&1
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
defaults write CreateDesktop false
osascript -e 'tell application "Finder" to quit'
open -a Finder
mayoff / main.m
Created May 31, 2017
adding objc_boxable to CoreGraphics structs
View main.m
@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 {
mayoff / FormatOptions.swift
Last active Feb 10, 2017
Avoiding duplication of property names
View FormatOptions.swift
// For
protocol Withable {
extension Withable {
func with(_ body: (inout Self) -> ()) -> Self {
var copy = self
View NSDateFormatter cheat sheet
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
You can’t perform that action at this time.