Skip to content

Instantly share code, notes, and snippets.

View davidleee's full-sized avatar

David Lee davidleee

View GitHub Profile
@davidleee
davidleee / osx_dmg_package
Created July 7, 2017 07:51 — forked from 44510/osx_dmg_package
mac osx 程序自动打包为 dmg 文件的脚本
set -e
title='千尋影視' # dmg 文件 mount 了之后在文件系统中显示的名称
background_picture_name='mac-dmg-bg.png' # dmg 文件在 mount 了之后界面中显示的背景图片路径
application_name='千尋影視.app' # 应用程序的名称
# Developer ID 证书的名称(名字的一部分即可,但是需要能在 Keychain Access 中唯一定位到该证书)
developer_id='Developer ID Application: Shanghai Truecolor Multimedia'
# dmg 窗口相关的一些设置,需要根据实际情况做变更
window_left=200 # 窗口位置的 x 坐标
@davidleee
davidleee / String+KeyCode.swift
Created April 13, 2018 09:16
Retrive the key code of macOS keyboard from the keys' names
//
// String+KeyCode.swift
// Volcano-Maxhub
//
// Created by David Lee on 2018/4/13.
// Copyright © 2018年 MAXHUB. All rights reserved.
//
// Thanks to this answer:
// https://stackoverflow.com/questions/10734349/simulate-keypress-for-system-wide-hotkeys/13004403#13004403
@davidleee
davidleee / String+Crypto.swift
Created April 13, 2018 09:20
Getting all kinds of crypted string from the original string (keep updating...)
// You should put "#import <CommonCrypto/CommonHMAC.h>" in the bridge header before using these code
import Foundation
extension String {
func sha256() -> String {
if let stringData = self.data(using: String.Encoding.utf8) as NSData? {
let digest = digestSHA256(source: stringData)
var bytes = [UInt8](repeating: 0, count: digest.length)
digest.getBytes(&bytes, length: digest.length)
import UIKit
extension String {
var glyphCount: Int {
let richText = NSAttributedString(string: self)
let line = CTLineCreateWithAttributedString(richText)
return CTLineGetGlyphCount(line)
}
@davidleee
davidleee / String+ChineseDetect.swift
Created August 10, 2018 01:33
An extension for String to detect if it contains Chinese characters
extension String {
var containsChinese: Bool {
for substring in self {
if substring.isChinese {
return true
}
}
return false
}
}
@davidleee
davidleee / firstDifferenceBetweenStrings.swift
Created August 16, 2018 03:02 — forked from kristopherjohnson/firstDifferenceBetweenStrings.swift
Swift code to find differences between strings and display them in a readable way, useful for displaying unit test results
import Foundation
/// Find first differing character between two strings
///
/// :param: s1 First String
/// :param: s2 Second String
///
/// :returns: .DifferenceAtIndex(i) or .NoDifference
public func firstDifferenceBetweenStrings(s1: NSString, s2: NSString) -> FirstDifferenceResult {
@davidleee
davidleee / BOApplePencilReachability.swift
Created January 5, 2019 03:46
Apple Pencil Detecter by Daniel Bocksteger
/*
Copyright 2017 Daniel Bocksteger
BOApplePencilReachability.swift
from https://gitlab.com/DanielBocksteger/BOApplePencilReachability
Inspiration from Answer on the following question
https://stackoverflow.com/questions/32542250/detect-whether-apple-pencil-is-connected-to-an-ipad-pro/41264961#41264961
@davidleee
davidleee / realmMock.js
Created March 6, 2019 10:05 — forked from hyb175/realmMock.js
Realm Mock for jest
// https://github.com/realm/realm-js/issues/370#issuecomment-270849466
export default class Realm {
constructor(params) {
this.schema = {};
this.callbackList = [];
this.data = {};
this.schemaCallbackList = {};
params.schema.forEach((schema) => {
this.data[schema.name] = {};
});
@davidleee
davidleee / Fonts.swift
Created November 25, 2020 02:56 — forked from feighter09/Fonts.swift
Set global font for iOS app in one place
// MARK: - Swizzling
extension UIFont {
class var defaultFontFamily: String { return "Georgia" }
override public class func initialize()
{
if self == UIFont.self {
swizzleSystemFont()
}
}
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!()