This file contains hidden or 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
GRect currentFrame = self.bounds; | |
CGContextSetLineJoin(context, kCGLineJoinRound); | |
CGContextSetLineWidth(context, strokeWidth); | |
CGContextSetStrokeColorWithColor(context, [MyPopupLayer popupBorderColor]); | |
CGContextSetFillColorWithColor(context, [MyPopupLayer popupBackgroundColor]); | |
// Draw and fill the bubble | |
CGContextBeginPath(context); | |
CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f); |
This file contains hidden or 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
func isLatest(id: String, callback: @escaping (Bool?, Error?) -> Void) { | |
var components = URLComponents(string: "http://itunes.apple.com/lookup") | |
components?.queryItems = [URLQueryItem(name: "id", value: id)] | |
var request = URLRequest(url: (components?.url!)!) | |
request.httpMethod = "POST" | |
let task = URLSession.shared.dataTask(with: request) { (data, _, error) in | |
guard error == nil else { | |
callback(nil, error) | |
return | |
} |
This file contains hidden or 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
#import <React/RCTNetworking.h> | |
@interface RCTNetworkTask (SelfSignCert) | |
@end |
This file contains hidden or 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
class TierTreeNode { | |
constructor() { | |
this.father = null | |
this.child = [] | |
this.keepChar = null | |
this.isWord = false | |
} | |
} | |
class TierTree { |
This file contains hidden or 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
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel | |
const popcnt = (v) => { | |
v -= (v >> 1) & 0x55555555 | |
v = (v & 0x33333333) + ((v >> 2) & 0x33333333) | |
return ((v + (v >> 4) & 0xf0f0f0f) * 0x1010101) >> 24 | |
} | |
// Fowler/Noll/Vo hashing. | |
const fnv_1a = (v) => { | |
let a = 2166136261 |
This file contains hidden or 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
import Foundation | |
public class NaiveBayes { | |
/// initialize our vocabulary | |
private(set) var vocalbulary = Set<String>() | |
/// number of documents we have learned from | |
private(set) var totalDocuments = 0 | |
/// document frequency table for each of our categories | |
private(set) var docCount = [String: Int]() | |
/// for each category, how many words total were mapped to it |
This file contains hidden or 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
import Foundation | |
class HashableObject { | |
private static var hashTable = [Int: Int]() | |
private(set) var hashKey: Int = 0 | |
private(set) var id: Int = 0 | |
private(set) static var globalCount = 0 | |
private static var queue = DispatchQueue(label: "your.queue.identifier") |
This file contains hidden or 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
import Foundation | |
struct AVLTree<T: Comparable> { | |
class AVLTreeNode<T: Comparable> { | |
typealias SearchResult = (isFound: Bool, searchNode: AVLTreeNode?, parent: AVLTreeNode?) | |
/// 节点携带的数据 | |
var data: T | |
/// 父节点 | |
var parentNode: AVLTreeNode? | |
/// 左节点 |
This file contains hidden or 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
public extension String { | |
func find(_ text: String) -> [Int] { | |
guard text.count <= self.count else {// 要查找的子串长度大于字符串长度,比较没有了意义…… | |
return [] | |
} | |
// 字符串子串前缀与后缀最大公共长度 | |
let getNext: (String) -> [Int] = { txt -> [Int] in | |
var arr = [Int](repeating: 0, count: txt.count+1) | |
//0和1的值肯定是0 | |
arr[0] = 0 |
This file contains hidden or 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
extension String { | |
subscript (i: Int) -> Character { | |
return self[index(startIndex, offsetBy: i)] | |
} | |
subscript (bounds: CountableRange<Int>) -> Substring { | |
let start = index(startIndex, offsetBy: bounds.lowerBound) | |
let end = index(startIndex, offsetBy: bounds.upperBound) | |
return self[start ..< end] | |
} | |
subscript (bounds: CountableClosedRange<Int>) -> Substring { |