Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Lex Tang lexrus

🏠
Working from home
View GitHub Profile
@lexrus
lexrus / ToggleHDRCatalina.applescript
Created Mar 26, 2020
Workaround the HDR bug of macOS Catalina 10.15.4
View ToggleHDRCatalina.applescript
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell process "System Preferences"
activate
delay 1
click menu item "Displays" of menu "View" of menu bar 1
delay 1
@lexrus
lexrus / createml.swift
Created Jun 29, 2018
CreateML 双色球
View createml.swift
import Cocoa
import CreateML
let 双色球神算子 = try MLTextClassifier(trainingData: [
"中奖啦": [
"09 11 14 20 27 30 09",
"02 09 14 15 16 23 10",
"11 16 19 22 25 30 08",
"02 05 06 13 16 19 03",
"04 09 15 16 19 27 10",
View CandleChart.swift
import UIKit
import PlaygroundSupport
let chartData: [Double] = [1, 2, 4, 0, 0, 2, 6, 0, 4, 8, 12, 14, 1, 2, 2, 0, 0, 1, 6, 0, 4, 0, 3, 0]
class TimelineCandleChart: UIView {
var data: [Double] = [] {
didSet { setNeedsDisplay() }
}
@lexrus
lexrus / RxTextFieldDelegateProxy.swift
Created Feb 14, 2018
RxSwift extension for textFieldShouldReturn of UITextFieldDelegate
View RxTextFieldDelegateProxy.swift
//
// RxTextFieldDelegateProxy.swift
//
// Created by Lex Tang on 2/14/18.
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
//
import RxSwift
import RxCocoa
@lexrus
lexrus / update_settings_version.sh
Created Aug 10, 2017
Update version string in Settings.bundle
View update_settings_version.sh
#!/bin/bash
PLISTBUDDY="/usr/libexec/PlistBuddy"
INFO_PLIST="$CODESIGNING_FOLDER_PATH/Info.plist"
SETTINGS_PLIST="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist"
VERSION_NUMBER="`$PLISTBUDDY -c \"Print CFBundleShortVersionString\" \"$INFO_PLIST\"`"
BUILD_NUMBER="`$PLISTBUDDY -c \"Print CFBundleVersion\" \"$INFO_PLIST\"`"
VERSION="Version $VERSION_NUMBER ($BUILD_NUMBER)"
GROUP_INDEX="`xmllint --xpath \"count(//array/dict)-1\" \"$SETTINGS_PLIST\"`"
$PLISTBUDDY -c "Set :PreferenceSpecifiers:$GROUP_INDEX:Title '$VERSION'" "$SETTINGS_PLIST"
@lexrus
lexrus / CollectionOperator.swift
Created Apr 24, 2017
Avoid hard-coded KVC collection operators
View CollectionOperator.swift
import Foundation
enum CollectionOperator: String {
case avg
case count
case max
case min
case sum
@lexrus
lexrus / enable-von-forward-nat.sh
Created Jun 15, 2016
Enable VPN forward for OpenVPN on Mac OS X El Capitan
View enable-von-forward-nat.sh
#
# https://roelant.net/2015/share-your-vpn-mac-el-capitan.html
sleep 15
#
/usr/sbin/sysctl -w net.inet.ip.fw.enable=1
/usr/sbin/sysctl -w net.inet.ip.forwarding=1
/usr/sbin/sysctl -w net.inet6.ip6.forwarding=1
pfctl -d
pfctl -f /Users/lex/Dropbox/openvpn/pf.conf -e
@lexrus
lexrus / BackgroundHint.m
Created May 11, 2016
iOS task list hint
View BackgroundHint.m
//
// BackgroundHint.m
// Zus
//
// Created by Lex on 4/13/16.
// Copyright © 2016 lex.sh. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
View patch001.lua
luaSetWaxConfig({openBindOCFunction="true"})
waxClass{"Zus.SettingVC"}
function viewDidLoad(self)
print("lua viewDidLoad");
self:ORIGviewDidLoad();
self:setTitle("Wax-patched " .. wax.appVersion)
end
@lexrus
lexrus / swift-interview-outline.md
Last active Dec 28, 2016
Swift interview outline
View swift-interview-outline.md
  • Array 是 value type,使用 structs 实现
  • 数据类型没有隐式转换
  • 对于 String,count() 的复杂度是 O(n),每一个 Character 都是 unicode scalars 的序列
  • raw values 和 associated values 的区别
  • 如果必要,对于实现了 _ObjectiveCBridgeable 的 value types 会被自动桥接成 reference types
  • 讲一下 unowned 和 weak 的区别
  • 改 struct 的属性的方法名前要加 mutating,但如果这个 struct 用 let 声明的,改不了。修正:网友指出用 nonmutating set 也可以改属性。
  • nil 和 .None 的区别
  • capture list in closure
  • 举一个 guard ... where 的例子
You can’t perform that action at this time.