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 / ANSIColor.swift
Created December 30, 2017 00:43
Generate Terminal Printable QRCode by Swift
import Foundation
enum ANSIColor: UInt8 {
enum Platte: String {
case WHITE_ALL = "\u{2588}"
case WHITE_BLACK = "\u{2580}"
case BLACK_WHITE = "\u{2584}"
case BLACK_ALL = ""
}
@AmatsuZero
AmatsuZero / polygon.js
Created February 25, 2018 11:01
Core HTML Canvas Samples Codes with ES6
const canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
slidesSelect = document.getElementById('sideSelect'),
startAngleSelect = document.getElementById('startAngleSelect'),
fillCheckbox = document.getElementById('fillCheckbox'),
mosuseDown = {x:0, y: 0},
rubberBandRect = {}
@AmatsuZero
AmatsuZero / context_count.swift
Last active February 26, 2018 11:12
Study OpenCL
import Foundation
import OpenCL
func contextCount() throws {
var platform: cl_platform_id?
guard clGetPlatformIDs(1, &platform, nil) >= 0 else {
fatalError("找不到任何平台")
}
var devices = [cl_device_id?]()
#import <Foundation/Foundation.h>
/// Utilities for NSStrings containing HTML
@interface NSString (GTMNSStringHTMLAdditions)
/// Get a string where internal characters that need escaping for HTML are escaped
//
/// For example, '&' become '&amp;'. This will only cover characters from table
/// A.2.2 of http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters
/// which is what you want for a unicode encoded webpage. If you have a ascii
//
// Sort.swift
// CLSwift
//
// Created by modao on 2018/3/11.
// Copyright © 2018年 MockingBot. All rights reserved.
//
import Foundation
@AmatsuZero
AmatsuZero / MBSlideInAnimationManager.swift
Created March 15, 2018 10:39
Custom modal transition
class MBSlideInAnimationManager: NSObject {
var direction = PresentationDirection.left
var disableCompactHeight = false
enum PresentationDirection {
case left, top, right, bottom
}
}
@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 {
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
import Foundation
struct AVLTree<T: Comparable> {
class AVLTreeNode<T: Comparable> {
typealias SearchResult = (isFound: Bool, searchNode: AVLTreeNode?, parent: AVLTreeNode?)
/// 节点携带的数据
var data: T
/// 父节点
var parentNode: AVLTreeNode?
/// 左节点
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")