Skip to content

Instantly share code, notes, and snippets.

@rnystrom
rnystrom / ViewController.swift
Created May 29, 2018 01:16
Interactive NSAttributedString link highlighting with TextKit
import UIKit
public extension CGSize {
func snapped(scale: CGFloat) -> CGSize {
var size = self
size.width = ceil(size.width * scale) / scale
size.height = ceil(size.height * scale) / scale
return size
}
@rnystrom
rnystrom / example.swift
Created January 18, 2021 00:30
Show the keyboard as a UISearchController in a modal is displayed
class ViewController: UIViewController {
@IBAction func onSearch(_ sender: Any) {
let fakeWindow = UIWindow(windowScene: view.window!.windowScene!)
let fakeTextField = UITextField()
fakeTextField.autocorrectionType = .no
fakeWindow.addSubview(fakeTextField)
fakeWindow.makeKeyAndVisible()
fakeTextField.becomeFirstResponder()
@rnystrom
rnystrom / iOS @3x assets script
Created November 26, 2014 01:52
Save this shell script to generate @2x and 1x PNG assets for your apps. Requires Imagemagick (http://www.imagemagick.org/). These will probably look shitty and blurred.
#!/bin/sh
# Example usage
# cd into directory that has @3x images
# ./whatever-you-name-this.sh
# Remember to chmod +x the script
resize () {
ls *@3x.png | awk '{print("convert "$1" -filter box -resize '$1' "$1)}' | sed 's/@3x/'$2'/2' | /bin/sh
}
@rnystrom
rnystrom / purge.md
Last active August 13, 2020 13:26
Purge inactive testflight users with fastlane

Purging inactive users from TestFlight

Pretty hacky flow, but this will remove anyone that was invited but not accepted their TestFlight invitation.

Start the Ruby REPL

$ irb
Date/Time: 2019-09-06 20:24:09.836 -0400
OS Version: Mac OS X 10.14.6 (18G95)
Report Version: 12
Bridge OS Version: 3.6 (16P6571)
Anonymous UUID: 2F39EFFF-A558-172D-A389-1B5A4D92497B
Sleep/Wake UUID: 2C691F51-7554-49E4-9814-D24C14443882
Time Awake Since Boot: 320000 seconds
Time Since Wake: 1200 seconds
@rnystrom
rnystrom / Cell.swift
Last active June 9, 2019 17:36
Self-sizing UITableViewCell with an h-scrolling UITextView
class Cell: UITableViewCell {
let textView = UITextView()
let scrollView = UIScrollView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.alwaysBounceHorizontal = true
scrollView.scrollsToTop = false
$ bash -l -c "$(curl -sfL https://raw.githubusercontent.com/bitrise-tools/codesigndoc/master/_scripts/install_wrap-xcode.sh)" 18-05-04 12:54:54
=> Creating a temporary directory for codesigndoc ...
=> Downloading version: 2.1.0
=> Downloading codesigndoc from (https://github.com/bitrise-tools/codesigndoc/releases/download/2.1.0/codesigndoc-Darwin-x86_64) to (/var/folders/cp/3k3452xn2w9223mgpchm2059krf8ch/T/codesigndocXXXXXX.REa5smBc/codesigndoc) ...
######################################################################## 100.0%
=> Making it executable ...
=> codesigndoc version: 2.1.0
=> Running codesigndoc scan ...
// ListSwiftAdapterDataSource.swift
public class Value {
public let value: ListSwiftDiffable
public let constructor: () -> ListSectionController
public init<T>(value: T, constructor: @escaping () -> ListSwiftSectionController<T>) {
self.value = value
self.constructor = constructor
}
@rnystrom
rnystrom / RN3DTouchGestureRecognizer.swift
Last active February 3, 2018 22:58
RN3DTouchGestureRecognizer
//
// RN3DTouchGestureRecognizer.swift
//
// Created by Ryan Nystrom on 10/10/15.
// Copyright © 2015 Ryan Nystrom. All rights reserved.
//
import UIKit.UIGestureRecognizerSubclass
class RN3DTouchGestureRecognizer: UIGestureRecognizer {
FAILED=false
if [ -z "${BUDDYBUILD_BUILD_NUMBER}" ]; then
echo "Script is not being run on CI"
exit 0
fi
if [ -z "${GITHUB_CLIENT_ID}" ]; then
echo "${SRCROOT}/Classes/Systems/Secrets.swift:14:1: warning: Missing GitHub Client ID"
FAILED=true