[Bash shell] Display the output with color

In bash shell, we have multiple ways to display the output, but do u know how to do this with color ?
Like this :
Image 8

It’s not so hard to do, the only thing we need to understand is  : ANSI escape code

An example of correspondence between the code and the color :

Black        0;30     Dark Gray     1;30
Red          0;31     Light Red     1;31
Green        0;32     Light Green   1;32
Brown/Orange 0;33     Yellow        1;33
Blue         0;34     Light Blue    1;34
Purple       0;35     Light Purple  1;35
Cyan         0;36     Light Cyan    1;36
Light Gray   0;37     White         1;37

The example in bash shell

#!/bin/bash

NC='\033[0m' 		# No color
RED='\033[0;31m'	# red
PURPLE='\033[0;35m'	# purple

printf "My ${PURPLE}name${NC} is ${RED}BO${NC} \n"

Do this in shell, and launch your script, you will get the same from the image in the beginning of this article.

[Linux command] Tar – Extract only the contents of an archived directory

 

As said the subject, we want to extract only the contents of a tar file to a specific folder.

I have my tar : myTarFolder.tar, my destination folder : destFolder

The structure of my tar file :

Image 10

If we use only the tar command, we will get :

tar -xf myTarFolder.tar -C destFolder 

Image 11

If we want to get something like this :

The option that we have to use is :

  1. –strip-components=NUMBER : strip NUMBER leading components from file names on extraction

An example of the command :

tar -xf myTarFolder.tar --strip-components=1 -C destFolder

The result :

Image 12

[Français] Correction des phrases

Grace à Eric que je puisse parler mieux le français.

 

Cela sera l’occasion pour qu’on retrouver un petit repas
=> Ce sera l’occasion de se retrouver pour un petit repas

Je serai plaisir de vous paie TOUS sauf l’entrée, le plate, le desserts ..
=> J’aurais le plaisir de vous inviter tous, sauf pour l’entrée, le plat et le dessert

Voici un petit sondage pour simplifier organisation
=> Voici un petit sondage pour simplifier l’organisation

[OpenShift] Deploy PHP/MySQL in OpenShift got 503 Service Temporarily Unavailable / 504 Gateway Time-out

Context :

The objective is to deploy the connection of MySQL with PHP in an OpenShift Server.
OpenShift is PaaS provided by Red Hat. For more info, read wikipedia OpenShift.

Problem :

The server returns :

503 Service Temporarily Unavailable

or

504 Gateway Time-out

Continue reading

[XMLHttpRequest] Cross-domain Ajax REST request + No ‘Access-Control-Allow-Origin’ header is present on the requested resource

Context :

In summary, this article is to record the solution for an “No ‘Access-Control-Allow-Origin’ header is present on the requested ressource” error.

My local domain is : localhost, in which based my local application

My request domain is : http://www.example.com, which is write in PHP, and will return a simple object in JSON
Such as : {"return":"OK"}

Continue reading