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 / 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)
mayoff / NSBezierPath-CGPath.swift
Last active Mar 19, 2017 — forked from juliensagot/NSBezierPath+cgPath.swift
Convert NSBezierPath to CGPath (Swift 3.0 / Xcode 8b4 syntax)
View NSBezierPath-CGPath.swift
import AppKit
public extension NSBezierPath {
public var CGPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {
mayoff /
Last active Aug 13, 2016 — forked from orta/
Disclosable Sections in a GH issue
Summary text. Hello World, how is it going?
Another thing. More revealed content.
You can’t perform that action at this time.