Skip to content

Instantly share code, notes, and snippets.

💭
🏔🏃‍♂

Rui Peres RuiAAPeres

💭
🏔🏃‍♂
Block or report user

Report or block RuiAAPeres

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RuiAAPeres
RuiAAPeres / gist:8905610
Last active Aug 29, 2015
RACSignal + Filter + Timer
View gist:8905610
// The goal is to make a server call every 5 minutes, but I want to make sure the user has at least moved 500 meters, how would go after this:
[RACObserve(self, userLocation) filter:^BOOL(CLLocation *newLocation)
{
return [newLocation distanceFromLocation:self.userLocation]>APH500Meters;
}];
// I was thinking on creating a scheduler so I got this:
RACScheduler *scheduler = [RACScheduler schedulerWithPriority:RACSchedulerPriorityDefault];
@RuiAAPeres
RuiAAPeres / gist:11190505
Created Apr 22, 2014
Swizzling valueForKey: and objectForKey:
View gist:11190505
#import <objc/runtime.h>
@implementation NSDictionary (Swizzled)
static void swizzInstance(Class class, SEL originalSel, SEL newSel)
{
Method origMethod = class_getInstanceMethod(class, originalSel);
Method newMethod = class_getInstanceMethod(class, newSel);
method_exchangeImplementations(origMethod, newMethod);
@RuiAAPeres
RuiAAPeres / gist:11353385
Created Apr 27, 2014
Draft new spec ReactiveCocoa
View gist:11353385
Pod::Spec.new do |s|
s.name = "ReactiveCocoa"
s.version = "2.3"
s.summary = "A framework for composing and transforming streams of values."
s.homepage = "https://github.com/blog/1107-reactivecocoa-is-now-open-source"
s.author = { "Josh Abernathy" => "josh@github.com" }
s.source = { :git => "https://github.com/ReactiveCocoa/ReactiveCocoa.git", :tag => "v#{s.version}" }
s.license = 'MIT'
s.description = "ReactiveCocoa (RAC) is an Objective-C framework for Functional Reactive Programming. It provides APIs for composing and transforming streams of values."
@RuiAAPeres
RuiAAPeres / gist:11402456
Last active Aug 29, 2015
Sam Page's SparkRecording Implementation with Facebook's Pop
View gist:11402456
//The calculations are coming from [here](https://gist.github.com/d-ronnqvist/11266321) (thanks David!)
- (void)updateAnimations
{
CGFloat duration = self.duration * (1.f - [[self.progressLayers firstObject] strokeEnd]);
CGFloat strokeEndFinal = 1.f;
for (CAShapeLayer *progressLayer in self.progressLayers)
{
POPBasicAnimation *popEndAnimation = [POPBasicAnimation animation];
View gist:52875b29e846427814f7
//The magic method
-(id (^)(id,...)) getSelector:(SEL) aSelector forTarget:(id) target withFirstArgument:(id) firstArgument {
id (^blockName)(id,...) = ^id(id values,...) {
id cenas = firstArgument;
SEL theSelector;
NSMethodSignature *aSignature;
NSInvocation *anInvocation;
View gist:3c828d37a8a3507ae8ea
func sum(lhs : Int)(rhs : Int) -> Int {
return lhs + rhs
}
let sum2 = sum (2)
let pair1 = sum2(rhs: 1)
let pair2 = sum2(rhs: 2)
let pair3 = sum2(rhs: 3)
let pair4 = sum2(rhs: 4)
View gist:3ef7af142a8958aaa62a
func curry<T,U,V>(f:(T,U)->V) -> T -> U -> V
{
return {x in { y in f(x,y)}}
}
extension Array {
var decompose : (T,[T])? {
return (count > 0) ? (self[0], Array(self[1..<count])) : nil
}
}
View ActionsWithPriority.swift
import Foundation
import ReactiveCocoa
final class PriorityAction<T> {
let identifier : String
let action : Action<Void, [T], Error>
init(identifier: String, action: Action<Void, [T], Error>) {
@RuiAAPeres
RuiAAPeres / NSObject+FacebookImage
Created Aug 29, 2013
Just a small piece of code to get the basic info + profile picture
View NSObject+FacebookImage
+ (void(^)())facebookImageBlockWithCompletionHandler:(void(^)(id profilePicture, id userInformation, NSError *error))completionHandler
{
void(^facebookBlock)()= ^{[FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
if (!error)
{
You can’t perform that action at this time.