Skip to content

Instantly share code, notes, and snippets.

View muizidn's full-sized avatar
👨‍🚀
Working between Tiangong and Mir

Former Not Wannabe Lord Paramount of the Wkwkland muizidn

👨‍🚀
Working between Tiangong and Mir
  • Indian Ocean
View GitHub Profile
@muizidn
muizidn / git_sizer.rb
Last active August 10, 2019 13:41
Check git size
require 'open-uri'
require 'json'
url = ARGV[0]
uri = URI.parse(url)
api_uri = "https://api.github.com/repos" + uri.path
puts "fetch from: #{api_uri}"
json_string = URI.parse(api_uri).read
json = JSON.parse(json_string)
size = json["size"]
@muizidn
muizidn / Closure.swift
Last active August 10, 2019 05:51
Make autocompletion gives you better result when assign closure
/// Eg: Closure<(Int) -> Void>
struct Closure<T> {
let closure: T
}
class LoginView: UIView {
var appereanceConfig: Closure<(UIStackView)->Void> = .init { _ in }
private stackView: UIStackView()
convenience init() {
@muizidn
muizidn / LifetimeLoggable.swift
Last active August 8, 2019 06:10
Log your object lifetime and count. Make sure it never leaked.
#if DEBUG
// By muiz.idn@gmail.com
import Foundation
fileprivate var kTracker: UInt = 0
fileprivate var items: [String:Int] = [:]
protocol LifetimeLoggable: AnyObject {
@muizidn
muizidn / HorizontalCollectionLayout.swift
Last active August 10, 2019 02:15
A Horizontal UICollectionLayout with Dynamic Width Cell
import ViewDSL // https://github.com/muizidn/viewdsl
import TinyConstraint // https://github.com/roberthein/TinyConstraints
import RxSwift // https://github.com/ReactiveX/RxSwift
import RxCocoa // https://github.com/ReactiveX/RxSwift
// The Visual Format Language may not correct!
fileprivate let kHeight: CGFloat = 30.0 // V:|-0-(cell)-0-|
fileprivate let kCellSubviewPadding: CGFloat = 10 // H:|-(10)-(subview)
// If we register multiple cell, make sure the estimated width is 2 * biggest padding in registered cell
@muizidn
muizidn / TypeSafeUserDefault.swift
Created July 15, 2019 06:54
Make your User Default TypeSafe.
import Foundation
// UserDefault is threadsafe
// https://developer.apple.com/documentation/foundation/userdefaults
struct State<T>: Equatable where T: Codable & Equatable {
fileprivate let id: String
fileprivate let `default`: T
}
@muizidn
muizidn / New_Mac.md
Last active May 27, 2019 06:57
What to do after install new macOS?
@muizidn
muizidn / Make_OSX_INSTALLER_WITHOUT_MAC.lnk
Created May 26, 2019 22:41
Nice Tutorial For Your Mac Development
Avoid Hackintosh, but sometimes need it to regain access to my unbootable Mac. Hupfh.
https://www.insanelymac.com/forum/topic/329828-making-a-bootable-high-sierra-usb-installer-entirely-from-scratch-in-windows-or-linux-mint-without-access-to-mac-or-app-store-installerapp/
import Foundation
class ChatRoom: NSObject, StreamDelegate {
var inputStream: InputStream!
var outputStream: OutputStream!
var username: String = ""
static let maxReadDefault = 4096
func setupNetworkCommunication() {
@muizidn
muizidn / UIScrollView+UIView+SnapKit.swift
Last active March 29, 2019 00:48
Collection of Examples for ViewDSL
view.add { (scroll: UIScrollView) in
scroll.backgroundColor = .green
scroll.snp.makeConstraints { maker in
maker.edges.equalTo(view.snp.edges)
}
scroll.add { (v: UIView)in
v.backgroundColor = .red
/// Vertical Scrolling
@muizidn
muizidn / ActionDirector.swift
Last active February 27, 2019 09:38
An Action Director handle all your UIControl behavior. In beautiful and manageable way!
/// Target-Action helper.
final class Action<I>: NSObject {
private let _action: (I) -> Void
private let _input: I
private let identifier = UUID().uuidString
init(action: @escaping (I) -> Void, input: I) {
_action = action
_input = input
super.init()
}