Skip to content

Instantly share code, notes, and snippets.

View jyliang's full-sized avatar

Jason Liang jyliang

  • New York, NY
  • 00:00 (UTC -05:00)
View GitHub Profile
@jyliang
jyliang / gist:164823ff7361259ad4b6010a7703bbc8
Last active January 31, 2018 06:28
react native inspect component
const _ = require('lodash')
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
https://docs.google.com/presentation/d/19AiyALt7-t5MZLBgTubaJ66njM2GLTO54oOiMG1KAog/edit#slide=id.g13a6caa795_0_7
#define BMTDollarReader(fieldName) \
- (double)fieldName ## Value { \
return BMTCentsToDollars(self.fieldName ## CentsValue); \
} \
\
- (NSNumber *)fieldName { \
return self.fieldName ## Cents ? @(self.fieldName ## Value) : nil; \
} \
// PLRK_SEL_STRING is for specifying selector (usually property) names to KVC
// or KVO methods.
// In debug it will generate warnings for undeclared selectors if
// -Wunknown-selector is turned on.
// In release it will have no runtime overhead.
#ifndef PLRK_SEL_STRING
#ifdef Debug
#define PLRK_SEL_STRING(selName) NSStringFromSelector(@selector(selName))
#else
#define PLRK_SEL_STRING(selName) @#selName
+ (Class)viewModelClassForModel:(Class)modelClass {
NSString *modelClassString = NSStringFromClass(modelClass);
NSInteger suffixLength = [@"Model" length];
NSString *viewModelClassString;
NSRange range = NSMakeRange(modelClassString.length - suffixLength, suffixLength);
viewModelClassString = [modelClassString stringByReplacingCharactersInRange:range
withString:@"ViewModel"];
Class viewModelClass = NSClassFromString(viewModelClassString);
if (!viewModelClass) {
NSLog(@"Internal Name convention broken.");
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
import Result
return RACSignal.createSignal({
(subscriber: RACSubscriber!) -> RACDisposable! in
return nil
})
@interface UIView (FrameObserver)
@end
@implementation UIView (FrameObserver)
- (void)observerFrame {
[self addObserver:self forKeyPath:@"frame" options:0 context:NULL];
[self.layer addObserver:self forKeyPath:@"bounds" options:0 context:NULL];
[self.layer addObserver:self forKeyPath:@"transform" options:0 context:NULL];
[self.layer addObserver:self forKeyPath:@"position" options:0 context:NULL];
- (void)registerKeyboardNotifications {
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)unregisterKeyboardNotifications {
@interface NSObject (category)
@property (nonatomic, copy, setter = setObjectInfo:) id objectInfo;
@end
#import <objc/runtime.h>
static char kObjectInfoDictionaryKey;
@implementation NSObject (category)
@jyliang
jyliang / animation on-off block
Last active August 29, 2015 14:01
animation on/off block
- (void)modifyView:(UIView *)view animated:(BOOL)animated {
void (^block)() = ^{
//modify view animation progress
};
void (^completion)(BOOL) = ^(BOOL finished){
//modify view completion
};
if (animated) {