Skip to content

Instantly share code, notes, and snippets.

@emarashliev
emarashliev / main.m
Created January 17, 2014 16:57
CFNotificationCenter usage examples
#include <CoreFoundation/CoreFoundation.h>
void notificationCallback (CFNotificationCenterRef center,
void * observer,
CFStringRef name,
const void * object,
CFDictionaryRef userInfo)
{
CFShow(CFSTR("Received notification (dictionary):"));
// print out user info
@emarashliev
emarashliev / A+EatApple.m
Last active January 1, 2016 17:59
Override Methods with Categories
#import "A.h"
#import <objc/runtime.h>
@implementation A (EatApple)
- (void)printAppleOverride
{
[self printAppleOverride];
NSLog(@"Eat that Apple");
}
rm -rf `ls /tmp | grep something`
@emarashliev
emarashliev / Singleton
Created November 5, 2013 12:49
Objective-c Singleton
@implementation Singleton
static id _sharedManager;
+ (instancetype)sharedManager
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});
@emarashliev
emarashliev / gist:6699636
Created September 25, 2013 13:31
Rocket code
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *resources = [[NSMutableArray alloc] init];
NSURL *URL = [NSURL URLWithString:@"http://localhost:8080"];
AFHTTPClient *manager = [[AFHTTPClient alloc] initWithBaseURL:URL];
[manager GET:@"/messages" parameters:nil success:^(NSHTTPURLResponse *response, id responseObject) {
[resources addObjectsFromArray:responseObject[@"resources"]];
@emarashliev
emarashliev / gist:6010845
Last active December 19, 2015 20:08
Get the class of calling object
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
Class callerClass = NSClassFromString([array objectAtIndex:3]);
@emarashliev
emarashliev / gist:5561872
Created May 12, 2013 00:05
Explanation isEqual: and == comparison for the Objective-C mutable and immutable objects
// Set non ARC flag (-fno-objc-arc) for the execution file
// http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project
//
//
NSMutableArray *mutableArrayOrginal = [NSMutableArray arrayWithObjects:@"asdasd", nil];
NSLog(@"mutableArrayOrginal address is: %p", mutableArrayOrginal);
NSMutableArray *mutableArrayCopy = [mutableArrayOrginal copy];
NSLog(@"mutableArrayCopy address is: %p", mutableArrayCopy);
if ([mutableArrayOrginal isEqual:mutableArrayCopy]) {
- (void)copyItems:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSMutableArray *items = [NSMutableArray arrayWithCapacity:_selectionView.selection.count];
for (TTShapeModelObject *shp in _selectionView.selection) {
[item setObject:[NSKeyedArchiver archivedDataWithRootObject:shp] forKey:@"TTShapeModelObject"];
[items addObject:item];
}
pasteboard.items = items;
class Offer < ActiveRecord::Base
belongs_to :offer_type
belongs_to :offer_rate
belongs_to :city
belongs_to :location
...
end