Skip to content

Instantly share code, notes, and snippets.

View AmatsuZero's full-sized avatar
💭
I may be slow to respond.

Daubert Jiang AmatsuZero

💭
I may be slow to respond.
  • Tencent
  • Beijing, China
View GitHub Profile
@AmatsuZero
AmatsuZero / MyPopupLayer.m
Created July 3, 2018 12:51
Speech Bubble
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);
@AmatsuZero
AmatsuZero / CheckVersion.swift
Last active May 16, 2018 08:55
利用iTunes接口检查是否有更新
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
}
@AmatsuZero
AmatsuZero / RCTNetworkTask+SelfSignCert.h
Created April 17, 2018 11:30
解决RN证书信任的问题(尚未测试)
#import <React/RCTNetworking.h>
@interface RCTNetworkTask (SelfSignCert)
@end
@AmatsuZero
AmatsuZero / TierTree.js
Created March 30, 2018 08:02
JS版字典树
class TierTreeNode {
constructor() {
this.father = null
this.child = []
this.keepChar = null
this.isWord = false
}
}
class TierTree {
@AmatsuZero
AmatsuZero / BloomFilter.js
Last active December 14, 2018 05:28
布隆过滤器的实现
// 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
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
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")
import Foundation
struct AVLTree<T: Comparable> {
class AVLTreeNode<T: Comparable> {
typealias SearchResult = (isFound: Bool, searchNode: AVLTreeNode?, parent: AVLTreeNode?)
/// 节点携带的数据
var data: T
/// 父节点
var parentNode: AVLTreeNode?
/// 左节点
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
@AmatsuZero
AmatsuZero / String+Extensions.swift
Created March 19, 2018 06:05
String subscript extension
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 {