Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am ishaq on github.
  • I am ishaq (https://keybase.io/ishaq) on keybase.
  • I have a public key whose fingerprint is 8968 BA0F 9581 CF68 707F 13B8 A192 A810 3511 3085

To claim this, I am signing this object:

class func daysToNextBirthday(birthdate: NSDate?) -> Int {
if (birthdate != nil) {
}
else {
return Int.max
}
let calender = NSCalendar.currentCalendar()
let now = NSDate()
let nowComponents = calender.components(NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit | NSCalendarUnit.YearCalendarUnit, fromDate: now)
@ishaq
ishaq / ArchiveHousekeeper.sh
Created June 10, 2014 09:30
This script stops the build if git repository has uncommitted changes, useful when archiving because it makes sure releases (Archives) are created from a clean tree. Put this script in a target (say ArchiveHousekeeper) and update target scheme's Build section to add ArchiveHousekeeper as dependency for Archive operation.
#!/bin/sh
if [ -z "$(git status --porcelain)" ]; then
echo "Working directory clean, proceding to Archive"
exit 0
else
echo "error: Working directory dirty, stopping build"
exit 1
fi
@ishaq
ishaq / SortedCountryCodes.m
Last active August 29, 2015 14:01
Get a list of all country codes sorted by their localised names
+ (NSArray *)getSortedCountryCodes {
NSLocale *locale = [NSLocale currentLocale];
NSArray *countryArray = [NSLocale ISOCountryCodes];
NSMutableDictionary *countriesDictionary = [[NSMutableDictionary alloc] initWithCapacity:countryArray.count];
for (NSString *countryCode in countryArray) {
NSString *localizedCountryName = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];
countriesDictionary[countryCode] = localizedCountryName;
}
@ishaq
ishaq / NSDate+dateByRemovingFractionalSeconds.h
Created May 7, 2014 15:46
category to remove fractional seconds from an NSDate
#import <Foundation/Foundation.h>
@interface NSDate (dateByRemovingFractionalSeconds)
+ (NSDate *)dateWithoutFractionalSeconds;
- (NSDate *)dateByRemovingFractionalSeconds;
@end
@ishaq
ishaq / AppDelegate.m
Last active September 6, 2018 10:04
iOS: load main interface programmatically
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = nil;
BOOL showLogin = NO;
if(showLogin == NO)
{
// mainStoryboard method looks like:
// return [UIStoryboard storyboardWithName:@"Main" bundle:nil];
@ishaq
ishaq / NSDate+FormattedString.h
Last active December 28, 2015 20:49
NSString from NSDate and vice versa
#import <Foundation/Foundation.h>
@interface NSDate (FormattedString)
- (NSString *)mi_dateStringWithStyle:(NSDateFormatterStyle)style
timeStyle:(NSDateFormatterStyle)timeStyle;
- (NSString *)mi_dateStringWithFormat:(NSString *)format;
- (NSString *)mi_isoDateString;
- (NSString *)mi_ecma262DateString;
@end
@ishaq
ishaq / NSString+Kahaf.h
Last active December 28, 2015 20:49
useful NSString functions
#import <Foundation/Foundation.h>
/**
* this category contains functions that either work on `NSString` or return `NSString`. The category is called <b>Kahaf</b>
* because these functions don't exactly fit into any other single category.
*/
@interface NSString (Kahaf)
/**
* Creates and returns a new UUID with RFC 4122 version 4 random bytes.
@ishaq
ishaq / KUtils.h
Last active October 11, 2019 22:15 — forked from jpwatts/xcode-git-version.sh
This Xcode build phase script automatically sets the version and short version string of an application bundle based on information from the containing Git repository. To Use it, you 1) add the contents of `xcode-git-version.sh` to a "Run Script" build phase for your application target. 2) add a new value to your info plist called `FullVersion` …
#import <Foundation/Foundation.h>
@interface KUtils : NSObject
+ (NSString *)getVersionInfo;
@end