Skip to content

Instantly share code, notes, and snippets.

@samdods
samdods / lldbinit
Created January 30, 2014 15:07
init file for LLDB, save this file in your home directory as .lldbinit, i.e. ~/.lldbinit
# rd: print recursive description of entire app window, or of a specified view
#
# usage: rd [view]
#
# if no view is specified, prints recursive description of app's keyWindow
#
command regex rd 's/^[[:space:]]*$/po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]/' 's/^(.+)$/po [%1 recursiveDescription]/'
# slow-on: turn slow animations on, for testing on device only, and optionally set the speed
#
@samdods
samdods / gist:8979831
Last active August 29, 2015 13:56
Expanded use of Foundation's assertions (modified from https://gist.github.com/krzysztofzablocki/5921645)
typedef NS_ENUM(NSInteger, kErrorCode) {
kErrorCodeInternal = 431432,
};
extern NSError *NSErrorMake(NSString *message, NSInteger code, NSDictionary *aUserInfo, NSString *methodOrFunction);
#define NSObjcAssert NSAssert
#define InvalidConditionString(condition) (@"Invalid condition not satisfying: " #condition)
#define GenericAssertCondition(ctype, condition) NS ## ctype ## Assert((condition), InvalidConditionString((condition)))
#define GenericErrorMake(condition, func) NSErrorMake(InvalidConditionString((condition)), kErrorCodeInternal, nil, func)
@samdods
samdods / gist:220791a7e87895da9fec
Created May 22, 2014 12:07
Use GCD dispatch_once function to execute some code only once per instance.
/*
* This may be obvious to some, but the most common use of dispatch_once is for the initialisation of
* a class singleton, so some people may not know how to do it per instance.
*
*/
@implementation MyViewController {
dispatch_once_t _oncePerInstance;
}
@samdods
samdods / UIView+NibLoading.swift
Last active July 31, 2018 21:07
This is the best way I've found to instantiate a view from a nib in Swift.
//
// UIView+NibLoading.swift
// Sam Dods on 29/10/2015.
//
import UIKit
/// Protocol to be extended with implementations
protocol UIViewLoading {}
@samdods
samdods / UIViewController+StoryboardLoading.swift
Created August 23, 2016 14:50
This is the best way to instantiate a view controller from a storyboard in Swift
//
// UIViewController+StoryboardLoading.swift
// Sam Dods on 23/08/2016.
//
import UIKit
/// Protocol to be extended with implementations
protocol UIViewControllerLoading {}
#!/bin/sh
SSHDIR=~/.ssh
BKPDIR=$SSHDIR/bkp`date "+%Y%m%d%H%M%S"`
mkdir $BKPDIR
cp $SSHDIR/id_rsa $BKPDIR
cp $SSHDIR/id_rsa.pub $BKPDIR
func application(_: UIApplication, didFinishLaunchingWithOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
Analytics.Config.analyticsKey = Config.analyticsKey
Analytics.Config.appVersion = Config.appVersion
Home.Config.baseURL = Config.baseURL
Home.Config.apiKey = Config.apiKey
Home.Config.adUnitPrefix = Config.adUnitPrefix
Search.Config.baseURL = Config.baseURL
Search.Config.searchURL = Config.searchURL
//
// Config.swift
// Analytics
//
final class ConfigType {
static fileprivate var shared: ConfigType?
let analyticsKey: String
let appVersion: String
fileprivate init(_ config: AnalyticsConfig.Type) {
self.analyticsKey = config.analyticsKey
self.appVersion = config.appVersion
}
public protocol AnalyticsConfig {
static var analyticsKey: String { get }
static var appVersion: String { get }
}