Skip to content

Instantly share code, notes, and snippets.

View thelbouffi's full-sized avatar

Taha EL BOUFFI thelbouffi

View GitHub Profile
@thelbouffi
thelbouffi / firebase scheme.json
Created December 23, 2017 21:58 — forked from palaniraja/firebase scheme.json
Firebase - REST api calls - postman collection. - Firebase schema - https://www.flickr.com/gp/palaniraja-mca/32J3rA
{
"activites" : "activitiesTable",
"tasks" : {
"-KfbYYnJDdJ1IfQ4D6bl" : {
"firstname" : "palani",
"lastname" : "just lastname updated"
},
"-KfpLsLVH59MpKXDdYVm" : {
"firstname" : "palaniraja",
"lastname" : "raja"
@thelbouffi
thelbouffi / LICENSE
Created January 8, 2018 17:18 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@thelbouffi
thelbouffi / express_callback_next_calback.js
Last active February 13, 2018 17:06
express callback next callback (also how to protect a link for example /profile)
// in express we can pass a callback to another callback using next
// for example if we need to choose between two response (if condition is made res.send else res.send) to do that we need to pass next()
// callback to else in our middleware
// in the auth_middleware.js
let authenticated = false;
let requireLogin = (req, res, next) => {
if (!authenticated) {
res.send('not logged in'); // res.redirect('/login');
console.log('not logged');
@thelbouffi
thelbouffi / module_exports_Vs_exports.method.js
Last active February 14, 2018 17:22
module.exports Vs exports.method
// in exports_method.js
let add = (a, b) => a + b;
exports.add = add; // OR module.exports.add = add;
// in module_exports.js
let add = (a, b) => a + b;
module.exports = add;
// in caller.js
@thelbouffi
thelbouffi / undefined_console.js
Created February 21, 2018 16:39
Chrome or node.js displays “undefined” on the console
// The JavaScript functions always return something. If you don't specify something to return in the function then
// 'undefined' is returned by default
// So, console.log() will always return 'undefined' on node and chrome because the function doesn't return anything
let x;
let y = 3;
console.log(y);
// this console.log will return
// 3

Error codes returned by the Backend Services RESTful API:

Error Code HTTP Status Code Error Message Description Returned By
1 500 Unexpected error. All Represents an error that doesn't fall into any other category.
107 General database error. All A problem occurred while working with the database. The error message will contain more information about the error.
107 400 The operation results in a duplicate key for a unique index. Create You are trying to create an item with a field that requires a unique value (for example: "Id"). The error shows that an item with such value already exists.
107 400 Duplicate values already exist for field Number of content type "New". Update field You are trying to enforce a uniqueness constraint on the values of a field but the field already contains non-unique values.
201 409 A user with the same username already exists. Register user, Update user The name of the user account you are creating or updating already exists.
202 400 No
@thelbouffi
thelbouffi / after_res_hooks.js
Created April 13, 2018 00:36 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups

Git Author Identity

Set Committer Name & Email Globally

$ git config --global user.name "Taha El"
$ git config --global user.email "[email protected]"

Set Committer Name & Email per Repository

avoid using --global

$ git config user.name "Taha El"

source: http://toon.io/understanding-passportjs-authentication-flow/

Passport.js is a flexible authentication middleware (allowing users to log in) that can be fully customised and works great with connect/express.

It is flexible in the sense that it allows for different authentication strategies (think via Twitter, via our own user database - installed via separate modules that can be combined) and it allows us to specify any route or output during authentication.

DIFFERENT PARTS IN USING PASSPORT.JS

There are three main parts in using passport.js:

  • Requiring the module and using its passport.initialize() and passport.session() middleware with express.
  • Configuring passport with at least one Strategy and setting up passport's serializeUser and deserializeUser methods.
@thelbouffi
thelbouffi / description.md
Last active April 21, 2019 21:14
debug node app on vscode

Debug node

  • if we choose this config we will only need to run the debugger, it will be automatically attached to the app

Attach by Process ID

  • when we want to choose this config
  • we will need in first place to run the app with --inspect: node --inspect app.js or node --inspect .
  • then we will attach the debugger to it by choosing the option with --inspect

Attach to nodemon

  • this type of config is great for nodemon, because it help debugger attached to always to the same process via the same port