Skip to content

Instantly share code, notes, and snippets.

View shannoga's full-sized avatar

Shani Hajbi shannoga

View GitHub Profile
@shannoga
shannoga / Fetch core data entity
Created May 30, 2011 07:29
Core data fetch function
+(NSArray*)fetchForCardsEntity:(NSString*)entityName withPredicate:(NSString*)predicateFormat withSortDiscriptor:(NSString*)sortdDscriptorName{
NSManagedObjectContext *moc=[[self appDelegate] managedObjectContext];
NSEntityDescription *entityDescription;
NSPredicate *predicate;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
entityDescription = [NSEntityDescription entityForName:entityName inManagedObjectContext:moc];
[request setEntity:entityDescription];
predicate = [NSPredicate predicateWithFormat: predicateFormat];
@shannoga
shannoga / Is that an ipad
Created May 30, 2011 11:58
Is that an ipad
+ (BOOL)isDeviceAniPad {
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
@shannoga
shannoga / simplepastiefile.m
Created May 30, 2011 12:36
Detect user languish
+(NSString*)currentLang{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
return [languages objectAtIndex:0];
}
@shannoga
shannoga / simplepastiefile.m
Created May 30, 2011 12:41
Get only numbers from NSString
+(NSString*)getOnlyNumbersFromString:(NSString*)stringToStrip{
NSMutableString *strippedString = [NSMutableString
stringWithCapacity:stringToStrip.length];
NSScanner *scanner = [NSScanner scannerWithString:stringToStrip];
NSCharacterSet *numbers = [NSCharacterSet
characterSetWithCharactersInString:@"0123456789"];
while ([scanner isAtEnd] == NO) {
NSString *buffer;
@shannoga
shannoga / gist:1008678
Created June 5, 2011 05:14
Get fonts family and font names list on iOS
// List all fonts on iPhone
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
CGRectGetWidth(startSegment.frame)