This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env swift | |
import Foundation | |
func oneLoop() -> Double{ | |
var sumValue = 0 | |
let startTime = NSDate().timeIntervalSince1970 | |
for i in 1...100000000 { | |
if (i % 2 == 1) { | |
sumValue++ | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *origin = @"<b><i>hello world</i></b>"; | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[origin dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:YES] | |
options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} | |
documentAttributes:nil | |
error:nil]; | |
_label.attributedText = attributedString; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var attrStr = NSAttributedString( | |
data: "<b><i>text</i></b>".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true), | |
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], | |
documentAttributes: nil, | |
error: nil) | |
label.attributedText = attrStr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(int)solution:(NSArray *)A{ | |
int minimum = 0; | |
for(int i=1; i<A.count; i++){ | |
NSRange range1 = NSMakeRange(0, i); | |
NSArray *array1 = [A subarrayWithRange:range1]; | |
int sum1 = 0; | |
for (int j = 0; j<array1.count; j++) { | |
NSNumber *number = array1[j]; | |
sum1 += number.integerValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*判斷這個 error message 是不是中文:http://stackoverflow.com/questions/6325073/detect-language-of-nsstring*/ | |
//告訴 tagger,我們想要它判斷哪些東西 | |
NSArray *tagsSchemes = @[NSLinguisticTagSchemeLanguage]; | |
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagsSchemes options:0]; | |
//告訴 tagger,我們要它判斷哪句話 | |
[tagger setString:errorMessage]; | |
NSRange range = NSMakeRange(0, errorMessage.length - 1); | |
//告訴 tagger,我們要它判斷的那句話會是哪種語言,不然它可能會判斷成日文或簡中 | |
NSOrthography *orthography = [NSOrthography orthographyWithDominantScript:@"Hant" languageMap:@{@"Hant":@[@"zh-Hant"]}]; | |
[tagger setOrthography:orthography range:range]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(instancetype)PIXURLRequestForOauth2POST:(NSString *)urlString parameters:(NSDictionary *)parameters{ | |
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]; | |
request.HTTPMethod = @"POST"; | |
//設定 http header | |
NSString *contentTypeValue = [NSString stringWithFormat:@"multipart/form-data; charset=utf-8; boundary=%@", kBoundaryConstant]; | |
[request addValue:contentTypeValue forHTTPHeaderField:@"Content-Type"]; | |
//設定 http body | |
[request setHTTPBody:[stringForFormData(parameters) dataUsingEncoding:NSUTF8StringEncoding]]; | |
return request; | |
} |