Skip to content

Instantly share code, notes, and snippets.

View priore's full-sized avatar

Prioregroup.com priore

View GitHub Profile
@priore
priore / issimulator.m
Created July 20, 2016 14:13
Identifies if is running from the device or simulator
#include <sys/sysctl.h>
+ (NSString*)hardwareString
{
int name[] = {CTL_HW,HW_MACHINE};
size_t size = 100;
sysctl(name, 2, NULL, &size, NULL, 0); // getting size of answer
char *hw_machine = malloc(size);
sysctl(name, 2, hw_machine, &size, NULL, 0);
@priore
priore / BaseViewController.m
Created July 5, 2016 12:41
Tips: a solid dealloc for all classes
#import <objc/runtime.h>
@implementation BaseViewController()
- (void)dealloc
{
[CATransaction setCompletionBlock:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
@priore
priore / loadwithurl.m
Last active April 22, 2016 11:00
Standardize AFNetworking calls
// [url] : service url
// [parameters] : optional parameters
// [keyPath] : optional root key to retrieve data
// [class] : object class that should return in the array
//
// eg. [PRHTTPSessionManager loadWithURL:@"http://mioservizio.com" parameters:nil keyPath:nil class:[ProductModel class] completion:....
// eg. [PRHTTPSessionManager loadWithURL:@"http://mioservizio.com" parameters:nil keyPath:@"products.list" class:[ProductModel class] completion:....
//
+ (void)loadWithURL:(NSString*)url
@priore
priore / CustomLabel.m
Created April 18, 2016 16:24
UILabel correct way to padding left/right
// UILabel correct way to padding left/right
#import <UIKit/UIKit.h>
@interface CustomLabel : UILabel
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
@end
#import "CustomLabel.h"
@priore
priore / pep.m
Created March 24, 2016 15:32
Performance examination procedure
// performance examination procedure
#ifdef DEBUG
double then, now;
now = CFAbsoluteTimeGetCurrent();
#endif
//
// TODO: your code here
//
@priore
priore / NSObject+CRC32.m
Last active March 24, 2016 16:34
CRC32 from generic NSObject
#import <zlib.h>
- (NSUInteger)crc32
{
// the object requires NSObject-Coding https://github.com/priore/NSObject-Coding
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self];
return crc32(0, data.bytes, data.length);
}
@priore
priore / dispatch_cancelable_block_t.h
Created March 4, 2016 16:25
Cancellable dispatch_after
#ifndef dispatch_cancellable_block_h
#define dispatch_cancellable_block_h
#import <Foundation/Foundation.h>
// https://github.com/SebastienThiebaud/dispatch_cancelable_block/issues/2
typedef void(^dispatch_cancelable_block_t)(BOOL cancel);
NS_INLINE dispatch_cancelable_block_t dispatch_after_delay(NSTimeInterval delay, dispatch_block_t block) {
if (block == nil) {
@priore
priore / scrollviewsense.m
Created March 3, 2016 16:40
Scroll direction pulses with a value sensitivity
@interface ViewController () <UIScrollViewDelegate>
{
CGFloat initialContentOffset;
CGFloat previousContentDelta;
}
@property (nonatomic, assign) CGFloat senseValue;
@end
@priore
priore / uiimagetext.m
Created February 28, 2016 02:59
Add text to image
//
// Created by Danilo Priore on 18/08/12.
// Copyright (c) 2012 Prioregroup.com. All rights reserved.
//
- (UIImage*)addTextToImage:(UIImage*)img text:(NSString*)text1 XPos:(int)xpos YPos:(int)ypos fontName:(NSString*)fontName fontSize:(CGFloat)fontSize fontColor:(UIColor*)fontColor {
int w = img.size.width;
int h = img.size.height;
@priore
priore / twtimeline.m
Created February 28, 2016 02:58
How to load Twitter Timeline Widget in a UIWebView
// 1. Before create a HTML file named mywidget.html and with content :
// <html>
// <head>
// <title></title>
// <script src="http://platform.twitter.com/widgets.js"> </script>
// </head>
// <body>
// <a class="twitter-timeline" height="%i" href="https://mobile.twitter.com/DaniloPriore" data-widget id="318522515175645184" data-chrome="noheader nofooter transparent" data-border-color="#cc0000" style="display:none"> </a>
// </body>
//</html>