Navigation Menu

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 / SPXEncodingDefines.h
Created March 13, 2014 13:54
NSCoding and NSUserDefaults Defines - Clean macros to simplify your life
/*
Copyright (c) 2014 Shaps Mohsenin. 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,
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)
@shaps80
shaps80 / dev-scripts.sh
Last active December 7, 2021 15:24
Open Xcode and AppCode projects from the command line. I recommend keeping this in a separate file and just importing the code into your bash_profile using: source ~/.dev-scripts.sh
#!/usr/bin/env bash
function openWorkspaceOrProjectWithApp()
{
if [[ -z "$1" || "$#" -ne 2 ]]; then
echo -e "Nothing found\n"
return
fi
IDEFileName=${2##*/}

Keybase proof

I hereby claim:

  • I am shaps80 on github.
  • I am shaps (https://keybase.io/shaps) on keybase.
  • I have a public key whose fingerprint is D1B3 44E7 F8A9 EF64 D1E0 4292 4286 651A F5BD CB47

To claim this, I am signing this object:

@shaps80
shaps80 / UIView+OptionalAnimations.h
Last active August 29, 2015 14:00
Added transitions
@interface UIView (SPXAdditions)
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations;
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration delay:(CGFloat)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion;
+ (void)animate:(BOOL)shouldAnimate duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion;
+ (void)transition:(BOOL)shouldTransition fromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion;
+ (void)transition:(BOOL)shoul
@shaps80
shaps80 / AsyncKiwiTest.m
Created May 22, 2014 18:31
The following is the test I have written but it never asserts from my tests. I think the issue is that the assertion occurs on a different thread that the one that the task is performed on, that perhaps this isn't getting back to the test.
it (@"should eventually throw assert for asynchronous operation", ^{
[[theBlock(^{
[MyClass performLongRunningAsynchronousTasks];
}) shouldEventually] raise];
});
@shaps80
shaps80 / UIApplication+SnippexAdditions.h
Last active August 29, 2015 14:22
Check if running inside an App Extension vs an App
@import Foundation;
@interface UIApplication (SnippexAdditions)
+ (BOOL)isAppExtension;
@end
@shaps80
shaps80 / UIView+NibLoading.swift
Created January 5, 2016 13:40 — forked from samdods/UIView+NibLoading.swift
This is the best way I've found to load 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 {}
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")
}