Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
JaviSoto / gist:6516942
Created September 10, 2013 22:57
iOS 7 Parallax effect
@interface UIView (JSParallaxEffect)
- (void)js_addParallaxEffectWithMaxOffset:(CGFloat)maxOffset;
@end
@JaviSoto
JaviSoto / gist:6926083
Last active November 15, 2021 06:37
Rotation transformation with anchor point
- (void)rotateView:(UIView *)view
byRadianDegrees:(CGFloat)radianDegrees
withAnchorPoint:(CGPoint)relativeAnchorPoint
{
const CGRect viewBounds = view.bounds;
const CGPoint anchorPoint = CGPointMake(viewBounds.size.width * relativeAnchorPoint.x, viewBounds.size.height * relativeAnchorPoint.y);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, anchorPoint.x, anchorPoint.y);
transform = CGAffineTransformRotate(transform, radianDegrees);
@JaviSoto
JaviSoto / gist:7092061
Created October 21, 2013 22:31
NSData decorator example if you're putting the bytes of an object in NSData and want to make sure ARC doesn't deallocate that object before you call -[data bytes];
@interface JSObjectBytesDataDecorator : NSData
+ (instancetype)dataDecoratorWithData:(NSData *)data holdingOnToBytesOfObject:(id)object;
@end
@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