Skip to content

Instantly share code, notes, and snippets.

View thelbouffi's full-sized avatar

Taha EL BOUFFI thelbouffi

View GitHub Profile
@thelbouffi
thelbouffi / rules-to-write-better-commit-messages.md
Created December 15, 2021 20:21 — forked from medhatdawoud/rules-to-write-better-commit-messages.md
This gist is the summary of a video on YouTube [in Arabic] you can watch from here: https://youtu.be/BTlL-LBDCSI

Rules to write a better commit message

These are my preferences for a good commit message, feel free to fork this gist and add your own standards, or add comment here to share yours with the community.

1. Include only the files related to the feature you are implementing:

  • Don't add any file that is not related to the main issue, you can make it in a separate commit.
  • Separating files that not related is important in the revert cases.
  • Revise the whole changes always before committing and make sure to mention each change you made in the message.

2. Commit subject should be concise and reflect the essence of the commit:

  • Imagine the commit as an Email to the owner or your team mates.
  • Subject in the first and main sentence of the commit, it should be concise and to the point.
  • It shouldn't exceed 50 char.
@thelbouffi
thelbouffi / 01_fibonacci_no_memo.js
Last active February 27, 2021 01:14
Memoization
// fibonacci function without memoization
function fib(n) {
if (n === 0) return 0;
if (n === 1) return 1;
return fib(n - 2) + fib(n - 1);
}
const start = Date.now();
console.log(fib(42));
console.log(`Time consumed ${Date.now() - start} ms`);

https://www.npmjs.com/package/npm-check-updates

to check packages => npm outdated
npm update will not always update all packages

solution => npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.

(for izmjs keep "path-to-regexp": "0.1.7")

@thelbouffi
thelbouffi / manage_vdi.txt
Last active July 5, 2019 12:05
virtualbox commands
to list vms:
vboxmanage list vms
to resize an existent vdi:
vboxmanage modifymedium disk 015319e5-4fbc-4437-83b0-cea42b2b21fe --resize 4096
as described on docs: https://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi
@thelbouffi
thelbouffi / 1_install_arch_linux.txt
Last active June 22, 2019 21:53
install arch linux
=======================================================
I- Partitionate the disk
fdisk -l
fdisk /dev/sda
* boot partition
n -> p -> enter -> enter (defines first sector for boot partition by default 2048) -> 1002048 sectors (defines last sector for boot partition)
a (toogle boot) -> t (type) -> ef (EFI)
* disk parttion
n -> p -> enter -> enter (fst sector) -> enter (last sector)
* to see parttion table
@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

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.

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"
@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

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