Skip to content

Instantly share code, notes, and snippets.

返回日期数列里与目标数列最近的日期下标
const getNearestDateIndex = (targetDate, dates) => {
    if (!targetDate || !dates) {
        throw new Error('Argument(s) is illegal !')
    }
    if (!dates.length) {
        return -1
 }
@K-Kevin
K-Kevin / dispatch_benchmark-Monkey
Created November 29, 2017 08:59
iOS 知识点
##dispatch_benchmark-Monkey
GCD 之 dispatch_benchmark 测量指定代码块执行时间
#import <Foundation/Foundation.h>
// 声明GCD中dispatch_benchmark函数原型
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));
int main(int argc, const char * argv[]) {
@autoreleasepool {
private let defaultTopType: String = "application"
private let defaultSubType: String = "octet-stream"
/// Represents a media type, consisting of a top-level type and a subtype.
/// May also possess parameters which adjust or qualify the media type.
/// MimeType parameters are not parsed or processed but are provided as-is as a String
public struct MimeType: ExpressibleByStringLiteral, CustomStringConvertible, Comparable {
/// Required for StringLiteralConvertible
public typealias StringLiteralType = String
@K-Kevin
K-Kevin / UIImageComfress.swift
Last active September 6, 2017 09:59
swift comfress image
extension UIImage {
/// 图片压缩
///
/// - Parameters:
/// - maxFileSize: 压缩后的最大容量,单位 MB
/// - compression: 初始压缩值,默认为 1
/// - Returns:
func mcCompress(maxFileSize: Int, compression: CGFloat = 1.0) -> Data? {
@K-Kevin
K-Kevin / upload.swift
Created September 6, 2017 09:54
Alamofire file upload
func requestWith(endUrl: String, imageData: Data?, parameters: [String : Any], onCompletion: ((JSON?) -> Void)? = nil, onError: ((Error?) -> Void)? = nil){
let url = "http://google.com" /* your API url */
let headers: HTTPHeaders = [
/* "Authorization": "your_access_token", in case you need authorization header */
"Content-type": "multipart/form-data"
]
Alamofire.upload(multipartFormData: { (multipartFormData) in
import UIKit
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
@K-Kevin
K-Kevin / Camera&Gallery
Last active September 6, 2017 09:55
Access to Camera and Photo Library