Skip to content

Instantly share code, notes, and snippets.

View zhaozzq's full-sized avatar
😜
I may be slow to respond.

Zhao zhaozzq

😜
I may be slow to respond.
View GitHub Profile
@zhaozzq
zhaozzq / ChineseTransliterator.swift
Created May 8, 2021 09:22
Transliterate Chinese between simplified and traditional (the wrong way).
import UIKit
struct ChineseTransliterator {
static func transliterate(text: String, sourceView: UIView) {
let textView = UITextView()
textView.isHidden = true
textView.text = text
textView.selectAll(nil)
sourceView.addSubview(textView)
// 进入后台
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
// 结束应用
DispatchQueue.main.asyncAfter(deadline: .now() + 1.25) {
  UIApplication.shared.perform(Selector(("terminateWithSuccess")))
}
@zhaozzq
zhaozzq / Perform-In-ViewDidApear-once.md
Last active August 21, 2020 09:06
UIViewController 第一次 viewDidApear
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if self.isBeingPresented || self.isMovingToParent {
            //Perform an action that will only be done once
        } 
    }
@zhaozzq
zhaozzq / Dictionary+KeyPaths.swift
Created July 31, 2019 10:14
Accessing Dictionaries with Key Paths
//
// DictionaryExtension.swift
// Haiyu
// zhao_zzq2012@163.com
// Created by zhaozzq@github on 2019/7/31.
// Copyright © 2019 Haiyu. All rights reserved.
// https://oleb.net/blog/2017/01/dictionary-key-paths/
// https://swift.gg/2017/01/25/dictionary-key-paths/
import Foundation
@zhaozzq
zhaozzq / 设置git代理.md
Last active January 26, 2024 10:53 — forked from chuyik/README.md
macOS 给 Git(Github) 设置代理(HTTP/SSH)
@zhaozzq
zhaozzq / open_xcode_project.sh
Created March 6, 2019 08:11
SourceTree Custom Action
#仓库路径
REPO_PATH=$1
#文件的类型
# OPEN_TYPE=$2
LIST=`find "$REPO_PATH" -name "*.xcworkspace" | grep -v ".xcodeproj/project.xcworkspace"`
if [ -z "$LIST" ] ; then
LIST=`find "$REPO_PATH" -name "*.xcodeproj" | grep -v "Pods.xcodeproj"`
fi
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if completion {
completion!()
@zhaozzq
zhaozzq / UIButton+VerticalLayout.m
Created August 17, 2018 02:31 — forked from lucaspang/UIButton+VerticalLayout.m
iOS UIButton center Image and Text Vertically
@interface UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding;
- (void)centerVertically;
@end
@implementation UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding
@zhaozzq
zhaozzq / codeshortcuts.py
Created June 27, 2018 03:13
VS Code 快捷键
# Duplicate Lines
# Shift + Option + Up Down Arrow Keys
# Move line up or down
# Alt / Option + Up Down Arrow Keys
# Write on multiple lines (without mouse)
# Shift + Option + Command + Up Down Arrow Keys
# Write on multiple lines (with mouse)
@zhaozzq
zhaozzq / inject.markdown
Last active March 30, 2021 12:39
Inject js to WKWebView
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
NSString *eruda = @"(function () { var script = document.createElement('script'); script.src='//cdn.jsdelivr.net/npm/eruda'; document.body.appendChild(script); script.onload = function () { eruda.init() } })();";
WKUserScript *script = [[WKUserScript alloc] initWithSource:eruda injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
[configuration.userContentController addUserScript:script];
_webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];

or

NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"vConsole" ofType:@"js"];