Skip to content

Instantly share code, notes, and snippets.

View jordanbrown's full-sized avatar

Jordan Brown jordanbrown

View GitHub Profile
@IanColdwater
IanColdwater / twittermute.txt
Last active April 22, 2024 17:26
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@jstart
jstart / touchID
Last active July 28, 2017 17:58
Touch ID Example
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Authenticate using your finger";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"User is authenticated successfully");
} else {
@nicklockwood
nicklockwood / Deprecated.md
Last active March 28, 2022 08:16
Writing Objective-C framework code that works on multiple OS versions AND can be compiled using multiple SDK versions without warnings can be a PITA. Here's my approach:

Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:

  1. The new API will crash if we call it on iOS 7
  2. The new API won't compile if we build it using the iOS 7 SDK
  3. The old API will raise a deprecation warning if built with a deployment target of iOS 8 and up

These three problems require three different technical solutions:

  1. We can avoid calling the new API on an old OS version by using runtime detection (e.g. respondsToSelector:)
  2. We can avoid compiling new APIs on old SDKs using the __IPHONE_OS_VERSION_MAX_ALLOWED macro
@kongtomorrow
kongtomorrow / gist:e95bea13162ca0e29d4b
Last active August 31, 2022 16:20
Y combinator in Swift!
/* The Y combinator in Swift!
For a discussion of what the heck this is all about, see http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html
The nifty thing is that it allows us to implement recursion without the ability for a function to refer to itself from within its own definition.
Note how we manage a recursive definition of factorial without any function referring to its own name.
Thanks to @eridius for help with the SelfToUnderlying<T> type.
*/
//
// MKMapView+ZoomLevel.h
//
// Created by Daniel.Burke on 7/3/14 via Nikita Galayko @ StackOverflow
// Copyright (c) 2014 Forrent.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20
@ghvillasboas
ghvillasboas / gist:4976eb8a4cf84c474464
Created June 23, 2014 20:49
WWDC 2014 - Talks by Evangelists
WWDC 2014 - Talks by Evangelists
============================================================
============================================================
Jake Behrens - App Frameworks Evangelists
behrens@apple.com/Twitter: @Behrens
============================================================
- A Look Inside Presentation Controllers
- Accessibility on iOS
- Accessibility on OS X
@steipete
steipete / NSFormattingContextPlayground.m
Last active December 21, 2017 17:52
NSFormattingContextDynamic got my attention, so I've digged into how this actually works. (tl;dr: _NSStringProxyForContext!)
// NSFormattingContext is new in iOS 8. For NSFormattingContextDynamic it promises is following:
// The capitalization context is determined dynamically from the set {NSFormattingContextStandalone, NSFormattingContextBeginningOfSentence, NSFormattingContextMiddleOfSentence}. For example, if a date is placed at the beginning of a sentence, NSFormattingContextBeginningOfSentence is used to format the string automatically. When this context is used, the formatter will return a string proxy that works like a normal string in most cases. After returning from the formatter, the string in the string proxy is formatted by using NSFormattingContextUnknown. When the string proxy is used in stringWithFormat:, we can determine where the %@ is and then set the context accordingly. With the new context, the string in the string proxy will be formatted again and be put into the final string returned from stringWithFormat:.
// Here's a simple example:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFor
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@steipete
steipete / gist:5333a5903e3a50ad14b3
Last active March 21, 2017 11:33
Load Reveal from lldb. Put into ~/.lldbinit, pause app, type reveal. Will only work in Simulator.
command alias reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);
command alias reveal_load_dev expr (void*)dlopen((const char *)[(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);
command alias reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
command alias reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
command alias reveal expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2), (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
#import <objc/objc-runtime.h>
#import "UIView+SGAutoLayoutExtensions.h"
@implementation UIView (SGAutoLayoutExtensions)
#ifdef DEBUG
- (NSString *)nsli_description
{
return [self restorationIdentifier] ?: [NSString stringWithFormat:@"%@:%p", [self class], self];