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
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
@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
@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 / RCTNetworkTask+SelfSignCert.h
Created April 17, 2018 11:30
解决RN证书信任的问题(尚未测试)
#import <React/RCTNetworking.h>
@interface RCTNetworkTask (SelfSignCert)
@end
@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 / 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 / PhotoManager.swift
Created July 25, 2018 11:28
iCloud && Photos.framework
//
// PhotoManager.swift
// EShopHelper
//
// Created by Jiang,Zhenhua on 2018/7/25.
// Copyright © 2018年 Daubert. All rights reserved.
//
import Foundation
import Photos
@AmatsuZero
AmatsuZero / proxyStatus.swift
Created August 14, 2018 02:45
iOS端检查是否设置了代理
/// 是否设置了代理
///
/// - Returns: 代理设置情况
func getProxyStatus() -> Bool {
guard let proxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue(),
let url = URL(string: "https://www.baidu.com") else {
return false
}
let proxies = CFNetworkCopyProxiesForURL((url as CFURL), proxySettings).takeUnretainedValue() as NSArray
guard let settings = proxies.firstObject as? NSDictionary,
@AmatsuZero
AmatsuZero / .gitconfig
Last active June 27, 2023 09:49
My Zsh Config
[alias]
a = add
amend = commit --amend
c = commit
ca = commit --amend
ci = commit -a
co = checkout
d = diff
dc = diff --changed
ds = diff --staged
//
// AudioProgressiveView.swift
// EShopHelper
//
// Created by Jiang,Zhenhua on 2018/10/16.
// Copyright © 2018 Daubert. All rights reserved.
//
import UIKit