Skip to content

Instantly share code, notes, and snippets.

View kingnight's full-sized avatar
🎯
Focusing

jinkai kingnight

🎯
Focusing
View GitHub Profile
@kingnight
kingnight / 0_reuse_code.js
Created June 14, 2014 01:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kingnight
kingnight / gist:ea323d77e9ad18dde19d5aa3493de1b2
Created December 11, 2018 10:11 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
import Foundation
protocol StateType: Hashable {}
protocol EventType: Hashable {}
struct Transition<S: StateType, E: EventType> {
let event: E
let fromState: S
let toState: S
// orogin swift protocol and calling
protocol aProtocol {
func testFunc()
}
class aStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
class bStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
@kingnight
kingnight / errorcodes.m
Created June 18, 2020 02:41 — forked from samirahmed/errorcodes.m
NSURLErrorDomain codes
kCFURLErrorUnknown = -998,
kCFURLErrorCancelled = -999,
kCFURLErrorBadURL = -1000,
kCFURLErrorTimedOut = -1001,
kCFURLErrorUnsupportedURL = -1002,
kCFURLErrorCannotFindHost = -1003,
kCFURLErrorCannotConnectToHost = -1004,
kCFURLErrorNetworkConnectionLost = -1005,
kCFURLErrorDNSLookupFailed = -1006,
kCFURLErrorHTTPTooManyRedirects = -1007,
@kingnight
kingnight / sendmail_setup.md
Created January 15, 2021 11:29 — forked from kany/sendmail_setup.md
Setup SENDMAIL on Mac OSX Yosemite
@kingnight
kingnight / xcframework_realm.sh
Created May 15, 2022 08:42 — forked from leemaguire/xcframework_realm.sh
Remove naming collisions in swiftinterface. Run this script in the root of the RealmSwift.xcframework folder
#!/bin/bash
set -o pipefail
set -e
find . -name "*.swiftinterface" -exec sed -i -e 's/Realm\.//g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/import Private/import Realm.Private/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/RealmSwift.Configuration/RealmSwift.Realm.Configuration/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/extension Configuration/extension Realm.Configuration/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/RealmSwift.Error/RealmSwift.Realm.Error/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/extension Error/extension Realm.Error/g' {} \;
@kingnight
kingnight / StopJumpingTableViewOnInsertRows.swift
Created July 7, 2022 06:19 — forked from joshdholtz/StopJumpingTableViewOnInsertRows.swift
Used when loading more data into UITableView for a smooth "infinite scroll" feel
// I dont want my table jumping/animation when appending new rows
// for an infinite scroll feel
//
// Some of this might not be needed but it works
//
// TODO: Possibly garbage
extension UITableView {
func reloadDataSmoothly() {
UIView.setAnimationsEnabled(false)