Skip to content

Instantly share code, notes, and snippets.

View thelbouffi's full-sized avatar

Taha EL BOUFFI thelbouffi

View GitHub Profile
@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
@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 / 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 / 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 / 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"
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@thelbouffi
thelbouffi / npm-cheat-sheet.md
Created November 9, 2017 22:05 — forked from AvnerCohen/npm-cheat-sheet.md
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

##List of less common (however useful) NPM commands

######Prepand ./bin to your $PATH Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

@thelbouffi
thelbouffi / Typings in Typscript
Last active May 12, 2022 11:28
What are Typings in Typescript?
JavaScript is untyped, meaning that we can pass around data and objects as we want.
We can write code that calls methods that don't exist on an object, or variables that we don't have.
These problems are hard to discover when you are writing code and it can lead to unstable code,
and doing big changes of your code can become very difficult and risky as you don't immediately see if your changes
conflicts with the rest of the code.
TypeScript is mainly about adding types to JavaScript. That means that TypeScript requires you to accurately
describe the format of your objects and your data. When you do that, that means that the compiler can investigate
your code and discover errors. It can see that you are trying to call a function that does not exist or use a variable
that is not accessible in the current scope.
var vehicle = function(ty) {
this.type=ty;
}
vehicle.prototype.ride = function() {
console.log('I am riding a ', this.type);
}
var newRebuild = function(constructor){
var obj = {};
Object.setPrototypeOf(obj, constructor.prototype);
var arArgs = Array.from(arguments).slice(1);
@thelbouffi
thelbouffi / Mongodb_ubuntu_15.10.md
Last active October 18, 2016 13:54
Installation and configuration of mongodb in ubuntu 15.10

Install mongodb
sudo apt-get install mongodb

Acess mongodb.service and insert the configuration code
cd /lib/systemd/system
sudo vim mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)