Skip to content

Instantly share code, notes, and snippets.

View lexrus's full-sized avatar
🏠
Working from home

Lex Tang lexrus

🏠
Working from home
View GitHub Profile
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 / com.shadowsocks.chinadns.plist
Last active May 31, 2018 18:39
LaunchCtl plist of ChinaDNS for El Capitan.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.shadowsocks.chinadns</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/chinadns</string>
<string>-c</string>
@lexrus
lexrus / enable-von-forward-nat.sh
Created June 15, 2016 12:44
Enable VPN forward for OpenVPN on Mac OS X El Capitan
#
# 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 / update_settings_version.sh
Created August 10, 2017 07:33
Update version string in Settings.bundle
#!/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 / swift-interview-outline.md
Last active December 28, 2016 07:04
Swift interview outline
  • 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 的例子
@lexrus
lexrus / BackgroundHint.m
Created May 11, 2016 02:00
iOS task list hint
//
// 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>
luaSetWaxConfig({openBindOCFunction="true"})
waxClass{"Zus.SettingVC"}
function viewDidLoad(self)
print("lua viewDidLoad");
self:ORIGviewDidLoad();
self:setTitle("Wax-patched " .. wax.appVersion)
end
@lexrus
lexrus / LTLog.h
Last active February 21, 2016 19:56
My DDLog config
//
// LTLog.h
//
// Created by Lex on 6/29/14.
// Copyright (c) 2014 LexTang.com. All rights reserved.
// https://gist.github.com/lexrus/8c6414e7c0177e9e66ea
//
#import <Foundation/Foundation.h>
@lexrus
lexrus / gist:5734257
Last active January 6, 2016 08:54
Log all NSNotifications. #import <objc/runtime.h> absolutely! Original: https://coderwall.com/p/7mopeq
#if TARGET_IPHONE_SIMULATOR
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit"
// Log all notifications via tail -f /tmp/msgSends-*
instrumentObjcMessageSends(YES);
#pragma clang diagnostic pop
#endif
@lexrus
lexrus / dump_edit_page_url_list_in_ios_dev_center.js
Created January 2, 2014 15:43
Dump edit page url list in iOS Dev Center
$.post(profileDataURL, function(d){d.provisioningProfiles.map(function(o){console.log('https://developer.apple.com/account/ios/profile/profileEdit.action?type=&provisioningProfileId='+o.provisioningProfileId)})});