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 / 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
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)
print(documentFolderUrl)
class ShapeView: UIView {
override class var layerClass: AnyClass { return CAShapeLayer.self }
@mayoff
mayoff / step1.sh
Created Jun 20, 2017
Services menu item to toggle Finder's desktop icons
View step1.sh
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 Jun 20, 2017 — forked from chockenberry/finder_icons.sh
A simple shell script to turn the Finders desktop icons on and off
View finder_icons.sh
#!/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
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
mayoff / FormatOptions.swift
Last active Feb 10, 2017
Avoiding duplication of property names
View FormatOptions.swift
// For https://twitter.com/nicklockwood/status/819938181483233285
protocol Withable {
init()
}
extension Withable {
func with(_ body: (inout Self) -> ()) -> Self {
var copy = self
body(&copy)
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
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
mayoff / Issue.md
Last active Aug 13, 2016 — forked from orta/Issue.md
Disclosable Sections in a GH issue
View Issue.md
Summary text. Hello World, how is it going?
Another thing. More revealed content.
You can’t perform that action at this time.