Today I Learned, literally
iOS stuff
- How do I convert an NSString value to NSData?
- Is it possible to force Excel recognize UTF-8 CSV files automatically?
- 為何使用 Microsoft Excel 打開匯出的報名人 CSV 檔案是亂碼?
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();
});
});
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];
How to lose margin/padding in UITextView?
self.textView.textContainer.lineFragmentPadding = 0;
self.textView.textContainerInset = UIEdgeInsetsZero;
links
- Common Mistakes With Adding Custom Fonts to Your iOS App
- Custom Fonts in Swift
- How to integrate and use Font Awesome with Objective-C or Swift in an Xcode project?
- Custom UIView from Xib file in Xcode 5 for Reusable Components - Part 1
- Create an IBDesignable UIView subclass with code from an XIB file in Xcode 6
links
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if(self.isMovingFromParentViewController == YES && self.isDirty)
{
// do stuff...
}
}
###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
}];
}
proper way do UITextField text change call back
textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
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);
Interesting links
- This is why most mobile development projects fail
- NSNumberFormatter use this to show currency base on current locale
NSNumber *someNumber = [NSNumber numberWithDouble:total];
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *someString = [nf stringFromNumber:someNumber];
Interesting links
- ELI5: Why do some organs come in pairs, like Kidneys and Lungs, but others are singular, such as the Liver or Heart?
- The easy & reliable way of handling UITableView insets when the keyboard is shown
- 5:2 diet - 2 days of low calorie(like 600ish for men), 5 days of normal calorie
- Soylent or soylent alternatives for healthy meal replacement, gaining muscle, and saving money?
Good stuff from surfing
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.
THE ULTIMATE 8-WEEK HIIT FOR FAT-BURNING PROGRAM
- all cap so it must be really ultimate
Quick syntax lookup for various programming languages
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
iOS native video player does not support .srt subtitle, only .scc subtitle is supported
- Scenarist Closed Caption (.scc file extension)
- srt file format
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 number00:03:03,643 --> 00:03:05,186
is the timestamp and durationI 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