This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh -f | |
# Purpose: Check to see if we are running on Big Sur | |
# | |
# From: Timothy J. Luoma | |
# Mail: luomat at gmail dot com | |
# Date: 2020-07-10 | |
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin" | |
# this will check to make sure `sw_vers` exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ipName = getIpAddress() ?? "" | |
func getIpAddress() -> String? { | |
var address : String? | |
// Get list of all interfaces on the local machine: | |
var ifaddr : UnsafeMutablePointer<ifaddrs>? | |
guard getifaddrs(&ifaddr) == 0 else { return nil } | |
guard let firstAddr = ifaddr else { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension UIDevice { | |
enum DeviceModelName: String { | |
case undefined | |
case iPodTouch5 | |
case iPodTouch6 | |
case iPhone4 | |
case iPhone4s | |
case iPhone5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(iOS 13.0, *) | |
func exampleCombineKVO () { | |
let article = Article(title: "Test", body: "Lorum ipsum") | |
// For a KeyPath 101, see https://www.swiftbysundell.com/posts/the-power-of-key-paths-in-swift | |
let keypath: ReferenceWritableKeyPath<Article,String> = \.title | |
// The new Combine stuff: | |
let sink = Subscribers.Assign(object: article, keyPath: keypath) | |
let source = Publishers.Future<String, Never> { subscriber in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class CodeTextField: UITextField, UITextFieldDelegate { | |
let codeLength: Int | |
var characterSize: CGSize | |
var characterSpacing: CGFloat | |
let textPreprocess: (String) -> String | |
let validCharacterSet: CharacterSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIScrollView { | |
func scrollSubViewToTop(_ subview: UIView, offset: CGFloat, animated: Bool) { | |
let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
setContentOffset(CGPoint(x: 0, y: point.y - offset), animated: animated) | |
} | |
func viewPortOffset(of subview: UIView) -> CGFloat { | |
let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
return point.y - contentOffset.y | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OVERVIEW: Swift compiler | |
USAGE: swiftc [options] <inputs> | |
MODES: | |
-dump-ast Parse and type-check input file(s) and dump AST(s) | |
-dump-parse Parse input file(s) and dump AST(s) | |
-dump-scope-maps <expanded-or-list-of-line:column> | |
Parse and type-check input file(s) and dump the scope map(s) | |
-dump-type-refinement-contexts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation AppHostCookie | |
+ (NSMutableArray<NSString *> *)cookieJavaScriptArray | |
{ | |
NSMutableArray<NSString *> *cookieStrings = [[NSMutableArray alloc] init]; | |
//取出cookie | |
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Since the WKWebView has no sizeToFit() method, increase the frame height of the webView to | |
// match the height of the content's scrollHeight | |
// | |
// The WKWebView's `navigationDelegate` property needs to be set for the delegate method to be called | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
if webView.isLoading == false { | |
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in | |
if let height = result as? CGFloat { |
NewerOlder