Skip to content

Instantly share code, notes, and snippets.

@mutekinootoko
mutekinootoko / dontfightwaistmeasures
Last active August 29, 2015 14:01
Don't fight your waist measures.
$(age).change(function (v) {
if( age >= 30 ) {
$(waistMeasure).attr('value', v);
}
});
@mutekinootoko
mutekinootoko / gist:791d223cfb978fbb41fa
Created January 16, 2015 07:54
find iphone screen size
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
UIGraphicsBeginImageContext(self.mjviewer.bounds.size);
[self.mjviewer.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* currentMJpegImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(currentMJpegImage, nil, nil, nil);
@mutekinootoko
mutekinootoko / gist:0ee6dcc53fba32beb8f7
Last active August 29, 2015 14:13
uitableview delegate and datasource
#pragma mark uitableview datasource and delegate
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// optional
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
@mutekinootoko
mutekinootoko / gist:1ad25e527f626f740029
Created January 23, 2015 06:43
AFNetworking with XML format response.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestSerializer * requestSerializer = [AFHTTPRequestSerializer serializer];
AFHTTPResponseSerializer * responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *ua = @"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25";
[requestSerializer setValue:ua forHTTPHeaderField:@"User-Agent"];
// [requestSerializer setValue:@"application/xml" forHTTPHeaderField:@"Content-type"];
responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/xml", nil];
manager.responseSerializer = responseSerializer;
manager.requestSerializer = requestSerializer;
[self.thumbnailView registerNib:[UINib nibWithNibName:@"___" bundle:nil] forCellWithReuseIdentifier:@"___"];
@mutekinootoko
mutekinootoko / gist:5fc0fc0be580ddf1d4dd
Created January 29, 2015 17:39
dispatch after sec
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2);
});
@mutekinootoko
mutekinootoko / gist:0097beaef7c6a92ca9cd
Last active August 29, 2015 14:15
PHCollectionList of each year and moments under them.
PHFetchResult* yearList = [PHCollectionList fetchMomentListsWithSubtype:PHCollectionListSubtypeMomentListYear options:nil];
for(id foobar in yearList) { // each year
if([foobar isKindOfClass:[PHCollectionList class]]) {
PHCollectionList* yearCollectionList = (PHCollectionList*) foobar;
NSDateComponents* dateComps = [[NSCalendar currentCalendar] components:NSCalendarUnitYear fromDate:yearCollectionList.startDate];
[years addObject: [NSNumber numberWithInt: (int) dateComps.year]];
NSLog(@"year %d", dateComps.year);
PHFetchResult* momentCollectionList = [PHCollectionList fetchCollectionsInCollectionList:yearCollectionList options:nil];
@class MyClass ;
@protocol MyClassDelegate
@optional
- (void) myClassStatusChange:(MyClassStatusChangeRequest*) changeRequest;
@end
@mutekinootoko
mutekinootoko / gist:3ce1ed506a288c5d7ba9
Created March 15, 2015 05:01
ios8+ all photo count of each year
- (NSMutableArray*) yearCollections {
if(_yearCollections == nil) {
_yearCollections = [NSMutableArray new];
// build year collection here
NSLog(@"building camera roll year collection tree.");
// 先設定好 取得phasset 參數
PHImageManager* pim = (PHImageManager*) [PHImageManager defaultManager];
PHImageRequestOptions* piro = [[PHImageRequestOptions alloc] init];