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 / FormatOptions.swift
Last active February 10, 2017 05:16
Avoiding duplication of property names
// For https://twitter.com/nicklockwood/status/819938181483233285
protocol Withable {
init()
}
extension Withable {
func with(_ body: (inout Self) -> ()) -> Self {
var copy = self
body(&copy)
@mayoff
mayoff / NSDateFormatter cheat sheet
Created December 14, 2016 19:20 — forked from romaonthego/NSDateFormatter cheat sheet
Date Formats for NSDateFormatter
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
mayoff / NSBezierPath-CGPath.swift
Last active September 20, 2022 11:00 — forked from juliensagot/NSBezierPath+cgPath.swift
Convert NSBezierPath to CGPath (Swift 3.0 / Xcode 8b4 syntax)
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
mayoff / Issue.md
Last active August 13, 2016 16:19 — forked from orta/Issue.md
Disclosable Sections in a GH issue
Summary text. Hello World, how is it going?
Another thing. More revealed content.
@mayoff
mayoff / NSDateComponents+DictionaryLiteral.swift
Created June 3, 2016 16:27
Attempting to make NSDateComponents conform to DictionaryLiteralConvertible
import Cocoa
public extension NSDateComponents {
public convenience init(_ components: DictionaryLiteral<NSCalendarUnit, Int>) {
self.init()
for (key, value) in components {
setValue(value, forComponent: key)
}
}
}
@mayoff
mayoff / Main.storyboard
Created May 14, 2016 21:23
disclosable sections like Xcode inspectors
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<capability name="stacking Non-gravity area distributions on NSStackView" minToolsVersion="7.0" minSystemVersion="10.11"/>
</dependencies>
<scenes>
<!--Application-->
<scene sceneID="JPo-4y-FX3">
@mayoff
mayoff / ConstraintCollection.swift
Last active April 19, 2016 05:49 — forked from jtbandes/ConstraintCollection.swift
Autolayout constraint literals in Swift (updated for Swift 2.2)
#if os(iOS)
import UIKit
#else
import AppKit
#endif
let view = UIView(frame: CGRectMake(0, 0, 400, 300))
view.backgroundColor = UIColor.redColor()
let button = UIButton(type: .Custom)
@mayoff
mayoff / kvoperf.m
Created February 23, 2016 23:13
KVO 100x slowdown in El Capitan
#import <Foundation/Foundation.h>
@interface Subject: NSObject
@property double a;
@property long b;
@property NSObject* c;
@property NSObject* d;
@property NSObject* e;
@property NSObject* f;
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
import UIKit
class FloatingButtonController: UIViewController {
private(set) var button: UIButton!
required init?(coder aDecoder: NSCoder) {
fatalError()
}