Nicolas BAPTISTA - Page 4 of 5 - Blog of a Parisian software architect

This blog contains 47 articles

N I C O L A S    B A P T I S T A

PERSONNAL BLOG

SOFTWARE ARCHITECT • JAVASCRIPT DEVELOPER • DESIGNER


LinkedIn Contact Github More...


Install MariaDB on a Fedora/CentOS/RedHat server

If you have your own server, the first thing you may want to do with your backend shoud be to install a database server on it.

Here is step by step how to install a MySQL/MariaDB (almost the same) database on your server:
Install the MariaDB service:

yum install mariadb mariadb-server

Create your user access – change the username and password you want:

mysql
CREATE USER username@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' ;
flush privileges;

Verify the user has been created:

SELECT User FROM mysql.user;

You should be able to login on your database from you app and remotely.

Créer une Cloud Function sur Google Cloud

Bonjour,


Si vous avez réalisé une application minimaliste, il se peut que vous n’ayez pas forcément besoin d’une machine pour faire tourner votre API. Dans ce cas, si vous avez besoin d’une route sans avoir à gérer l’identification par exemple, les Cloud Functions peuvent suffire. Ils se trouvent dans la section Calcul:

Créez votre fonction:

Nommez votre fonction, puisque c’est un GET depuis votre appli, je vous conseille de commence par l’appeler get, par exemple si on retourne la liste des voitures, ce sera “getVoiture”. Ce sera un déclencheur HTTP :

Je conseille d’exiger le protocole HTTPS pour des raisons évidentes de sécurité. Vous pouvez commenter la première ligne. Vous pouvez ensuite faire votre liste de voitures au format JSON.

Vous pouvez ensuite tester la fonction depuis l’onglet TEST ou alors en allant directement dans l’URL du déclencheur dans l’onglet DECLENCHEUR :

Vérifier l’authenticité d’un diplôme d’un candidat

Bonjour à tous,

Etant donné que nous sommes en “Vive la France, Vive la République” le pays de Molière et de Baudelaire, l’état nous a mis à disposition une magnifique plateforme de vérification des diplômes accessible depuis https://diplome.gouv.fr/ si vous voulez vérifier les premiers diplômes d’un candidat à savoir son baccalauréat ou quelques diplômes comme le BTS, vu que j’ai fait un BTS avant de me diriger vers une license puis un Master:

Ainsi, pas de doutes, Jean Michel est bien diplômé. Attention cependant à bien vérifier l’académie et l’année pour trouver vos diplômes, car si vous avez été dans plusieurs départements, ce ne sera sans doute pas la même académie. Par exemple, en région Ile-de-France, vous avez 3 académies: Créteil, Paris, Versailles. Me concernant j’ai dû aller chercher dans celles de Créteil puis celle de Paris.

Analyze the trading market with MarketWatcher

I am very happy to annonce you that I have finally published Market Watcher, a Metatrader 4 indicator that I’ve made and been using several years on different brokers. This indicator allows you to see in few seconds the most important characteristics of each pairs (FOREX, CFD, Index or Crypto) of a Metatrader 4 broker, such:

Spread ( How much you lose when you open an order )

Ticks to Zero ( How much ticks for the spread )

Tick Value ( The value of each tick/pips )

ATR ( Average True Range, to determine the volatility )

Lot Min-Max ( The minimum and maximum lots allowed to trade on the pair )

This is a good way to know easily and very fast if a broker is interesting, whatever if you are using a demo or real account on your broker.
You can see additionally the order, in GREEN the best values and the others in RED.
On the right side, there is a calculated list of the best pairs that you should trade.

MarketWatcher 1.4 on Metatrader 4

Do not hesitate to contact me if you have any question how to use it.

Solving errors of publishing an app on Google Play – Cordova / Ionic

INVALID APP VERSION :versionCode OR versionName

You should have a look on the following files:
platforms\android\AndroidManifest.xml
You will find the tag “android:versionCode” and ” android:versionName”.
config.xml
You will find the tag “android-versionCode” and ” version”.

Don’t forget to change this file and not only the AndroidManifest.xml because if you are using the Ionic Cordova command to build, this one:

ionic cordova build android --prod --release

It will takes the version from config.xml and should regenerate AndroidManifest.xml.

INVALID ANDROID SDK VERSION

• Open Android Studio
• Download the latest version of the Android SDK, by going File > Project Settings :

The latest API level is 30

• Set the latest API level on File > Project Structure :

CentOS : Fix ” HTTPS Error 404 – Not Found ” with YUM

If you want to install a package on CentOS with YUM is it possible that you might have the following error

Total download size: 20 M
Installed size: 60 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
PACKAGE.x86 FAILED                                          
https://rpm.nodesource.com/pub_15.x/el/7/x86_64/PACKAGE.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

Error downloading packages:
  2:PACKAGE.x86_64: [Errno 256] No more mirrors to try.

To solve this problem we should reset the sources used by YUM, the package manager of CentOS. To do so, you should use the following command:

yum clean all

It should clean the sources of the repos. You should now be able to install the packages you want with yum i <package>

Host multiple frontend React/Angular app on one NGINX server

Is it possible that you have multiple web applications React.JS or Angular and you want it to be on one unique machine

You will have to check your NGINX configuration file /etc/nginx/nginx.conf or /etc/nginx/conf.d/ssl.conf – on CentOS/Fedora/RedHat.

ON THE SAME DOMAIN

One app will run on domain.com and the other app will run on domain.com/app2 :

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name DOMAIN.COM;
    #ssl_certificate /etc/letsencrypt/live/DOMAIN.COM/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/DOMAIN.COM/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    
    # FIRST WEB APP - runs on https://DOMAIN.COM
    root /usr/share/nginx/firstapp/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;

    # SECOND WEB APP - runs on https://DOMAIN.COM/app2
    location /app2 {
      autoindex on;
      index index.html;

      alias /usr/share/nginx/app2/build/;

      try_files $uri $uri/ /index.html;
    }
}

ON DIFFENTS DOMAINS

One app will run on app1.domain.com and the other app will run on app2.domain.com :

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name app1.domain.com;
    #ssl_certificate /etc/letsencrypt/live/app1.domain.com/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/app1.domain.com/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    root /usr/share/nginx/app1/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
}
server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name app2.domain.com;
    ssl_certificate /etc/letsencrypt/live/app2.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/app2.domain.com/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    root /usr/share/nginx/app2/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
}

403 Forbidden / 404 Not authorized

In case of error, you will have to check your logs:

sudo tail -n 20 /var/log/nginx/error.log

Google Cloud SQL : SUPER privilege error while importing

When importing SQL file on Google Cloud (MySQL 5.7), I faced the following error:

exit status 1 ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER privilege(s) for this operation  

You can see the error when go in “Operation”, you can see the logs of the MySQL instance

In order to solve this problem, you should understand that we do not have SUPER privileges on the Google Cloud SQL instance, it means if you do “SHOW GRANTS” on your MySQL, it will tell you that you have almost all the rights but not all.

This problem happen when you try to import some specific things such triggers, views, … so you should be careful on the SQL export when you do it.
As for me, I’m using MySQL Workbench 8.0, it seems that by default I have this error when I try to import the SQL file generated on Google Cloud.
I tried to import an export from Google Cloud to another instance and seems to work, so the problem is when you export the SQL file it should not contains things that needs specific privileges.
I found a configuration that worked for me and now I don’t have this annoying error anymore. Great !
Here is the options I have used. First, when you export, go to Advanced Options…


Then you should check the following options:

Now you can try to import the SQL file on Google Cloud, it should works ! F*ck yeah!

Compare different branches with GitLens

Is it possible that in your working project, you are using different branch that you need to update and you cannot merge in master because of some obligations (working with different clients, different teams, …). So what we want is only to update few files when we modify it on another branch.

I find out an amazing tool GitLens to compare different branches from your git project directly from the IDE (using Visual Studio Code).

You can find it in the Marketplace here is what it looks like:

After you have installed it, you will have a new tab on Visual Studio Code, in this tab you will be able to see 5 tools:

  • Repositories : See on which repositories and branch you are working on
  • Files History : visualize navigate and explore the revision history of current file
  • Line History : visualize navigate and explore the history of the selected lines of current file
  • Compare Commits : to visualize comparisons between branches, tags, commits, and more, THIS is the most interesting tool that we are going to use
  • Search Commits : to search and explore commit histories

With the Compare Commits tool we can click Compare <branch, tag, or ref> and be able to compare 2 branch:

VinceOPS | Git : Astuces et productivité #2

If you click on a commit or a file, you will be in read only mode. To modify your file side by side you will have to click on a button.
This button is Compare with HEAD here is where is it located:

You can now compare and modify the file side by side, what you cannot do with Visual Studio in a single branch.

Commandes GIT sur serveur en production

Les commandes suivantes peuvent être utilisé sur un serveur en production.
Dans le cas d’un déveleppement sur machine locale, utiliser des logiciels gratuits comme GIT DESKTOP / SourceTree.

Voici les deux commandes utilisés au quotidien:

Premier déploiement dans un dossier

git clone <URL GITLAB/GITHUB HTTPS>

Mise à jour / Récupération des derniers changements

git pull

Les commandes suivantes répondent à des problematiques particulières qui peuvent arriver.

Changement de l’URL du repository GIT

Ce problème peut intervenir notamment si vous utilisez GITLAB ou GITHUB en SSH et que vous voulez passer en HTTPS ou vis versa, ou suite à des problèmes de droits d’une clé SSH type “remote: The project you were looking for could not be found.” et “fatal: Could not read from remote repository.”

Vérification de l’URL du repository:

git remote -v

Changement de cet URL:

git remote set-url origin <URL>

Changement de branche

git checkout <nom_de_la_branche>

Le git pull ne fonctionne pas “You have unstaged changes”

Il se peut que vous ayez l’erreur suivante, indiquant que des fichiers ont changés et doivent être commit alors que vous n’avez rien touché et que vous souhaitez juste mettre le serveur à jour :

Cannot pull with rebase: You have unstaged changes. 
Please commit or stash them. 

Dans ce cas, on doit supprimer ces changements avec la commande suivante :

git reset --hard

Vous pouvez ensuite faire votre git pull

Revenir au commit précédent

git reset --hard HEAD^

Revenir à un commit précis

git reset --hard <ID COMMIT>

L’ID du commit est générallement à 7 chiffres et lettres hexadecimal, exemple:
26b47fa

Vous pouvez le trouver dans l’onglet historique de votre GIT DESKTOP

Ecraser les modifications sur le repository distant (local > remote)

git push --force origin master

Attention, écrase le répository distant, utile si vous voulez “supprimer” un commit qui a été pushé.

Ecraser les modifications sur le repository local (remote > local)

git reset --hard origin/master

Attention, supprime toutes les modifications faites non pushé vers le git distant, utile si vous voulez “supprimer” les commits en local pour avoir la même chose que sur le git distant.