Skip to content

Instantly share code, notes, and snippets.

View priore's full-sized avatar

Prioregroup.com priore

View GitHub Profile
@priore
priore / gist:3128985
Created July 17, 2012 11:49
How to enable automatic observer notification
//
// How to enable automatic observer notification
//
// Created by Danilo Priore on 03/04/12.
// Copyright (c) 2012 Prioregroup.com. All rights reserved.
//
- (id)init {
if (self = [super init]) {
[self addObserverNotifications];
}
@priore
priore / gist:3128993
Created July 17, 2012 11:50
Copy object with property values
// Created by Danilo Priore on 02/04/12.
// Copyright (c) 2011 Prioregroup.com. All rights reserved.
//
// Copy object with property values
//
- (id)copy {
id copied = [[[self class] alloc] init];
unsigned int count = 0;
objc_property_t *properties = class_copyPropertyList([self class], &count);
@priore
priore / gist:7163408
Created October 25, 2013 23:32
ASP.NET [C#] Redirect with post data
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Text;
// ASP.NET [C#] REDIRECT WITH POST DATA
public static class WebExtensions
{
@priore
priore / gist:7163424
Created October 25, 2013 23:34
iOS SOAP client engine
/*
This generic SOAP client allows you to access web services using a your iOS app.
https://github.com/priore/SOAPEngine
With this Framework you can create iPhone and iPad Apps that supports SOAP Client Protocol. This framework able executes methods at remote web services with SOAP standard protocol.
** Features
* Support both 2001 (v1.1) and 2003 (v1.2) XML schema.
* Support array, array of structs and dictionary.
* Support user-defined object. Capable of serializing complex data types and array of complex data types, even multi-level embedded structs.
@priore
priore / gist:7163432
Created October 25, 2013 23:35
MD5 encode NSString
// MD5
#import <CommonCrypto/CommonDigest.h>
- (NSString*)getMD5WithString: (NSString*)str{
// Create pointer to the string as UTF8
const char *ptr = [str UTF8String];
// Create byte array of unsigned chars
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
// Create 16 byte MD5 hash value, store in buffer
@priore
priore / gist:7163444
Created October 25, 2013 23:36
Fix for Fecebook SDK when retrieving user permissions
// fix for Facebook SDK bug (from 3.0 to 3.7.1) https://developers.facebook.com/bugs/111727002307769
- (void)getUserDataPermissionsComplete:(void(^)(NSArray *permissions, NSError *error))completeBlock {
FBRequest *requestPermissions = [FBRequest requestWithGraphPath:@"me/permissions" parameters:Nil HTTPMethod:@"GET"];
[requestPermissions startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (completeBlock) {
NSMutableArray *permiss = [NSMutableArray array];
NSArray *data = [(NSDictionary*)result objectForKey:@"data"];
if (data && data.count > 0) {
NSDictionary *dict = [data objectAtIndex:0];
@priore
priore / gist:7163455
Created October 25, 2013 23:37
SHA1 encode NSString
// SHA1
#import <CommonCrypto/CommonDigest.h>
- (NSString*)getSHA1WithString:(NSString*)string
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, (CC_LONG)data.length, digest);
NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
@priore
priore / gist:7163463
Created October 25, 2013 23:37
How to create a perfect circle UIView
#import <QuartzCore/QuartzCore.h>
// create a perfect circle view
- (UIView*)createCircleViewWithRadius:(int)radius
{
// circle view
UIView *circle = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 2 * radius, 2 * radius)] autorelease];
circle.layer.cornerRadius = radius;
circle.layer.masksToBounds = YES;
@priore
priore / gist:7163469
Created October 25, 2013 23:38
How to retrieve the current displayed viewcontroller
//
// how to retrieve the current displayed viewcontroller
//
+ (UIViewController*)topMostController
{
UIViewController *topController = [[UIApplication sharedApplication] keyWindow].rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
@priore
priore / gist:7163478
Created October 25, 2013 23:39
How to put an image and a bottom text together in a UIButton
@implementation UIButton (Style)
const CGFloat kImageTopOffset = -15;
//const CGFloat kTextBottomOffset = -30;
- (void)centerButtonImageTopAndTextBottomWithOffset:(CGFloat)bottomOffset
{
[self setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -self.imageView.image.size.width, -bottomOffset, 0.0)];
[self setImageEdgeInsets:UIEdgeInsetsMake(kImageTopOffset, 0.0, 0.0, -self.titleLabel.bounds.size.width)];
}