Skip to content

Instantly share code, notes, and snippets.

View ytyubox's full-sized avatar
😎
TooFastToSlow

Tsungyu Yu ytyubox

😎
TooFastToSlow
View GitHub Profile
class Button:UIButton{
typealias Handler = (Button)->Void
var title:String = "default title"{
didSet {
setTitle("Default Title", for: [])
sizeToFit()
}
}
var tapHandle:Handler!
@ytyubox
ytyubox / sVim.rc
Last active April 23, 2019 02:56
sVimrc
map "ctrl+w" nextWindow
map "ctrl+W" previousWindow
unmap "w"
map "ctrl+k" nextTab
map "ctrl+j" previousTab
unmap "K"
unmap "J"
@ytyubox
ytyubox / ATimer.swift
Last active May 1, 2019 14:25
A friendly timer
protocol ATimer {
func start()
func stop()
var isRuning:Bool{get}
var timeInterval:TimeInterval{get set}
typealias Job = ()->Void
}
class AReapeatTimer:ATimer{
var isRuning: Bool {return timer != nil}
init(job: @escaping Job) {
@ytyubox
ytyubox / README.md
Last active May 3, 2019 17:32
UITextDocumentProxy Detail

documentContextBeforeInput & documentContextAfterInput

The Document is auto recognized for Sentence like String.

-- Cursor postion --⇣ 
A Random text. B Ran🙆dom String.

textDocumentProxy.documentContextBeforeInput  //B Ran
textDocumentProxy.documentContextAfterInput   //dom String.
@ytyubox
ytyubox / URLSession+.swift
Last active May 7, 2019 14:24
easy DataTask
extension URLSession{
typealias URLResult = Result<(Data,URLResponse),Error>
typealias URLCallback = (URLResult)->Void
enum URLERROR:Error {
case nodata, reponseUnknow
}
func CallBackDataTask(with request:URLRequest,
callback:@escaping URLCallback){
let task = dataTask(with: request) { (data, reponse, error) in
var result:URLResult

file io in swift

Make a file

#!/bin/bash
touch the/path/to/file
@ytyubox
ytyubox / Jest_test.md
Created May 18, 2019 10:07
Share note on the day of May 16, 2019, host by Howard at GoodIdeas Studio, Tainan.
title tags
透過 Jest 快速測試 API,不用燃燒生命幫後端 debug
Howard, test, jest, API

透過 Jest 快速測試 API,不用燃燒生命幫後端 debug

後端 API 測試責任 前端手動測試 前端遲早要自己測試 API 的!

Objective-C and Swift

OC project injecting Swift

#import "_projectName_-Swift.h"
@property (nonatomic, strong) _swiftClass_ *property;

Swift project injecting OC

@ytyubox
ytyubox / README.md
Last active June 6, 2019 04:48
A good way to route by Coordinator

usage

class AppDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let tabC = UITabBarController()
        let mC = MCoordinator()
        
        coordinator = MainCoordinator(tabBarController: tabC, tabs: [mC])
 coordinator?.start()
@ytyubox
ytyubox / APIFetching3CaseResult.swift
Last active June 11, 2019 12:10
A API Endpoint with two response
class EndPointsManager{
struct Route<Model:Codable,APIError:Codable>{
let endpoint:String
let info:[String:String]
}
private let urlComponents:URLComponents
let session = URLSession.shared