Skip to content

Instantly share code, notes, and snippets.

View syshen's full-sized avatar

Steven Shen syshen

View GitHub Profile
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
[[self.viewModel.refreshCommand.executing deliverOnMainThread] subscribeNext:^(id executing) {
if ([executing boolValue]) {
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeGradient];
} else {
[SVProgressHUD dismiss];
}
}];
@weakify(self);
[[self.viewModel.refreshCommand.errors deliverOnMainThread] subscribeNext:^(NSError *error) {
- (RACCommand*) refreshCommand {
if (_refreshCommand)
return _refreshCommand;
_refreshCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [[HNClient sharedClient] topStories];
}];
return _refreshCommand;
}
RACSignal *falseSignal = [RACSignal return:@(NO)];
RACSignal *triggerSignal = [[RACSignal combineLatest:@[[self rac_didStartLoad], [self rac_didFinishLoad]]] map:^id(id value) {
@strongify(self);
return @(self.canGoForward);
}];
signal = [RACSignal merge:@[falseSignal, triggerSignal]];
- (void)testNormalReturn {
// Create mock objects for API clients
id HNClientMock = OCMPartialMock([HNClient sharedClient]);
id RAClientMock = OCMPartialMock([ReadabilityClient sharedClient]);
// Stub the API responses
NSDictionary *HNRtn = @{@"by":@"andrewbarba",
@"descendants":@12,
@"id":@9135641,
@"kids":@[@9135772,@9135785],
@weakify(self);
[[RACObserve(self.viewModel, url) deliverOnMainThread] subscribeNext:^(NSString *urlString) {
@strongify(self);
self.urlLabel.text = urlString;
}];
RAC(self.urlLabel, text) = [RACObserve(self.viewModel, url) deliverOnMainThread];
- (RACSignal*) topStories {
return [[[self rac_GET:@"topstories.json" parameters:nil] reduceEach:^id(AFHTTPRequestOperation *op, NSArray * response) {
return response;
}] deliverOn:[RACScheduler schedulerWithPriority:RACSchedulerPriorityBackground]];
}
@syshen
syshen / gist:8e78894aa403f4059e70
Created January 28, 2015 04:35
Request to register
POST 'http://localhost:5999/api/v3/register': {
"Accept-Language" = "en;q=1";
"Content-Type" = "application/json; charset=utf-8";
"User-Agent" = "EMQ/0.6 (iPhone Simulator; iOS 8.1; Scale/2.00)";
"X-Device-ID" = 5794b6b61929b402c20be8447ef6a3e3fb1f6afc;
} {"password":"******","mobile_number":"+8860921607734","full_name":"Steve Jobs","email":"steve_jobs@apple.com","mobile_country_code":"tw"}
2015-01-28 12:33:25.234 EMQ[6238:132268] 200 'http://localhost:5999/api/v3/register' [3.2715 s]: {
"Content-Length" = 677;
"Content-Type" = "application/json";
Date = "Wed, 28 Jan 2015 04:33:25 GMT";
@syshen
syshen / nsurlsession.m
Last active August 29, 2015 14:10
NSURLSession
NSURLSessionConfiguration *conf = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:con delegate:self delegateQueue:nil];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest: req];
[task resume];