jtg2078 / TIL

Today I Learned, literally

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TIL

Today I Learned, literally

7-1

iOS stuff

how to solve generated csv file will not display properly in microsoft excel

// thanks to http://stackoverflow.com/a/26034145/1440081
// manually add BOM character in the front of the file
cvsStringFile = [[NSString alloc] initWithFormat:@"\357\273\277%@", cvsStringFile];

NSData *myXLSData = [cvsStringFile dataUsingEncoding:NSUTF8StringEncoding];
[picker addAttachmentData:myXLSData mimeType:@"text/csv;charset=utf-8" fileName:@"Report.csv"];

Mousewheel horizontal scrolling

$(function() {
        $("html, body").mousewheel(function(event, delta) {
            this.scrollLeft -= (delta * 30);
            event.preventDefault();
        });
    });

6-27

How to get the date without Time from NSDate?

NSDateComponents *components = [[NSCalendar currentCalendar] 
             components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
              fromDate:[NSDate date]];
NSDate *startDate = [[NSCalendar currentCalendar] 
             dateFromComponents:components];

6-23

How to lose margin/padding in UITextView?

self.textView.textContainer.lineFragmentPadding = 0;
self.textView.textContainerInset = UIEdgeInsetsZero;

6-08

links

5-26

links

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    if(self.isMovingFromParentViewController == YES && self.isDirty)
    {
        // do stuff...
    }
}

5-25

###how to save image to photo library in iOS

use UIImageWriteToSavedPhotosAlbum function

- (void)saveImageToPhotoAlbum:(UIImage *)image
{
    id contextInfo = @"can be anything";
    
    UIImageWriteToSavedPhotosAlbum(image,
                                   self,
                                   @selector(image:didFinishSavingWithError:contextInfo:),
                                   (__bridge_retained  void *)(contextInfo));
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    id myInfo = (__bridge_transfer id)contextInfo;
    // use error to check success or not
    // contextInfo is watever you pass in
}

but this way you can't get the path of the image you just saved

use ALAssetsLibrary

- (void)saveImageToPhotoAlbum2:(UIImage *)image
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    [library writeImageToSavedPhotosAlbum:image.CGImage
                              orientation:(ALAssetOrientation)image.imageOrientation
                          completionBlock:^(NSURL *assetURL, NSError *error) {
        
        // now you can use assetURL to find the save image's url
        
    }];
    
}

but ALAssetsLibrary is deprecated in iOS9

use PHPhotoLibrary

// need @import Photos;

- (void)saveImageToPhotoAlbum3:(UIImage *)image
{
    __block PHObjectPlaceholder *placeholder = nil;
    
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        
        PHAssetChangeRequest *request = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
        placeholder = request.placeholderForCreatedAsset;
        
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        
        PHFetchResult<PHAsset *> *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[placeholder.localIdentifier] options:nil];
        
        PHAsset *asset = result.firstObject;
        
        // do watver with PHAsset
        
        // note: this completionHandler runs on arbitrary queue
        
    }];
}

5-23

proper way do UITextField text change call back

textField addTarget:self 
             action:@selector(textFieldDidChange:) 
   forControlEvents:UIControlEventEditingChanged];

5-20

Most reliable way to adjust UITableView cell separator insets

// where you can set it in cellForRowAtIndexPath
// or in cell's awakeFromNib
cell.separatorInset = UIEdgeInsetsMake(0, 50, 0, 0);

5-17

Interesting links

NSNumber *someNumber = [NSNumber numberWithDouble:total];

NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *someString = [nf stringFromNumber:someNumber];

5-12

Interesting links

5-7

Good stuff from surfing

5-6

High-intensity interval training (HIIT), is great!

  • Short bursts of just a few minutes of exhausting physical activity can prepare muscles to work harder, boosting the production of new mitochondria link
  • It seems like the "best" approach is to do low intensity cardio training regularly, and high intensity interval training one to two days a week link
  • One HIIT, One tempo(which is like a moderate high intensity non interval for like 20 minutes) , One Long run(slow and long), in between are easy

How Long and Intense Your Low-Intensity Intervals Should Be

Start out with a 1:2 ratio between high- and low-intensity intervals. For example, 1 minute at high-intensity and 2 minutes at low. As you get fitter, you can work toward a 1:1 ratio. Your rest periods should also be active recovery, where you keep moving, not a standstill. Studies have shown that active, not passive, recovery is advantageous for reaching Vmax during the high-intensity periods and eliciting the adaptive response to the exercise that we’re after.

How Long Should Your HIIT Workouts Be?

The great thing about HIIT is how much you get out of relatively small amounts of it. That said, it can be quite stressful on the body, which means you don’t want to overdo it. Start your workouts with 2 to 3 minutes of low-intensity warm-up and then do 20 to 25 minutes of intervals followed by 2 to 3 minutes of warm-down and you’re done. There’s just no need to do more than this in each workout.

link link2

THE ULTIMATE 8-WEEK HIIT FOR FAT-BURNING PROGRAM

  • all cap so it must be really ultimate

Quick syntax lookup for various programming languages

5-5

how to broadcast with two computers

  • one gaming pc and one streaming pc
  • streaming pc uses capture card, links up with gaming pc via HDMI, duplicate monitor mode on gaming pc
  • use Audio Repeater to duplicate game audio and sends to capture card via hdmi
  • OBS for creating streaming source

5-4

iOS native video player does not support .srt subtitle, only .scc subtitle is supported

SRT file format is generally consist of following unit(s)

15
00:03:03,643 --> 00:03:05,186
I can always...
  • 15 is the sequence number
  • 00:03:03,643 --> 00:03:05,186 is the timestamp and duration
  • I can always... is the content of the subtitle

It possible that the sequence number and timestamp don't match... e.g. the sequence number is small but its timestamp is much later. so when this happen the video player might not show any subtitle when it encounter this kind of discrepancy.

So how do we fix this?

  • we can use the rule -> timestamp dictates its sequence number
  • use subtitle editing app Jubler to sort subtitle units based on timestamp, and regenerate sequence number

About

Today I Learned, literally