Skip to content

Instantly share code, notes, and snippets.

View shaps80's full-sized avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
@shaps80
shaps80 / SPXGeometry.m
Created September 25, 2013 10:31
CGRectDivide with Padding
void CGRectDivideWithPadding(CGRect rect, CGRect *slide, CGRect *remainder, CGFloat amount, CGFloat padding, CGRectEdge edge)
{
CGRect rect1, rect2;
CGRectDivide(rect, &rect1, &rect2, amount, edge);
if (edge == CGRectMaxXEdge || edge == CGRectMaxYEdge)
{
CGRect tmp = rect1;
rect1 = rect2;
rect2 = tmp;
@shaps80
shaps80 / NSAttributedString+SPXAdditions.h
Created September 25, 2013 10:46
NSAttributedString Category to add more flexible customisation.
/*
Copyright (c) 2013 Snippex. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / NSOperation+SPXAdditions.m
Created September 25, 2013 10:50
LIFO NSOperationQueue
/*
Copyright (c) 2013 Snippex. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / Logging.h
Last active January 3, 2016 21:39
Provides better logging with pretty formatting custom timestamp formatting. Fully customisable, and easy drop in replacement to start tidying up existing logs. No additional or frameworks required! Simply replace all NSLog occurrences with SPXLog and watch the logs get prettier! ;)
#import <Foundation/Foundation.h>
#ifdef __SPXLOGGING
#define __SPXLOGGING
/**
* Custom C function for getting the current date/time.
* This function provides custom formatting and is much faster than using
* NSDate and NSDateFormatter, which a lot of log messages are sent.
* Also this way there's little additional memory overhead during logging.
@shaps80
shaps80 / InitWithException.m
Created January 22, 2014 16:47
ProTip: Better way to raise an exception when -init is called on a class that implements a designated initialiser. Turn on -Wstrict-selector-match to get compiler warnings when this selector doesn't exist. Some IDEs (like AppCode) will even refactor this for you should you change the selector ;) The best thing about this is if its inside a stati…
- (instancetype)init
{
SEL selector = @selector(initWithName:);
[NSException raise:NSGenericException format:@"Please use %@", NSStringFromSelector(selector)];
return nil;
}
- (instancetype)initWithName:(NSString *)name
{
self = [super init];
import Foundation
/**
* Simple GCD Wrapper
*/
public struct Queue {
public typealias TimeInterval = NSTimeInterval
public static let Main = Queue(queue: dispatch_get_main_queue());
func enumIterator<T: Hashable>(_: T.Type) -> AnyGenerator<T> {
var cast: (Int -> T)!
switch sizeof(T) {
case 0: return anyGenerator(GeneratorOfOne(unsafeBitCast((), T.self)))
case 1: cast = { unsafeBitCast(UInt8(truncatingBitPattern: $0), T.self) }
case 2: cast = { unsafeBitCast(UInt16(truncatingBitPattern: $0), T.self) }
case 4: cast = { unsafeBitCast(UInt32(truncatingBitPattern: $0), T.self) }
case 8: cast = { unsafeBitCast(UInt64($0), T.self) }
default: fatalError("cannot be here")
}
import UIKit
/// Protocol to be extended with implementations
protocol UIViewLoading {}
/// Extend UIView to declare that it includes nib loading functionality
extension UIView : UIViewLoading {}
/// Protocol implementation
extension UIViewLoading where Self : UIView {
/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
Provides a generic implementation of testing a value for value semantics.
*/
import XCTest
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.698053 0.73105 0.720167 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>OperatorMono-Book - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.847059 0.847059 0.376471 1</string>