Skip to content

Instantly share code, notes, and snippets.

View bouchtaoui-dev's full-sized avatar

Nordin-010 bouchtaoui-dev

  • Netherlands, Rotterdam
View GitHub Profile
/**
* 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);
@bouchtaoui-dev
bouchtaoui-dev / promise_example2.js
Created January 15, 2019 13:15
Here we're chaining multiple promises, which solves the callback hell.
/**
* This function returns a promise to fetch a user by id
*/
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);
// on success
/**
* 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);
@bouchtaoui-dev
bouchtaoui-dev / promise.js
Last active January 15, 2019 12:35
Simple example of a Promise pattern
/**
* 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
@bouchtaoui-dev
bouchtaoui-dev / motion.c
Created November 5, 2018 19:38
Voorbeeld code van een bewegingsdetectie voor demonstratie van Home Automation met de Raspberry Pi
#include <signal.h>
#include <stdio.h>
#include <wiringPi.h>
#define LED 4
#define PIR 5
volatile char isRunning = 1;
void processMotionDetection();
#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...");
// in some class.h
@protocol ProtocolName
@required
// list of required methods
@optional
// list of optional methods
@end
// NSString+MyAddition.h
@interface NSString(MyAdditions)
- (NSString *) getCopyRightString;
@end
@implementation NSString(MyAdditions)
-(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]
#import <Foundation/Foundation.h>
#if DEBUG == 0
#define DBLog(...)
#elif DEBUG == 1
#define DBLog(...) NSLog(__VA_ARGS__)
#endif
int main()