Skip to content

Instantly share code, notes, and snippets.

View mmackh's full-sized avatar

Maximilian Mackh mmackh

View GitHub Profile
@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);
@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 / 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 / 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 / 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 / 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];