Skip to content

Instantly share code, notes, and snippets.

View andrewsardone's full-sized avatar

Andrew Sardone andrewsardone

View GitHub Profile
function createNewNutshellLead( $api ) {
$ns_contact_id = $this->setNutshellContactAndReturnID( $api );
$products = array();
$quote_price_ex_vat = ( $this->price + $this->getAdditionalProductsTotalPrice() );
$quote_product = array(
'qty'=>1,
@andrewsardone
andrewsardone / gist:3889904
Last active January 31, 2020 17:07
A quick cheat sheet for using CocoaPods

CocoaPods project setup

Create a Podfile at the root of your project

platform :ios, '5.0'

pod 'AFNetworking'
pod 'OHAttributedLabel'
// unpredictable backing type for this enum
typedef enum {
CDZTypePhone,
CDZTypeEmail
} CDZType;
// vs.
enum {
CDZTypePhone,
@andrewsardone
andrewsardone / ExampleTableViewDelegate.m
Created October 4, 2012 18:17
-[UITableViewDelegate tableView:heightForRowAtIndexPath:] calculation with n-number of side-by-side content views (like the textLabel and detailTextLabel)
// ...
#pragma mark UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *attributes = [NSMutableArray array];
id labelAttributes = @{
UITableViewCellNLHeightAttributeText: [self textLabelTextAtIndexPath:indexPath],
@andrewsardone
andrewsardone / gist:3751168
Created September 19, 2012 18:03
How does UIKit get pixels onto the screen?

UIView Drawing Model

-[UIView setNeedsDisplay]

You have some kind of custom UIView which implements some awesome drawing in -[UIView drawRect:]. In order to have UIKit draw it for you, you send the -[UIView setNeedsDisplay] to the view object to queue it up for drawing.

-[CALayer setNeedsDisplay]

     *------------*           *------------*

| | | |

@andrewsardone
andrewsardone / gist:3740504
Created September 17, 2012 23:58
CGRectDivide

CGRectDivide is handy for slicing up a rectangle.

Example of getting a slice and the remaining area of a rectange.

CGRect rect = CGRectMake(0, 0, 240, 150);
  
CGRect remainder, slice;
    
CGRectDivide(rect, &slice, &remainder, 120, CGRectMinYEdge);
@andrewsardone
andrewsardone / gist:3723354
Created September 14, 2012 17:24
NSKeyValueObserving's use of a context pointer for identifying interested observations

The NSKeyValueObserving addition to NSObject adds an observe message that takes an identifying context pointer – don't use NULL in its place.

Your superclass may observe the same key path for the same object. You need to pass along its observations, and only take actions on yours. The context pointer distinguishes which observations are yours.

static void *kContext = &kContext;
@andrewsardone
andrewsardone / gist:3701925
Created September 11, 2012 20:48
Necessary HIG-compliant tasks to perform in UIViewController subclass with a UITableView

To conform to Apple's human-interface guidelines, you need to implement the following tasks when subclassing UIViewController and including a UITableView in your hierarchy (hence recreating UITableViewController):

Clear any selection in the table view before it's displayed

In -[UIViewController viewWillAppear:], clear the selected row (if any) by sending the -[UITableView deselectRowAtIndexPath:animated:] message.

Flash scroll view's scroll indicators

In -[UIViewController viewDidAppear:], send the -[UITableView flashScrollIndicators] message.

@andrewsardone
andrewsardone / gist:3085222
Created July 10, 2012 18:08
A perfect example of listening to your tests, and appropriately abandoning ship (i.e., rethink that design)
#import <SenTestingKit/SenTestingKit.h>
#import "OCMock.h"
#import "SenTestCase+MethodSwizzling.h"
#import <objc/runtime.h>
#import "NLWelcomeViewController.h"
#import "NLWelcomeFlowGoogleViewController.h"
#pragma mark Setup
@andrewsardone
andrewsardone / gist:3020696
Created June 29, 2012 21:16
org.json.JSONObject halp
public void testJSONObjectEquality() throws Exception {
final JSONObject json1 = new JSONObject("{ \"foo\" : 1 }");
final JSONObject json2 = new JSONObject("{ \"foo\" : 1 }");
assertEquals(json1, json2);
}
// junit.framework.AssertionFailedError: expected:<{"foo":1}> but was:<{"foo":1}>