Skip to content

Instantly share code, notes, and snippets.

View kharmabum's full-sized avatar
💭
🧀

Juan-Carlos Foust kharmabum

💭
🧀
View GitHub Profile
#########################
# .gitignore file for Xcode5
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
# and https://gist.github.com/adamgit/3786883
@kharmabum
kharmabum / sim-db-replace.sh
Created March 13, 2014 02:44
replace db in sim
ps auxw | grep Coff
cp ~/Downloads/sqlite.db ~/Library/Application\ Support/iPhone\ Simulator/7.1/Applications/9CD889F1-2335-481F-8C34-6E4B7E33F571/Documents/sqlite.db
@kharmabum
kharmabum / feedback.m
Created March 12, 2014 17:41
Get feedback from user w/ bundle version id
} else if ([choice isEqualToString:@"Feedback"]) {
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"[Hopp2IT] Feedback"];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
NSString *device = ([HPManager isiPhone5]) ? @"iPhone5" : @"<=iPhone4";
NSString *messageBody = [NSString stringWithFormat:@"\n\n~~~~~~~~~~~~~~\nPlatform: iOS\nDevice: %@\nVersion: %@\n",device,version];
[mailer setMessageBody:messageBody isHTML:NO];
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
@kharmabum
kharmabum / nsstring-unicode-comparison.m
Created March 9, 2014 22:37
String objects are not normalized unless you perform that step manually. This means that comparing strings that contain combining character sequences can potentially lead to wrong results. Both isEqual: and isEqualToString: compare strings byte for byte. If you want precomposed and decomposed variants to match, you must normalize the strings first.
// http://www.objc.io/issue-9/unicode.html
NSString *s = @"\u00E9"; // é
NSString *t = @"e\u0301"; // e + ´
BOOL isEqual = [s isEqualToString:t];
NSLog(@"%@ is %@ to %@", s, isEqual ? @"equal" : @"not equal", t);
// => é is not equal to é
// Normalizing to form C
NSString *sNorm = [s precomposedStringWithCanonicalMapping];
NSString *tNorm = [t precomposedStringWithCanonicalMapping];
NSUInteger realLength = [s lengthOfBytesUsingEncoding:NSUTF32StringEncoding] / 4;
NSLog(@"The real length of %@ is %lu", s, realLength);
// => The real length of 🌍 is 1
@kharmabum
kharmabum / nsstring-unicode-loop.m
Created March 9, 2014 22:32
Looping through NSString Unicode characters - http://www.objc.io/issue-9/unicode.html
NSString *s = @"The weather on \U0001F30D is \U0001F31E today.";
// The weather on 🌍 is 🌞 today.
NSRange fullRange = NSMakeRange(0, [s length]);
[s enumerateSubstringsInRange:fullRange
options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString *substring, NSRange substringRange,
NSRange enclosingRange, BOOL *stop)
{
NSLog(@"%@ %@", substring, NSStringFromRange(substringRange));
}];
@kharmabum
kharmabum / UITextField-CharacterCount.m
Created February 14, 2014 19:19
Delegate methods for tracking character count
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
int remainder = MAX_CHARACTER_COUNT - textField.text.length;
self.counterLabel.text = [NSString stringWithFormat:@"%d", remainder];
if (textField == self.activityNameTextField) {
self.counterLabel.yOrigin = self.activityNameContainerView.yOrigin;
[self closePlaceTableView];
} else {
@kharmabum
kharmabum / HPGroupSelectViewController.h
Created February 14, 2014 19:18
For selecting mutually exclusive categories in a dependent hierarchy (i.e. tracing a taxonomy). See -> http://www.cocoanetics.com/2011/03/expandingcollapsing-tableview-sections/
#import <UIKit/UIKit.h>
@interface HPGroupSelectViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@end
@kharmabum
kharmabum / locationServiceEnabled-check.m
Created February 13, 2014 02:28
Check whether locationServices are enabled.
if ((![CLLocationManager locationServicesEnabled])
|| ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted)
|| ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Location services must be enabled in Settings.", nil) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];