Skip to content

Instantly share code, notes, and snippets.

@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@steipete
steipete / PSPDFViewController.h
Last active June 6, 2017 03:56
This method will help to prevent a lot of emails about "weird bugs".
// Defines a yet undocumented method to add a warning if super isn't called.
#ifndef NS_REQUIRES_SUPER
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
#else
#define NS_REQUIRES_SUPER
#endif
#endif
@interface UIViewController (SubclassingWarnings)
@interface NSIndexSet (Operations)
// http://en.wikipedia.org/wiki/Union_(set_theory)
- (NSIndexSet *)unionWith:(NSIndexSet *)other;
// http://en.wikipedia.org/wiki/Intersection_(set_theory)
- (NSIndexSet *)intersectionWith:(NSIndexSet *)other;
// http://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement
- (NSIndexSet *)relativeComplementIn:(NSIndexSet *)universe;
@mikeash
mikeash / gist:5172803
Created March 15, 2013 20:18
Main thread watchdog
- (void)watchdog {
NSTimeInterval pingInterval = 1.0/60.0;
NSTimeInterval watchdogInterval = 1.0/30.0;
__block NSTimeInterval lastPing = 0;
NSProcessInfo *pi = [NSProcessInfo processInfo];
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, pingInterval * NSEC_PER_SEC, 0);
@mattt
mattt / uiappearance-selector.md
Last active March 19, 2024 12:52
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@markschabacker
markschabacker / post_run_script.rb
Created December 7, 2012 21:32
Xcode 4.5 Command Line Unit Tests
# Run iOS Unit Tests from the command line with Xcode 4.5 and iOS 6
# Adapted from Scott Thompson at http://stackoverflow.com/a/10823483/1359212
#
# Steps:
# 1. Create a new Xcode Scheme for the Tests target
# 2. Edit the Tests Scheme so that the "Run" checkbox is checked for the Tests target
# 3. Use this script as the Test Target's "Run Script" entry on the "Build Phases" tab
# 4. Run tests from the command line with:
# xcodebuild -sdk iphonesimulator -scheme 'TestSchemeName' build SL_RUN_UNIT_TESTS=YES
@lsloan
lsloan / Open Selected Finder Folder in iTerm
Last active September 13, 2017 06:10 — forked from al3xandru/gist:1156476
Use the selected folder in Finder to open a shell in iTerm and go to its directory.
Gist title: "Open Selected Finder Folder in iTerm"
Summary: Use the selected folder in Finder to open a shell in iTerm and go to its directory.
See also: https://gitlab.com/gnachman/iterm2/issues/3552
@gruber
gruber / Liberal Regex Pattern for All URLs
Last active May 6, 2024 21:38
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))