Skip to content

Instantly share code, notes, and snippets.

@altyus
altyus / recursivereduce.swift
Last active August 29, 2015 14:17
Recursive Reduce Swift
//Implement Reduce
func reduceRecursively <A, R>(xs: [A], initialValue: R, combine:(R, A) -> R) -> R {
if let head = xs.first {
let tail = Array(dropFirst(xs))
return reduceRecursively(tail, combine(initialValue, head), combine)
} else {
return initialValue
}
}
@altyus
altyus / gist:10299517
Last active August 29, 2015 13:58
Center two labels in view with Visual Format Language
self.stepLabel = [[UILabel alloc] init];
self.stepLabel.text = @"0 Steps";
self.stepLabel.textAlignment = NSTextAlignmentCenter;
self.stepLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:50];
self.historicalLabel = [[UILabel alloc] init];
self.historicalLabel.text = @"Historical";
self.historicalLabel.textAlignment = NSTextAlignmentCenter;
self.historicalLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:50];
@altyus
altyus / gist:10223831
Created April 9, 2014 03:35
Parse Cloud code to get Post objects for in network friends with passed in facebook IDs
Parse.Cloud.define("friends", function(request, response){
var query = new Parse.Query("User");
query.containedIn("facebook_id", request.params.facebook_ids_array);
query.find({
success: function(results){
var friendIDs = new Array();
for (var i = 0; i < results.length; i++)
{
friendIDs.push(results[i].get('facebook_id'));
}
@altyus
altyus / gist:9916207
Created April 1, 2014 15:13
Facebook Get Friends List Social Framework
- (void)getFacebookFriendsListWithCompletion:(void(^)(NSArray *friendsDictionaries))completion
{
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *accounts = [self.accountStore accountsWithAccountType:accountType];
NSDictionary *params = @{@"limit": @5000,
@"offset": @0};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:params];
@altyus
altyus / gist:9916182
Created April 1, 2014 15:12
Facebook Login With ACAccountStore
- (void)facebookLoginWithCompletion:(void (^)(NSString *userID, NSString *email, NSString *fullName))completion
{
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
ACFacebookAppIdKey:FACEBOOKAPPID,
ACFacebookPermissionsKey: @[@"read_stream", @"basic_info"],
I need Help really really bad
Joe I need help
Joe I need help