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 / 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 / ConversationView.swift
Created February 14, 2020 20:05
playground demonstrating SwiftUI PreferenceKey, EnvironmentKey, and GeometryReader
import SwiftUI
import PlaygroundSupport
struct EqualWidthKey: PreferenceKey {
static var defaultValue: CGFloat? { nil }
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
switch (value, nextValue()) {
case (_, nil): break
case (nil, let next): value = next
@mayoff
mayoff / SteppingSubscriber.swift
Created December 18, 2019 06:50
Custom Combine operator for stepping a publisher's signals through function
// See https://stackoverflow.com/q/59367202/77567
import Combine
import Foundation
extension Publisher {
func step(with stepper: @escaping (SteppingSubscriber<Output, Failure>.Event) -> ()) -> AnyCancellable {
let subscriber = SteppingSubscriber<Output, Failure>(stepper: stepper)
self.subscribe(subscriber)
return .init(subscriber)
@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
@mayoff
mayoff / unowned-safety-dance.swift
Created February 23, 2019 03:00
test Swift unowned safety
class MyObject { }
var o = MyObject()
print("strong o = \(o)")
unowned let u = o
print("unowned u = \(u)")
o = MyObject()
@mayoff
mayoff / main.m
Created February 11, 2019 19:32
Set pHYs chunk (DPI) of PNG
@import AppKit;
@import ImageIO;
@import CoreServices;
#define fromCF (__bridge id)
#define toCF (__bridge CFTypeRef)
int main(int argc, const char * argv[]) {
@autoreleasepool {
CGRect rect = CGRectMake(0, 0, 100, 100);
@mayoff
mayoff / wedges-with-gaps.swift
Created December 27, 2018 06:30
Simon game wedges in iOS
import UIKit
import PlaygroundSupport
typealias Radians = CGFloat
extension UIBezierPath {
static func simonWedge(innerRadius: CGFloat, outerRadius: CGFloat, centerAngle: Radians, gap: CGFloat) -> UIBezierPath {
let innerAngle: Radians = CGFloat.pi / 4 - gap / (2 * innerRadius)
let outerAngle: Radians = CGFloat.pi / 4 - gap / (2 * outerRadius)
@mayoff
mayoff / Decimal.py
Created October 10, 2018 22:13
Decimal / NSDecimal support for lldb
# Decimal / NSDecimal support for lldb
#
# Put this file somewhere, e.g. ~/.../lldb/Decimal.py
# Then add this line to ~/.lldbinit:
# command script import ~/.../lldb/Decimal.py
import lldb
def stringForDecimal(sbValue, internal_dict):
from decimal import Decimal, getcontext
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina3_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>