This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This one I use very often | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| // run following code in main queue | |
| // this block will be put in the queue to be executed later | |
| }); | |
| dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| // do some task in background | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| // update some UI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @interface Box:NSObject | |
| { | |
| //Instance variables | |
| double length; // Length of a box | |
| double breadth; // Breadth of a box | |
| } | |
| @property(nonatomic, readwrite) double height; // Property | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #if DEBUG == 0 | |
| #define DBLog(...) | |
| #elif DEBUG == 1 | |
| #define DBLog(...) NSLog(__VA_ARGS__) | |
| #endif | |
| int main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(NSString *) someMethod:(int) id withError:(NSError **)errorPtr{ | |
| if(id == 1) | |
| { | |
| return @"Execution of some code..."; | |
| } | |
| else | |
| { | |
| NSString *domain = @"com.MyCompany.MyApplication.ErrorDomain"; | |
| NSString *desc =@"Unable to complete the process"; | |
| NSDictionary *userInfo = [[NSDictionary alloc] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NSString+MyAddition.h | |
| @interface NSString(MyAdditions) | |
| - (NSString *) getCopyRightString; | |
| @end | |
| @implementation NSString(MyAdditions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // in some class.h | |
| @protocol ProtocolName | |
| @required | |
| // list of required methods | |
| @optional | |
| // list of optional methods | |
| @end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <wiringPi.h> | |
| #define LED 4 | |
| #define PIR 5 | |
| int main() { | |
| // doe een setup om wiringPi te gebruiken | |
| if(wiringPiSetup()<0) { | |
| printf("Error setting up wiringPi..."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <signal.h> | |
| #include <stdio.h> | |
| #include <wiringPi.h> | |
| #define LED 4 | |
| #define PIR 5 | |
| volatile char isRunning = 1; | |
| void processMotionDetection(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * promise object | |
| * Explanation: When creating a promise object, it is supposed to be in a pending state. | |
| * If a certain process succeeded, we call resolve() callback and it is assumed resolved, | |
| * also called fulfilled. Meaning, you fulfilled your promise :) | |
| * If the process failed, than the promise is rejected. | |
| */ | |
| let promise = new Promise((resolve, reject) => { | |
| // We're now in a pending state | |
| User.find({}, (user, err) => { // <-- this an async work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * promise object | |
| */ | |
| function getUserWithId(id) { | |
| return new Promise((resolve, reject) => { | |
| // Look for a user with id in the database | |
| User.find({_id: id}, (user, err) => { | |
| if(err) return reject(err); |