Skip to content

Instantly share code, notes, and snippets.

View jdewind's full-sized avatar

Justin DeWind jdewind

  • LifeWorks
  • Grand Rapids
View GitHub Profile
function doTap(x, y, numTaps, delay)
delay = delay or 16000;
local fingerId = 1;
for i=numTaps,1,-1
do
touchDown(fingerId, x, y);
usleep(delay);
touchUp(fingerId, x, y);
usleep(delay);
end
- (instancetype)fetchPerson:(NSInteger)personId {
[[self fetchAtEndPoint: [NSString stringWithFormat: @"/person/%d", personId], mapTo: [Person class]] flattenMap: ^(id person) {
if(!person) {
return [RACSignal error: nil];
} else {
return [RACSignal return: person];
}
}];
}
- (void) load {
RACSignal* signal = [api fetchPerson: personId];
[signal subscribeNext: ^(id person) {
[view renderPerson: person];
}];
[signal subscribeError: ^(NSError *error) {
[view renderError];
}];
}
- (void) load {
RACSignal *signal = [[api fetchPerson: personId] flattenMap: ^(id person) {
return [[[api fetchFamilyMembers: person.id] map: ^(id familyMembers) {
return [self buildViewModel: person familyMembers: familyMembers];
}] startWith: [self buildViewModel: person familyMembers: @[]];
}];
}
@jdewind
jdewind / subform_tap.rb
Created May 27, 2014 18:54
Subform ontap
@form.row(:subform_key).row(:a_row).on_tap |do|
end
@interface ApplicationDelegate<UIApplicationDelegate>
@end
@implementation ApplicationDelegate
- (RACSignal *)rac_registeredForRemoteNotifications {
RACSignal *signal = objc_getAssociatedObject(self, _cmd);
if (signal != nil) return signal;
RACSignal *didRegisterForRemoteNotification = [[self rac_signalForSelector: @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:) fromProtocol: @protocol(UIApplicationDelegate)] map: ^(RACTuple *tuple) {
return tuple.second;
@jdewind
jdewind / DelegateExample.m
Last active January 4, 2016 17:19
ReactiveCocoaDelegateExample
- (void)viewDidLoad {
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame: CGRectZero];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchController.delegate = self;
// Place it in view
searchBar.delegate = self;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
self.searchResults = [self search: text];
class MyViewController < UIViewController
def viewDidLoad
@search_bar = UISearchBar.alloc.initWithFrame CGRectZero
self.navigationController.rac_liftSelector "setNavigationBarHidden:animated:", withSignalsFromArray: [@search_bar.rac_editing, RACSignal.return(true)]
# Add search bar to table view, etc.
end
end
@implementation UISearchBar (RAC)
- (RACSignal *)rac_editing {
// Pretend we have an ivar I know we'd use setAssociatedObject
_proxy = [[RACDelegateProxy alloc] initWithProtocol: @protocol(UISearchBarDelegate)];
return [@[
[[_proxy signalForSelector: @selector(searchBarTextDidBeginEditing:)] mapReplace: @YES],
[[_proxy signalForSelector: @selector(searchBarTextDidEndEditing:)] mapReplace: @NO]
].rac_sequence.signal switchToLatest];
}
@end
@jdewind
jdewind / mapping-hash.rb
Created November 22, 2013 19:31
Terse approach to mapping a Hash
Hash[query.map { |k,v| [k, [v].flatten[0]] }]