Skip to content

Instantly share code, notes, and snippets.

static int getMinPathValue(int[][] input) {
int[] firstLine = input[0];
ArrayList<Integer> buff = new ArrayList<Integer>(Collections.nCopies(firstLine.length, Integer.MAX_VALUE));
int result = 0;
for (int y=0; y<input.length; y++) {
for (int x=0; x<input.length; x++) {
if (input[y][x] < buff.get(x)) {
buff.set(x, input[y][x]);
@SunXiaoShan
SunXiaoShan / ThrottleDemo.m
Created July 17, 2017 06:41
ThrottleDemo
const NSTimeInterval INTERVAL_TIME = 0.5; // 0.5 sec
RACSubject *subject = [RACSubject subject];
[[subject throttle:INTERVAL_TIME] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
[subject sendNext:@1];
[subject sendNext:@2];
[subject sendNext:@3];
[subject sendNext:@4];
@SunXiaoShan
SunXiaoShan / DistinctUntilChangedDemo.m
Created July 17, 2017 06:13
DistinctUntilChangedDemo
RAC(self.labelView, text) = [RACObserve(objA, strContent) distinctUntilChanged];
objA.strContent = @"content1"; // 1st
objA.strContent = @"content1"; // 2nd
objA.strContent = @"content1"; // 3rd
@SunXiaoShan
SunXiaoShan / callback.js
Created July 14, 2017 08:22
callbackDemo
function main(data,cb){
fun1(data,function(err,data){
if(!err){
fun2(data,function(err,data){
if(!err){
fun3(data,cb);
}else{
cb(err);
}
});
@SunXiaoShan
SunXiaoShan / RACwaterfall.m
Created July 14, 2017 07:42
RACwaterfallDemo
// Define function
- (RACSignal *)RACSignalDemoA {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
NSLog(@"handle A");
[subscriber sendNext:@"A"];
[subscriber sendCompleted];
return nil;
}];
}
@SunXiaoShan
SunXiaoShan / RACSignalDemoFunction.m
Last active July 14, 2017 04:05
RACSignalDemoFunction
- (RACSignal *)RACSignalDemoFunction {
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
// your code ...
BOOL isSuccess = YES;
NSObject *result = [NSObject new];
if (isSuccess) {
[subscriber sendNext:result];
[subscriber sendCompleted];
} else {
// JAVA
// QUESTION 1
static String getReverseString(String input) {
char[] in = input.toCharArray();
char buff;
for (int i=0,j=input.length()-1; i<input.length()/2;i++,j--) {
buff = in[i];
in[i] = in[j];
in[j] = buff;
}
@SunXiaoShan
SunXiaoShan / SimpleDemo.m
Last active July 8, 2017 19:42
RAC_SimpleDemo
@interface Model:NSObject
@property (strong, nonatomic) NSString *content;
@end
@implementation Model
@end
@interface ViewModel:NSObject
@property (strong, nonatomic) NSString *content;
- (void) execute:(NSString *)content;
@SunXiaoShan
SunXiaoShan / RAC_button_click.m
Created July 7, 2017 09:43
RAC_button_click
[[self.btnButton rac_signalForSelector:@selector(actionButton:)] subscribeNext:^(RACTuple * _Nullable x) {
NSLog(@"button click..");
}];
@SunXiaoShan
SunXiaoShan / RAC_notification.m
Created July 7, 2017 09:38
RAC_notification
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidShowNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
NSLog(@"keyboard - \n%@", x);
}];