Skip to content

Instantly share code, notes, and snippets.

View simonpang's full-sized avatar

Simon Pang simonpang

  • Hong Kong
View GitHub Profile
@simonpang
simonpang / RxSwiftMultithreadTests.swift
Last active November 27, 2018 07:22
RxSwift multi-threading tests
//
// RxSwiftMultithreadTests.swift
// GoodNotesTests
//
// Created by Simon Pang on 27/11/2018.
// Copyright © 2018 Time Base Technology Limited. All rights reserved.
//
import XCTest
import RxSwift
@simonpang
simonpang / ViewController.m
Last active May 30, 2018 08:15
Dynamic collection view cell size using auto-layout
//
// ViewController.m
// DemoScrolling
//
// Created by Simon Pang on 30/5/2018.
// Copyright © 2018 Simon Pang. All rights reserved.
//
#import "ViewController.h"
@simonpang
simonpang / Application.swift
Last active February 2, 2018 08:54
Debug UIEvent
override func sendEvent(_ event: UIEvent) {
NSLog("sendEvent \(event)")
super.sendEvent(event)
var vc = keyWindow!.rootViewController!
while vc.presentedViewController != nil {
vc = vc.presentedViewController!
}
// Find hit view
if let view = vc.view {
@simonpang
simonpang / MVMUM.swift
Last active November 10, 2017 09:39
MVMUM Architecture (i.e. View ViewModel UseCase Model)
MVMUM Architecture (View ViewModel UseCase Model)
V > VM > UC > M ( i.e. direction of dependency)
<= direct of flow control
=> increasing relevant to domain (i.e. plain object)
<= increasing relevant to framework/environment (i.e. platform objects with side effect e.g. native GUI, database)
Example: (user login screen)
@simonpang
simonpang / gist:b08353a13eb776c7639f
Last active August 29, 2015 14:14
Network Request Library in Cocoa Style (Command pattern)
@interface DNSession : NSObject<NSCopying, NSCoding>
@property (copy) NSString *authToken;
@property (copy) NSString *userIdentifier;
+ (instancetype)defaultSession;
- (instancetype)initWithConfiguration:(NSDictionary *)options;
@end
@simonpang
simonpang / gist:5301093
Created April 3, 2013 13:14
Dreaming of promise event handling v3
- (id)init
{
if (self = [super initNibName:nil bundle:nil]) {
[[[[self whenViewDidLoad] then:^(id result, NSError *error) {
return [self.loginButton whenTouchDown];
}] then:^(id result, NSError *error) {
@simonpang
simonpang / gist:5292844
Created April 2, 2013 14:54
Dreaming of promise base event handling v2
- (id)init
{
if (self = [super initNibName:nil bundle:nil]) {
[[self whenViewDidLoad] then:^(id result, NSError *error) {
[[self.loginButton whenTouchDown] then:^(id result, NSError *error) {
[[client login:self.loginField.text password:self.passwordField.text] then:^(id result, NSError *error) {
[client saveAccessToken:[result token]];
@simonpang
simonpang / LoginViewController.m
Last active December 15, 2015 15:39
Dreaming of promise base API for event handling
- (id)init
{
if (self = [super initNibName:nil bundle:nil]) {
[[self whenViewDidLoad] then:^{
id loginPromise = [client login:self.loginField password:self.passwordField when:[self.loginButton whenTouchDown]];
[UIAlertView presentMessage:^{ return [loginPromise alertError]; } when:[loginPromise whenFail]];
[client saveAccessToken:[self.loginPromise whenSuccess]];
[self presentModalViewController:[RegisterViewController willCreate] when:[self.registerButton whenTouchDown]];
}];
@simonpang
simonpang / tlc.lua
Created October 15, 2012 14:06 — forked from seclorum/tlc.lua
LuaJIT ObjC bridge
-- TLC - The Tiny Lua Cocoa bridge
-- Note: Only tested on x86_64 with OS X >=10.7.3 & iPhone 4 with iOS 5
-- Copyright (c) 2012, Fjölnir Ásgeirsson
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@simonpang
simonpang / gist:3760453
Created September 21, 2012 08:54
Create RAM disk on OS X
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://2175854`