Skip to content

Instantly share code, notes, and snippets.

View wess's full-sized avatar
💭
When am I not writing code?

Wess Cope wess

💭
When am I not writing code?
View GitHub Profile
@wess
wess / gist:3494099
Created August 28, 2012 01:29
JSON FOR F'ING BROWNIES.
NSURL *url = [NSURL URLWithString:@"http://rigmonkeyapp.com/wp-admin/admin-ajax.php?action=wpp_export_properties&api=343cae213812a8662431a29c5e6ddcc20154219b&format=json&limit=5"];
NSURLRequest *request = [NSURLRequest requestWithURL:articleURL];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
@wess
wess / gist:3783564
Created September 25, 2012 18:25
Get a little better stacktrace in Objective-C
int main(int argc, char *argv[])
{
@autoreleasepool
{
int retVal;
@try
{
retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([YOUR_DELEGATE class]));
}
@catch (NSException *exception)
@wess
wess / gist:3802994
Created September 29, 2012 02:52
objc shit
@protocol ClassADelegate;
@interface ClassA : NSObject
@property (strong, nonatomic) id<ClassADelegate>delegate;
- (void)letShitHappen;
@end
@protocol ClassADelegate <NSObject>
- (void)doSomeShit;
@wess
wess / gist:3894907
Created October 15, 2012 19:56
Survey example form file
// BJSignupForm.h
// Bizjournals
//
// Created by Wess Cope on 10/15/12.
// Copyright (c) 2012 ACBJ. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Survey/Survey.h>
#ifndef __WC__MACROS__
#define __WC__MACROS__
#define AND &&
#define OR ||
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#ifndef __WC__MACROS__
#define __WC__MACROS__
#define AND &&
#define OR ||
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#define APP_EXECUTABLE [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]
#define APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
@wess
wess / gist:4228027
Created December 6, 2012 20:26
parsing HTML
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:string attributes:self.attributes];
TFHpple *doc = [[TFHpple alloc] initWithHTMLData:[[string lowercaseString] dataUsingEncoding:NSUTF8StringEncoding]];
NSArray *elements = [doc searchWithXPathQuery:@"//b | //strong | //em | //i"];
[elements enumerateObjectsUsingBlock:^(TFHppleElement *element, NSUInteger idx, BOOL *stop) {
NSString *tagName = [element.tagName lowercaseString];
if([tagName isEqualToString:@"b"] || [tagName isEqualToString:@"strong"])
{
NSRange boldRange = [string rangeOfString:element.text];
@wess
wess / gist:4236368
Created December 7, 2012 20:46
Link detection/getting in coretext based view
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
NSString *link = [attrString urlStringForTextAtPoint:location];
if(link)
NSLog(@"LINK: %@", link);
}
@wess
wess / gist:4236518
Created December 7, 2012 21:04
Wilde Readme

Wilde

Wilde, named after the author Oscar Wilde, is a helper class that eases the pain of creating and drawing attributed strings.

Getting started:

  • First grab the Wilde repository: git submodule add git://github.com:wess/Wilde.git

  • The grab Wilde's submodules: git submodule update --init --recursive

@interface MyTableController : UITableViewController
@end
@interface MyTableController()
@property (strong, nonatomic) NSArray *myArray;
@end
@implementation
- (void)viewDidLoad
{