Thanks to dog.ceo and its API, you can display a random beautiful dog in a website. Just add the code below in your PHP:

<img style="width: 100%;" src="<?php
$my_json = "https://dog.ceo/api/breeds/image/random" ;
$my_content = file_get_contents($my_json);
$my_content_dec = json_decode($my_content);
$url_img = $my_content_dec->message ;
print $url_img;
?>" alt="Oh my dog!" title="Oh my dog!">

 To restrict the joke to your users (more polite), just enclose the code with this kind of PHP condition.

<?php if ($user->id != 0): ?>
   ...
<?php endif; ?>

 In Joomla a perfect spot to put it: templates/your_template/index.php, into the <div id="aside" class="span3">.

Please let me know if you find other APIs like it!

When you have to import files as text, csv, etc ... into an SQL database, non-desired line breaks (often from notes fields, text boxes,  <BR> tags, tabs, or other misinterpreted HTML ...) are very painful. It may fail your import, or be a waste of time. Exploring one's file with Notepad is sometimes necessary.

Complete 4-step correction

How to effectively manage these line breaks?

In this standard example, we want to identify and fix lines that do not start with a double quote (caused by line breaks) within a file where healthy lines start with a double quote.

Django REST API 2Here some tips about Django REST Framework (DRF) with Django 3.

Official website

Quick install

> pip install djangorestframework

Then in settings.py:

INSTALLED_APPS = [
    ...
    'rest_framework',
]

Let's go!

Liste de commandes non-exhaustive bien sûr, et surtout propre à mon usage personnel (sous Windows). Ce mémo est lié à l'article À la découverte de Django et GeoDjango.

Créer un projet Django (un site)

Sous Windows :

python -m django startproject mon_projet

Sous Linux :

django-admin startproject mon_projet

Sous Linux mais avec des versions anciennes, parfois :

django-admin.py startproject mon_projet

Créer une app Django (une fonctionnalité du site)

Placez-vous dans votre projet, changez le nom d'app souhaité, puis :

python manage.py startapp mon_appli

À chaque fois qu'il faut se placer dans le répertoire de votre projet Django, c'est pour utiliser le fichier manage.py, qui permet d'appeler Python directement à partir de votre projet personnel, pourtant situé hors de l'environnement virtuel.

Accès SSH en ligne :

https://ssh-hinot.alwaysdata.net/

Activer l'environnement virtuel

Après création d'un projet Django via l'administration Alwaysdata, un environnement virtuel est créé à la racine du projet, nommé env pour moi.

Pour l'activer, une fois dans votre projet (cd votre_projet).

source env/bin/activate

Fichiers statiques

Si vos fichiers statiques sont par exemple dans un répertoire nommé static à la racine de votre projet, ajoutez dans votre site Alwaysdata de type Python WSGI (dans l'administration Alwaysdata), dans l'option Static paths :

/static=static
Liste de commandes évidemment non-exhaustive, s'il est besoin de le préciser... Surtout propre à mon usage perso, attention dans vos manipulations.

Windows

Chercher une chaîne

Chercher dans un fichier

FIND /I "string to find" C:\way\to\find\*

Cherche ici, depuis n'importe où, la chaîne string to find dans les fichiers situés dans C:\way\to\find\*.

Mais parfois un problème d'accès refusé peut apparaître, bloquant la recherche récursive. Ceci malgré les droits d'administrateur ou vos tentatives de comprendre Windows... Dans ce cas utilisez ce script :

for /R %G in (*) do (find "string to find" %G)

Ou cette variante si les résultats sont peu lisibles, pour les sortir dans un fichier (faîtes ensuite une recherche de la chaîne dans le fichier) :

for /R %G in (*) do (find "string to find" %G) >> output.txt

Généralités Linux

Accorder tous les droits au contenu d'un répertoire

Une fois dans le répertoire en question :

chmod u+x *

Accorder les droits d'exécution à un fichier

chmod +x fichier.extension

Connaître la version de Centos

cat /etc/redhat-release

Connaître la binarité sous Centos

uname -a