Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
JaviSoto / PBMainThreadSynchronousScheduler.h
Last active August 29, 2015 13:55
PBMainThreadSynchronousScheduler
#import <ReactiveCocoa/RACQueueScheduler+Subclass.h>
/**
* This scheduler class schedules values sent down a signal on the main thread synchronously
* if they're sent on the main thread as opposed to RACScheduler.mainThreadScheduler
* which always sends values asynchronously.
*/
@interface PBMainThreadSynchronousScheduler : RACQueueScheduler
+ (instancetype)mainThreadSynchronousScheduler;
@JaviSoto
JaviSoto / ReactiveCocoa.md
Last active August 29, 2015 13:56
ReactiveCocoa

ReactiveCocoa

A lot is being written these days about ReactiveCocoa and the paradigms it introduces. In my opinion, there are only two sides giving their opinion: the ones that know a lot about it and are therefore obviously biased, and the ones that refuse to learn it.

I decided to write something myself because I think I'm right in the middle. Some months ago I knew nothing about it, and now I know enough to want to use it every day. I hope that by not being an expert, I can actual introduce a few really simple ideas in a much easier way to pick up by new-commers, to show why I think ReactiveCocoa is an incredibly powerful tool to help us write better, cleaner, and more maintainable code.

It's signals all the way down

The base of everything that happens in ReactiveCocoa is signals. I'm going to try to explain what they represent and why they fit in the way we think about what happens on an app. A lot of the things you may read about Functional Reactive Programming end up confusing you when

@JaviSoto
JaviSoto / gist:9984349
Last active August 29, 2015 13:58
-[UIViewController viewWillAppear:] from UIView
- (void)tapIntoViewControllerWillAppear {
@weakify(self);
[[[[[[[RACSignal interval:0.1f onScheduler:[RACScheduler mainThreadScheduler]] takeUntil:self.rac_willDeallocSignal] flattenMap:^RACStream *(id value) {
@strongify(self);
return [RACSignal return:self.pb_viewController];
}] ignore:nil] take:1] flattenMap:^RACStream *(UIViewController *viewController) {
return [viewController rac_signalForSelector:@selector(viewWillAppear:)];
}] subscribeNext:^(id x) {
@strongify(self);
@JaviSoto
JaviSoto / keybase.md
Created April 11, 2014 23:17
keybase.md

Keybase proof

I hereby claim:

  • I am javisoto on github.
  • I am javisoto (https://keybase.io/javisoto) on keybase.
  • I have a public key whose fingerprint is A401 6A03 CA78 5463 EF54 B0B1 4196 06D9 0B5A BAFD

To claim this, I am signing this object:

#!/bin/bash
# https://gist.github.com/949831
# http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
# command line OTA distribution references and examples
# http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
# http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html
struct Set<T: AnyObject> : Printable {
typealias ElementType = (T: AnyObject)
var set: NSMutableSet
init() {
self.init(array: [] )
}
init(array: ElementType[]) {
@JaviSoto
JaviSoto / gist:292435381bb2e0d31402
Last active August 29, 2015 14:12
Functor and Monad in Swift blog post
@JaviSoto
JaviSoto / gist:2407956
Created April 17, 2012 18:18
AppleScript to add a reminder to iCal
on run taskName
tell application "iCal"
tell calendar "WhateverYourReminderListIsCalled"
make new todo at end with properties {summary:taskName}
end tell
end tell
end run
@JaviSoto
JaviSoto / gist:3933095
Created October 22, 2012 18:14 — forked from steipete/gist:3933090
Simple main thread usage detector that I'm using in PSPDFKit to find performance problems early on.
// Smart little helper to find main thread hangs. Enable in appDidFinishLaunching.
// Only available with source code in DEBUG mode.
@interface PSPDFHangDetector : NSObject
+ (void)startHangDetector;
@end
@implementation PSPDFHangDetector
+ (void)startHangDetector {
#ifdef DEBUG
@JaviSoto
JaviSoto / watchface01.c
Created April 17, 2013 16:58
My first Pebble Watchface
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x57, 0xFF, 0x75, 0x31, 0x72, 0x97, 0x46, 0x0A, 0x86, 0x02, 0x6F, 0x6F, 0x79, 0xEA, 0x4E, 0xE4 }
PBL_APP_INFO(MY_UUID,
"Watchface", "Javier Soto",
1, 0, /* App version */
DEFAULT_MENU_ICON,