Skip to content

Instantly share code, notes, and snippets.

View alex-zige's full-sized avatar
🤞
Focusing

Alex Z. Li alex-zige

🤞
Focusing
View GitHub Profile
@alex-zige
alex-zige / gist:6f77d3a4e1403339c587
Created September 9, 2014 02:20
DB reset (drop & create & migrate & seed)
# check if stdout is a terminal...
if [ -t 1 ]; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@alex-zige
alex-zige / gist:523f8f0a8534eebff731
Last active May 23, 2023 09:45
Custom Search Bar in Nav
@alex-zige
alex-zige / gist:ddbd70682493c6e1bf98
Created June 27, 2014 03:49
Add calendar options
//add calendar option
- (void)_addToCalendar{
NSString *meetingTitle= [NSString stringWithFormat:@"Meeting with %@", self.meeting.participant.name.capitalizedString];
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) {return;}
BOOL matched = [self _checkForExistedCalendarInStore:store];
dispatch_async(dispatch_get_main_queue(), ^{
if (matched){
[[[UIAlertView alloc] initWithTitle:@"Warning" message:@"This meeting has already been added to your calendar." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
@alex-zige
alex-zige / gist:e3734363e97dcf5be6f5
Created June 23, 2014 04:36
UIDatePicker config with interval
-(void)configDatePicker:(UIDatePicker *)datePicker{
datePicker.backgroundColor = [UIColor whiteColor];
// Round Default date with 15 mins interval
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit fromDate:[NSDate date]];
NSInteger minutes = [dateComponents minute];
NSInteger minutesRounded =roundf((float)minutes / (float)30 + 0.5) * 30;
NSDate *roundedDate = [[NSDate alloc] initWithTimeInterval:60.0 * (minutesRounded - minutes) sinceDate:[NSDate date]];
[datePicker setMinimumDate:roundedDate];
@alex-zige
alex-zige / gist:82037e8588ec813e944f
Last active August 29, 2015 14:02
Mac OSX 10.10 RVM & Ruby

Fix Brew

Brew still using 1.8 ruby verison. but OSX 10.10 ship with 2.0.0 so symoblinking for now.

$ sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
$ sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Brew update

@alex-zige
alex-zige / gist:9460097
Created March 10, 2014 05:51
zshrc.symlink
# shortcut to this dotfiles path is $ZSH
export ZSH=$HOME/.dotfiles
# your project folder that we can `c [tab]` to
export PROJECTS=~/Code
# use .localrc for SUPER SECRET CRAP that you don't
# want in your public, versioned repo.
if [[ -a ~/.localrc ]]
then
@alex-zige
alex-zige / gist:9103810
Created February 19, 2014 23:29
Curl post json file to api url endpoints for API testing
curl -H "Content-Type: application/json" --data @your-json-file-name.json http://localhost:XXXX/api-end-point
@alex-zige
alex-zige / gist:9044285
Created February 17, 2014 03:35
JSON mapper examples
//with custom Class
NSString *jsonFileName = @"resources";
NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"];
NSData *JSONData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:nil];
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil];
ResourceList *resourceList = [ResourceList createObjectsUsingJSONDictwithCustomClass:jsonObject];
NSLog(@"resources %@", resourceList);
#with undefined Meetings returns NSArray
NSString *jsonFileName1 = @"meetings";