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 / Main.storyboard
Created September 10, 2014 15:04
Storyboard with autolayout constraints for aspect-fit of a subview in a container view, for http://stackoverflow.com/a/25768875/77567
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
@mayoff
mayoff / README.md
Last active August 23, 2021 14:41
defining an extra-large widget only if on iOS 15

You probably have a WidgetBundle type in your widget extension like this:

@main
struct MyWidgets: WidgetBundle {
    var body: some Widget {
        SmallWidget()
        MediumWidget()
        LargeWidget()
    }
@mayoff
mayoff / RefreshableTests.swift
Created July 19, 2021 18:35
for pointfree episode 153
@testable import SwiftUICaseStudies
import XCTest
class RefreshableTests: XCTestCase {
func testVanilla() async {
var k: CheckedContinuation<Void, Never>? = nil
let viewModel = PullToRefreshViewModel(
fetch: {
@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 / UIImage+Rob_PDFPage.h
Created August 12, 2013 22:58
A UIImage category that renders one page of a PDF.
#import <UIKit/UIKit.h>
@interface UIImage (Rob_PDFPage)
/**
I return an image in which I have drawn page `pageNumber` of the PDF found at `url`. Pages are numbered starting at 1. If I can't draw the page, I return `nil`.
*/
+ (UIImage *)Rob_imageWithPDFURL:(NSURL *)url pageNumber:(size_t)pageNumber;
@end
@mayoff
mayoff / ViewController.m
Created December 20, 2012 04:49
Animate a CALayer's position starting from its current (possibly mid-animation) position.
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController {
CALayer *_layer;
}
@mayoff
mayoff / ArrowLayer.h
Created November 27, 2012 06:44
A CALayer subclass that draws a very simple arrow
#import <QuartzCore/QuartzCore.h>
@interface ArrowLayer : CALayer
@property (nonatomic) CGFloat thickness;
@property (nonatomic) CGFloat startRadians;
@property (nonatomic) CGFloat lengthRadians;
@property (nonatomic) CGFloat headLengthRadians;
@property (nonatomic, strong) UIColor *fillColor;
@mayoff
mayoff / ContentView.swift
Created February 26, 2020 16:36
SwiftUI gradients spanning multiple views
import SwiftUI
struct BubbleFramesValue {
var framesForKey: [AnyHashable: [CGRect]] = [:]
var gradientFrame: CGRect? = nil
}
struct BubbleFramesKey { }
extension BubbleFramesKey: PreferenceKey {
@mayoff
mayoff / gist:bcb5fc06b79f8b0a0270ebf48e38d4a1
Last active February 24, 2020 20:31
Xcode secret settings
# Show the Xcode version number over the Dock icon.
defaults write com.apple.dt.Xcode DVTEnableDockIconVersionNumber -bool YES
# Or set ShowDVTDebugMenu.
# Show Index in the Report navigator.
# https://pspdfkit.com/blog/2019/how-xcode-indexing-works-and-how-to-solve-problems/
defaults write com.apple.dt.Xcode IDEIndexShowLog -bool YES
@mayoff
mayoff / decode-dyn-uti.swift
Created March 14, 2019 22:13
Swift command-line script to decode dynamic UTIs
#!/usr/bin/xcrun swift
// http://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
extension String {
static let bitsForCodeUnit: [Character: [UInt8]] = {
var dict = [Character: [UInt8]]()
for (i, ch) in "abcdefghkmnpqrstuvwxyz0123456789".enumerated() {
let bits = Array((0 ..< 5).map({ UInt8((i >> $0) & 1) }).reversed())
dict[ch] = bits