Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mmackh's full-sized avatar

Maximilian Mackh mmackh

View GitHub Profile
@mmackh
mmackh / gist:5797253
Last active December 18, 2015 14:28
Parse terrible news.ycombinator.com HTML in Obj-C with Hpple
- (void)loadCommentsOnStoryWithID:(NSString *)storyID result:(void(^)(NSArray *results))completionBlock
{
NSString *queryURLString = [NSString stringWithFormat:@"https://news.ycombinator.com/item?id=%@",storyID];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:queryURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSMutableArray *comments = [NSMutableArray new];
@mmackh
mmackh / NSString+Additions.h
Last active January 19, 2017 23:12
Personal NSString Additions
//
// NSString+Hash.h
// Orbitink
//
// Created by mmackh on 5/3/13.
// Copyright (c) 2013 Professional Consulting & Trading GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@mmackh
mmackh / NSDate+Extensions.m
Last active December 19, 2015 15:39
Find the number of overlapping days of 4 NSDates
- (BOOL) isBetweenBeginDate:(NSDate *)beginDate endDate:(NSDate *)endDate
{
return ([self compare:beginDate] == NSOrderedDescending || [self compare:beginDate] == NSOrderedSame) && ([self compare:endDate] == NSOrderedAscending);
}
- (NSInteger)distanceInDaysToDate:(NSDate *)anotherDate
{
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit fromDate:self toDate:anotherDate options:0];
return components.day;
@mmackh
mmackh / NSObject+Notifications.h
Last active December 23, 2015 09:39
NSObject category for an NSNotificationCenter abstraction to keep your code clean & lean.
//
// NSObject+Notifications.h
// InstaPDF
//
// Created by Maximilian Mackh on 18/09/13.
// Copyright (c) 2013 mackh ag. All rights reserved.
//
#import <Foundation/Foundation.h>
@mmackh
mmackh / PCCountedObjectContainer.h
Last active August 29, 2015 13:55
Ordered NSCountedSet. Subclassing and overwrite `- (id)keyForObject:(id)object` to specify your own keys for objects.
//
// PCCountedObjectContainer.h
// Slingshot
//
// Created by Maximilian Mackh on 02/02/14.
// Copyright (c) 2014 Professional Consulting & Trading GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@mmackh
mmackh / gist:9049038
Created February 17, 2014 11:35
KNX Write Protocol
- (void)changeStatusOfObject:(PCHousemasterObject *)object toValue:(float)value
{
NSArray *groupAddressArray = [object.groupAddress componentsSeparatedByString:@"/"];
NSString *groupAddressBaseTwo = [NSString stringWithFormat:@"%@%@%@",[self convertToBinary:[groupAddressArray[0] integerValue] padding:5],[self convertToBinary:[groupAddressArray[1] integerValue] padding:3],[self convertToBinary:[groupAddressArray[2] integerValue] padding:8]];
NSString *groupAddressDecimal = [NSString stringWithFormat:@"%ld",strtol([groupAddressBaseTwo UTF8String], NULL, 2)];
NSString *message = [NSString stringWithFormat:@"1|%@|%i\0",groupAddressDecimal,(int)(value * 100)];
NSLog(@"%@",message);
//
// PCMutableDirectory.h
// SmartOrderKit
//
// Created by Maximilian Mackh on 23/03/14.
// Copyright (c) 2014 Professional Consulting & Trading GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>

Keybase proof

I hereby claim:

  • I am mmackh on github.
  • I am maxi (https://keybase.io/maxi) on keybase.
  • I have a public key whose fingerprint is 262F 8E5A F8AF 56AA 84BD F742 17E5 DA95 49FE 7E1B

To claim this, I am signing this object:

@mmackh
mmackh / gist:e24f4ad31326e54a68f1
Created September 21, 2014 18:20
Change UIStatusBar Color
NSString *statusBarString = [NSString stringWithFormat:@"_s%@at%@sBar",@"t",@"u"];
NSString *colorKey = @"foregroundColor";
id statusBar = [application valueForKey:statusBarString];
if (statusBar && [statusBar respondsToSelector:NSSelectorFromString(colorKey)])
{
[statusBar setValue:[AFPConstantsColorGold colorWithAlphaComponent:0.5] forKey:colorKey];
}
@mmackh
mmackh / PCWebView.h
Last active April 13, 2017 09:48
PCWebView
//
// PCWebView.h
//
// Created by Maximilian Mackh on 25/03/2017.
// Note this Open Source class relies on PCSplitView.h found on Github
#import <UIKit/UIKit.h>
@interface PCWebView : UIView