Skip to content

Instantly share code, notes, and snippets.

View ethanhuang13's full-sized avatar

Ethan Huang ethanhuang13

View GitHub Profile
@JohnSundell
JohnSundell / gh
Created April 30, 2018 07:51
Script that makes it easy to show a Git repo on GitHub.com
#!/usr/bin/env bash
# If run without a name, open any current repo
if [ -z "$1" ]; then
URL=$(git remote get-url origin)
URL=${URL/"git@github.com:"/"https://github.com/"}
URL=${URL/".git"/""}
open $URL
else
open "https://github.com/$1"
@erica
erica / BTWhee.swift
Last active January 22, 2019 20:42
import Cocoa
import CoreBluetooth
import PlaygroundSupport
class BTHelper: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
var centralManager: CBCentralManager
override init() {
self.centralManager = CBCentralManager(delegate: nil, queue: nil)
super.init()
@hongrich
hongrich / gist:260fc8c36aaed3f2a63c0612ba9fc910
Last active June 3, 2019 20:29
App Store Review Guidelines
App Store Review Guidelines
Introduction
Apps are changing the world, enriching people’s lives, and enabling developers like you to innovate like never before. As a result, the App Store has grown into an exciting and vibrant ecosystem for millions of developers and more than a billion users. Whether you are a first time developer or a large team of experienced programmers, we are excited that you are creating apps for the App Store and want to help you understand our guidelines so you can be confident your app will get through the review process quickly.
The guiding principle of the App Store is simple - we want to provide a safe experience for users to get apps and a great opportunity for all developers to be successful. We do this by offering a highly curated App Store where every app is reviewed by experts and an editorial team helps users discover new apps every day. For everything else there is always the open Internet. If the App Store model and guidelines are not best for your app or business idea th
@pofat
pofat / GetCreationTime.swift
Last active June 20, 2019 17:20
Get the timestamp of creation time of the process which runs your application in iOS
func getProcessStartTime() -> TimeInterval {
let pid = ProcessInfo.processInfo.processIdentifier
var procInfo = kinfo_proc()
var cmd: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid]
var size = MemoryLayout.stride(ofValue: procInfo)
if sysctl(&cmd, UInt32(cmd.count), &procInfo, &size, nil, 0) == 0 {
// tv_sec is timestamp measured in second; tv_usec is the rest fraction part in microsecond
return Double(procInfo.kp_proc.p_un.__p_starttime.tv_sec) * 1000.0 + Double(procInfo.kp_proc.p_un.__p_starttime.tv_usec) / 1000.0
} else {
print("Can't get information of process \(pid)")
@oleksii-demedetskyi
oleksii-demedetskyi / ReducerBuidler.swift
Created June 12, 2019 12:48
Redux reducer composed using new @functionBuilder api
protocol Action {}
struct Reducer<State> {
let reduce: (State, Action) -> State
}
struct Increment: Action {}
struct Decrement: Action {}
func on<State, A>(_ actionType: A.Type, reduce: @escaping (State, A) -> State) -> Reducer<State> {
@yllan
yllan / FloatingPointExact.swift
Created November 28, 2019 13:12
Calculate the exact value of flaoting point number
// 特殊的數字我沒處理,會 fail。例如 subnormal 或者 NaN
// 用法: 0.94.exact() // "0.939999999999999946709294817992486059665679931640625"
//
// main.swift
// FloatingPoint
//
// Created by Yung-Luen Lan on 2019/8/27.
// Copyright © 2019 yllan. All rights reserved.
//
@pofat
pofat / get_pre_main_time.swift
Created February 16, 2020 14:23
Get pre-main time
/// Call this at main()
/// return: time in milliseconds
func getPreMainTime() -> Double {
let currentTimeIntervalInMilliSecond = Date().timeIntervalSince1970 * 1000.0
var procInfo = kinfo_proc()
let pid = ProcessInfo.processInfo.processIdentifier
var cmd: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid]
var size = MemoryLayout.stride(ofValue: procInfo)
// Retrieve information of current process
if sysctl(&cmd, UInt32(cmd.count), &procInfo, &size, nil, 0) == 0 {
@klemenzagar91
klemenzagar91 / MulticastDelegateV2.swift
Created June 22, 2017 12:16
Multicast Delegate with hash table
class MulticastDelegate <T> {
private let delegates: NSHashTable<AnyObject> = NSHashTable.weakObjects()
func add(delegate: T) {
delegates.add(delegate as AnyObject)
}
func remove(delegate: T) {
for oneDelegate in delegates.allObjects.reversed() {
if oneDelegate === delegate as AnyObject {
enum Equality<T: Equatable> {
case equal(T)
case notEqual
}
func == <T: Equatable>(lhs: T, rhs: T) -> Equality<T> {
if lhs == rhs {
return .equal(lhs)
} else {
return .notEqual
@yesleon
yesleon / UIWindow+AuthenticationSession.swift
Last active July 13, 2020 03:51
A wrapper around ASWebAuthenticationSession and SFAuthenticationSession.
//
// Usage:
//
// Facebook:
//
// 1. Follow this guide (WITHOUT setting up a URL scheme in Xcode):
// https://github.com/fullstackreact/react-native-oauth/issues/76#issuecomment-335902057
//
// 2. call startFacebookAuthenticationSession(appID:completionHandler:) on a window:
//