Skip to content

Instantly share code, notes, and snippets.

View hebertialmeida's full-sized avatar
✈️

Heberti Almeida hebertialmeida

✈️
View GitHub Profile
@hebertialmeida
hebertialmeida / gist:6ba1331e3bc9ecb0cb89
Last active August 29, 2015 14:06
Remove repeated values from a INT array, returning the resultant array in the same order as original. Swift implementation.
import UIKit
var numbers = [7, 7, 7, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8]
var filter = [Int]()
for number in numbers {
if !contains(filter, number) {
filter.append(number)
}
}
@hebertialmeida
hebertialmeida / gist:9680780
Created March 21, 2014 06:34
Open native Apps or open on Safari if don't have the App
- (void)openThisURL:(NSString *)launchUrl withFallback:(NSString *)fallback
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:launchUrl]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:launchUrl]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fallback]];
}
}
@hebertialmeida
hebertialmeida / gist:8769297
Created February 2, 2014 14:35
Finding the most common character in a string
- (NSString *)mostCommonCharacter:(NSString *)string
{
__block NSMutableArray *charIndex = [[NSMutableArray alloc] init];
// Enumerate
[string enumerateSubstringsInRange:NSMakeRange(0, string.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop)
{
[charIndex addObject:substring];
}];