Skip to content

Instantly share code, notes, and snippets.

View Neo-J's full-sized avatar

Neo Jiang Neo-J

  • Tesla
  • Tokyo, Shanghai
View GitHub Profile
@Neo-J
Neo-J / swapItem.js
Created January 3, 2018 03:09
swap index of 2 items in an array
function swapItem(arr, fromIndex, toIndex) {
arr[toIndex] = arr.splice(fromIndex, 1, arr[toIndex])[0];
return arr;
};
@Neo-J
Neo-J / gist:98cccc385433256a699e
Created September 18, 2014 03:03
WebColor to UIColor
+ (UIColor *)colorFromHexString:(NSString *)hexString {
unsigned rgbValue = 0;
NSScanner *scanner = [NSScannerscannerWithString:hexString];
[scanner setScanLocation:1];// bypass '#' character
[scannerscanHexInt:&rgbValue];
return [UIColorcolorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
@Neo-J
Neo-J / gist:d42f5c2a03d257eba3bf
Created August 29, 2014 02:51
使用NSAttributedString创建html字符串
NSAttributedString *attrString; // from previous code
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [attrString dataFromRange:NSMakeRange(0, [attrString length]) documentAttributes:options error:nil];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
@Neo-J
Neo-J / gist:cd3c855198927f545ee1
Created August 29, 2014 02:49
使用NSAttributedString来解析html字符串
NSString *html = @"<bold>Wow!</bold> Now <em>iOS</em> can create <h3>NSAttributedString</h3> from HTMLs!";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding]
options:options documentAttributes:nil error:nil];
@Neo-J
Neo-J / index.js
Created August 22, 2014 04:52 — forked from edokeh/index.js
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@Neo-J
Neo-J / gist:6971655
Created October 14, 2013 06:35
Hello world!
Hello world!