Compare commits
7 Commits
5d223655fc
...
719e4b2780
Author | SHA1 | Date | |
---|---|---|---|
719e4b2780
|
|||
9feeed82e5
|
|||
d410b35b37
|
|||
e8c7b3d1e7
|
|||
1513d0cc9a
|
|||
df0ef69452
|
|||
324da3208b
|
@@ -1,6 +1,6 @@
|
||||
:PROPERTIES:
|
||||
:ID: ca50d517-3e8a-4d03-ba38-7ff411e87408
|
||||
:mtime: 20220910133708
|
||||
:mtime: 20220928120750
|
||||
:ctime: 20211230101331
|
||||
:END:
|
||||
#+title: Software
|
||||
@@ -18,6 +18,9 @@ Il est nécessaire que le language mis en oeuvre permette l'interception d'erreu
|
||||
* Design pattern
|
||||
TODO
|
||||
|
||||
* Classement/tri de données
|
||||
** [[id:6af01039-a0a9-46fc-abe8-82f9662bc4b7][heap sort algorithm]]
|
||||
|
||||
* Langages
|
||||
** Compilés
|
||||
*** [[id:ed8be72a-8a4d-4ef7-92e4-78d07095deaf][C++]]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
:PROPERTIES:
|
||||
:ID: 171ce2f7-4028-47b0-b4e0-5a4a6ccb74ac
|
||||
:mtime: 20220527114623
|
||||
:mtime: 20221229103915
|
||||
:ctime: 20220104155310
|
||||
:END:
|
||||
#+title: Postgres
|
||||
@@ -12,7 +12,11 @@
|
||||
* Fonctionne sur Solaris, SunOS, Mac OS X, HP-UX, AIX, Linux, IRIX, Digital Unix, BSD, NetBSD, FreeBSD, OpenBSD, SCO unix, NeXTSTEP, UnixWare et toutes sortes d'Unix. Depuis la version 8.0, PostgreSQL fonctionne également nativement sur Windows.
|
||||
|
||||
* Interfaces utilisateur
|
||||
** [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]]
|
||||
** CLI
|
||||
* [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]]
|
||||
** Graphique
|
||||
* [[https://arctype.com/][ArcType]]
|
||||
* [[https://github.com/dbeaver/dbeaver][DBeaver]]
|
||||
|
||||
* Howto
|
||||
** Pour lister les utilisateurs
|
||||
@@ -33,5 +37,55 @@ sudo -u postgres dropdb <database>
|
||||
\password <user>
|
||||
#+END_SRC
|
||||
|
||||
* Profiling de requêtes (query plan)
|
||||
** Depuis [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]]
|
||||
#+BEGIN_SRC sql
|
||||
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS) SELECT _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id AS id_1, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts, stop_areas.id AS id_2, stop_areas.type
|
||||
FROM _stops LEFT OUTER JOIN stops ON _stops.id = stops.id LEFT OUTER JOIN stop_areas ON _stops.id = stop_areas.id
|
||||
WHERE _stops.name ILIKE '%Chaville rive droite%'
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC
|
||||
Nested Loop Left Join (cost=148.62..250.06 rows=5 width=194) (actual time=1.213..1.346 rows=12 loops=1)
|
||||
Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts, stop_areas.id, stop_areas.type
|
||||
Inner Unique: true
|
||||
Buffers: shared hit=123
|
||||
-> Nested Loop Left Join (cost=148.33..208.53 rows=5 width=182) (actual time=1.196..1.296 rows=12 loops=1)
|
||||
Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts
|
||||
Inner Unique: true
|
||||
Buffers: shared hit=97
|
||||
-> Bitmap Heap Scan on public._stops (cost=148.04..166.99 rows=5 width=93) (actual time=1.172..1.219 rows=12 loops=1)
|
||||
Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts
|
||||
Recheck Cond: ((_stops.name)::text ~~* '%Chaville rive droite%'::text)
|
||||
Heap Blocks: exact=11
|
||||
Buffers: shared hit=63
|
||||
-> Bitmap Index Scan on name_idx_gin (cost=0.00..148.04 rows=5 width=0) (actual time=1.155..1.155 rows=12 loops=1)
|
||||
Index Cond: ((_stops.name)::text ~~* '%Chaville rive droite%'::text)
|
||||
Buffers: shared hit=52
|
||||
-> Index Scan using stops_pkey on public.stops (cost=0.29..8.31 rows=1 width=89) (actual time=0.005..0.005 rows=1 loops=12)
|
||||
Output: stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts
|
||||
Index Cond: (stops.id = _stops.id)
|
||||
Buffers: shared hit=34
|
||||
-> Index Scan using stop_areas_pkey on public.stop_areas (cost=0.29..8.30 rows=1 width=12) (actual time=0.003..0.003 rows=0 loops=12)
|
||||
Output: stop_areas.id, stop_areas.type
|
||||
Index Cond: (stop_areas.id = _stops.id)
|
||||
Buffers: shared hit=26
|
||||
Planning:
|
||||
Buffers: shared hit=22
|
||||
Planning Time: 1.015 ms
|
||||
Execution Time: 1.521 ms
|
||||
(28 rows)
|
||||
|
||||
Time: 3.503 ms
|
||||
#+END_SRC
|
||||
|
||||
** Visualisation de Query plan
|
||||
Différents sites permettent de visualiser graphiquement les query plans:
|
||||
* Gratuits:
|
||||
* [[https://explain.dalibo.com/][PEV2 - Dalibo]]
|
||||
* Payants:
|
||||
* [[https://app.pgmustard.com/login][PgMustard]]
|
||||
|
||||
* Références
|
||||
* [[https://stackoverflow.com/questions/45395538/postgres-md5-password-plain-password][Postgres: MD5 Password / Plain password - Github]]
|
||||
* [[https://www.postgresql.org/docs/current/sql-explain.html][Sql-explain - PostgreSQL]]
|
||||
|
@@ -1,12 +1,12 @@
|
||||
:PROPERTIES:
|
||||
:ID: 0455921f-3ac0-437e-ba76-1afb3f6f85ea
|
||||
:mtime: 20220104160506
|
||||
:mtime: 20221229101120
|
||||
:ctime: 20220104155517
|
||||
:END:
|
||||
#+title: Psql
|
||||
#+filetags: :postgre:database:
|
||||
|
||||
Interface en ligne de commande permettant la saisie de requêtes SQL, directement ou par l'utilisation de procédures
|
||||
Interface en ligne de commande permettant la saisie de requêtes PostgreSQL, directement ou par l'utilisation de procédures
|
||||
stockées.
|
||||
|
||||
* Commandes
|
||||
|
@@ -1,6 +1,6 @@
|
||||
:PROPERTIES:
|
||||
:ID: 5943c76c-8b25-4cbd-b0b9-c819e5a490ba
|
||||
:mtime: 20220305154620
|
||||
:mtime: 20220927121655
|
||||
:ctime: 20220130140137
|
||||
:END:
|
||||
#+title: cyber
|
||||
@@ -20,6 +20,10 @@
|
||||
** Linux: [[id:262f233d-9ae9-4bd7-a8e9-cba392a2c1f6][AIDE]]
|
||||
|
||||
* Serveur
|
||||
** "Tarpit"
|
||||
*** [[id:1ed652bc-bdcc-4410-a207-fb470df29e71][endlessh]]
|
||||
** Anti-DoS
|
||||
*** [[id:00b1b480-0f0c-42a3-8952-4275bc10bc00][fail2ban]]
|
||||
** Tips
|
||||
*** [[id:9eedbc4b-a961-4057-b2d8-8f10845f0478][Vérification des cyphers suites acceptées par un serveur]]
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
:PROPERTIES:
|
||||
:ID: e93719b3-088d-4fe7-9ef8-fc9a4fd84827
|
||||
:mtime: 20220524205131
|
||||
:mtime: 20221229111938
|
||||
:ctime: 20220501191904
|
||||
:END:
|
||||
#+title: Git
|
||||
@@ -74,8 +74,32 @@ Pour créer une branche afin que celle-ci suive une distante :
|
||||
pull~,
|
||||
* La branche existe déjà : ~git branch -u <branche_distante> <branche_locale>~
|
||||
|
||||
** Correction
|
||||
Pour supprimer un fichier du dernier commit non /pushed/ : ~git reset --soft HEAD <filename>~.
|
||||
Pour commiter la correction d'un précédent /commit/ :
|
||||
#+BEGIN_SRC shell
|
||||
git commit --fixup <hash_commit_à_corriger>
|
||||
git rebase -i --autosquash
|
||||
#+END_SRC
|
||||
|
||||
** Comparaison
|
||||
Pour comparer deux branches : ~git diff <branche_a>..<branche_b>~.
|
||||
Pour comparer un fichier ou un répertoire entre deux branches : ~git diff <branche_a>..<branche_b> -- <path>~.
|
||||
Ajouter l'option ~-w~ à /git diff/ pour ignorer les espaces.
|
||||
|
||||
** Logs
|
||||
Pour afficher l'historique d'une fonction ou d'un fichier : ~git log -L:<class_name>:<filename>~
|
||||
Pour afficher les dernières positions de /HEAD/ : ~git reflog~.
|
||||
|
||||
* Outils tiers
|
||||
** Visualisation
|
||||
** Visualisation de dépôts
|
||||
*** [[https://github.com/rgburke/grv/][grv]]
|
||||
Visualisation de dépôts git depuis un terminal.
|
||||
*** [[https://github.com/o2sh/onefetch][onefetch]]
|
||||
Informations du dépôt courant au lancement d'un terminal.
|
||||
*** [[https://github.com/git-up/GitUp][GitUp]]
|
||||
Application de visualisation de dépôts pour MacOS.
|
||||
** Visualisation de différences
|
||||
*** [[https://github.com/dandavison/delta][Delta]]
|
||||
Affichage de ~git diff~.
|
||||
*** [[https://github.com/darrenburns/dunk][Dunk]]
|
||||
@@ -88,4 +112,6 @@ Jeu en ligne de commande permettant d'apprendre l'usage de Git.
|
||||
Site permettant l'apprentissage de l'usage de Git.
|
||||
|
||||
* Références
|
||||
*
|
||||
* [[https://martinheinz.dev/blog/43][Advanced Git features you didn't know You needed - Martin Heinz]]
|
||||
* [[https://medium.com/@porteneuve/getting-solid-at-git-rebase-vs-merge-4fa1a48c53aa][Getting solid at Git rebase vs. merge - Christophe Porteneuve]]
|
||||
* [[https://medium.com/@porteneuve/mastering-git-reset-commit-alchemy-ba3a83bdfddc][Mastering Git Reset: Commit Alchemy - Christophe Porteneuve]]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
:PROPERTIES:
|
||||
:ID: 47707ab9-7792-4592-b25b-8dd2f2e45b05
|
||||
:mtime: 20220604101605
|
||||
:mtime: 20221229104128
|
||||
:ctime: 20220526082057
|
||||
:END:
|
||||
#+title: Self-hosted server
|
||||
@@ -29,3 +29,9 @@ certbot certonly --nginx --force-renew -d imap.adrien.run
|
||||
* Vidéo
|
||||
** Plateforme de streaming
|
||||
*** [[https://github.com/Chocobozzz/PeerTube][PeerTube]]
|
||||
|
||||
* Rendez-vous (remplacement de Doodle)
|
||||
** [[id:8bb29bf5-219f-49ff-b410-e7cc2473337f][framadate]]
|
||||
|
||||
* Microblogging
|
||||
** [[id:056e86ae-99ad-45c6-be11-fe6582028870][mastodon]]
|
||||
|
31
20220830224237-fail2ban.org
Normal file
31
20220830224237-fail2ban.org
Normal file
@@ -0,0 +1,31 @@
|
||||
:PROPERTIES:
|
||||
:ID: 00b1b480-0f0c-42a3-8952-4275bc10bc00
|
||||
:mtime: 20220831211359
|
||||
:ctime: 20220830224237
|
||||
:END:
|
||||
#+title: fail2ban
|
||||
|
||||
* Introduction
|
||||
Outil permettant de bloquer pendant une certaine durée toute IP depuis laquelle plusieurs tentatives de connexions ont
|
||||
échoué.
|
||||
|
||||
* Installation
|
||||
#+BEGIN_SRC shell
|
||||
apt install fail2ban
|
||||
#+END_SRC
|
||||
|
||||
* Configuration
|
||||
#+BEGIN_SRC shell
|
||||
cat >/etc/fail2ban/jail.d/sshd.local EOF<<
|
||||
[sshd]
|
||||
enabled = true
|
||||
port = ssh
|
||||
action = iptables-multiport
|
||||
logpath = /var/log/secure
|
||||
maxretry = 3
|
||||
bantime = 600
|
||||
EOF
|
||||
#+END_SRC
|
||||
|
||||
* Références
|
||||
* [[https://www.redhat.com/sysadmin/protect-systems-fail2ban][Linux security: Protect your systems with fail2ban - Redhat]]
|
30
20220926120504-get_things_done.org
Normal file
30
20220926120504-get_things_done.org
Normal file
@@ -0,0 +1,30 @@
|
||||
:PROPERTIES:
|
||||
:ID: 8d548f9b-2a7c-40c3-8538-b14c2926b865
|
||||
:mtime: 20220926123315
|
||||
:ctime: 20220926120504
|
||||
:END:
|
||||
#+title: Get Things Done
|
||||
|
||||
* Introduction
|
||||
* Méthode créée par David Allen,
|
||||
* Gestion du workflow de tâches, composé des étapes suivantes :
|
||||
* *Capturer* tout ce qui traverse son esprit (idées, taches, liens à explorer), rien n'est trop petit ou grand,
|
||||
* *Clarifier* ce qui a été précédemment capturé sous forme de tâches,
|
||||
* *Organiser* les réunions dans l'agenda, les táches dans les différents projets, définir quelles sont les prochaines
|
||||
actions à réaliser, et si celles-ci nécessitent moins
|
||||
de 2mins, les faire,
|
||||
* *Revoir/mettre à jour* l'agenda, l'/inbox/ et les différentes táches. Les objectifs de cette étape sont les
|
||||
suivants :
|
||||
* Vider sa tête des choses à retenir (idéé, tâche, rendez-vous) afin de se concentrer sur la réalisation des
|
||||
tâches : mise à jour de l'inbox,
|
||||
* Avoir un planning et des listes de tâches à jour (contenu, priorités, dépendances entre celles-ci),
|
||||
* *Réaliser les tâches plannifiées* d'après le contexte, les temps et energie disponibles et la priorité des tâches.
|
||||
|
||||
#+DOWNLOADED: https://www.ionos.com/startupguide/fileadmin/StartupGuide/Schaubilder/EN-getting-things-done-workflow.png @ 2022-09-26 12:17:54
|
||||
#+ATTR_ORG: :width 1024
|
||||
[[file:Introduction/EN-getting-things-done-workflow_2022-09-26_12-17-54.png]]
|
||||
|
||||
* Références
|
||||
* [[https://www.ionos.com/startupguide/productivity/getting-things-done-gtd/][Getting things done - Ionos]]
|
||||
** Usage avec org-mode
|
||||
* [[https://github.com/rougier/emacs-gtd][emacs-gtd - Rougier]]
|
39
20220927093748-endlessh.org
Normal file
39
20220927093748-endlessh.org
Normal file
@@ -0,0 +1,39 @@
|
||||
:PROPERTIES:
|
||||
:ID: 1ed652bc-bdcc-4410-a207-fb470df29e71
|
||||
:mtime: 20220927114630
|
||||
:ctime: 20220927093748
|
||||
:END:
|
||||
#+title: endlessh
|
||||
|
||||
* Introduction
|
||||
Outil permettant de ralentir les tentatives de connexions SSH sur le port 22 en envoyant une bannière très lentement
|
||||
(client SSH bloqué pendant des heures), l'idée étant de se connecter depuis un autre port.
|
||||
|
||||
* Installation
|
||||
#+BEGIN_SRC shell
|
||||
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
|
||||
sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config
|
||||
systemctl restart sshd
|
||||
|
||||
apt install endlessh
|
||||
mkdir /etc/endlessh
|
||||
cat >/etc/endlessh/config <<EOF
|
||||
Port 22
|
||||
EOF
|
||||
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/endlessh
|
||||
mkdir /etc/systemd/system/endlessh.service.d/
|
||||
cat /etc/systemd/system/endlessh.service.d/override.conf <<EOF
|
||||
[Service]
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
PrivateUsers=false
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
systemctl restart endlessh.service
|
||||
#+END_SRC
|
||||
|
||||
* Références
|
||||
* [[https://github.com/skeeto/endlessh][endlessh - github]]
|
||||
* [[https://www.digitalocean.com/community/tutorials/how-to-set-up-an-endlessh-tarpit-on-ubuntu-22-04][How To Set Up an Endlessh Tarpit on Ubuntu 22.04 - DigitalOcean]]
|
||||
|
||||
|
86
20220927123818-mastodon.org
Normal file
86
20220927123818-mastodon.org
Normal file
@@ -0,0 +1,86 @@
|
||||
:PROPERTIES:
|
||||
:ID: 056e86ae-99ad-45c6-be11-fe6582028870
|
||||
:mtime: 20221229104009
|
||||
:ctime: 20220927123818
|
||||
:END:
|
||||
#+title: mastodon
|
||||
|
||||
* Introduction
|
||||
Service de microblogging open-source et décentalisée.
|
||||
|
||||
* Installation
|
||||
#+BEGIN_SRC shell
|
||||
# Mastodon requires nodejs 16
|
||||
sudo snap install node --classic
|
||||
|
||||
apt install imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
|
||||
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \
|
||||
bison build-essential libssl-dev libyaml-dev libreadline6-dev \
|
||||
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
|
||||
nginx redis-server redis-tools postgresql postgresql-contrib \
|
||||
certbot python3-certbot-nginx libidn11-dev libicu-dev libjemalloc-dev
|
||||
|
||||
yarn set version stable
|
||||
|
||||
# We will be using rbenv to manage Ruby versions, because it’s easier to get the right versions and
|
||||
# to update once a newer release comes out. rbenv must be installed for a single Linux user,
|
||||
# therefore, first we must create the user Mastodon will be running as:
|
||||
adduser --disabled-login mastodon
|
||||
|
||||
# The following command shall be run using root priviledges (sudo)
|
||||
su - mastodon
|
||||
# Proceed to install rbenv and rbenv-build:
|
||||
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
|
||||
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
|
||||
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
|
||||
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3
|
||||
rbenv global 3.0.3
|
||||
gem install bundler --no-document
|
||||
exit
|
||||
|
||||
# Creating mastodon user in postgres
|
||||
sudo -u postgres psql
|
||||
#+END_SRC
|
||||
#+BEGIN_SRC sql
|
||||
CREATE USER mastodon CREATEDB;
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC shell
|
||||
# The following command shall be run using root priviledges (sudo)
|
||||
su - mastodon
|
||||
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash -
|
||||
nvm install v16.17.1
|
||||
npx browserslist@latest --update-db
|
||||
|
||||
git clone https://github.com/tootsuite/mastodon.git live && cd live
|
||||
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
|
||||
sed -i 's/\([ ]*"emoji-mart": \)"[^"]*",/\1"^3.0.1",/' package.json
|
||||
|
||||
bundle config deployment 'true'
|
||||
bundle config without 'development test'
|
||||
bundle install -j$(getconf _NPROCESSORS_ONLN)
|
||||
yarn install --pure-lockfile
|
||||
|
||||
RAILS_ENV=production bundle exec rake mastodon:setup
|
||||
|
||||
exit
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC shell
|
||||
cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
|
||||
sed -i 's/example.com/mastodon.adrien.run/' /etc/nginx/sites-available/mastodon
|
||||
sed -i 's/\([ ]*server 127.0.0.1\):3000/\1:3001/' /etc/nginx/sites-available/mastodon
|
||||
sed -i 's/\# \(ssl_certificate[ ]*.*\)/\1/' /etc/nginx/sites-available/mastodon
|
||||
|
||||
certbot --nginx -d example.com
|
||||
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
|
||||
|
||||
cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
|
||||
sed -i 's/\(Environment="PORT\)=3000/\1=3001/' /etc/systemd/system/mastodon-web.service
|
||||
systemctl daemon-reload
|
||||
|
||||
#+END_SRC
|
||||
|
||||
* Références
|
||||
* [[https://docs.joinmastodon.org/admin/install/][Installing from source - Mastodon documentation]]
|
71
20220928113147-heap_sort_algorithm.org
Normal file
71
20220928113147-heap_sort_algorithm.org
Normal file
@@ -0,0 +1,71 @@
|
||||
:PROPERTIES:
|
||||
:ID: 6af01039-a0a9-46fc-abe8-82f9662bc4b7
|
||||
:mtime: 20220928120648
|
||||
:ctime: 20220928113147
|
||||
:END:
|
||||
#+title: heap sort algorithm
|
||||
|
||||
* Introduction
|
||||
* Algorithme de classement /in-place/ d'un tableau en le divisant en deux sous-tableaux contenant les éléments classés et non
|
||||
classés,
|
||||
* Efficace : *O(nlog(n))* où n correspond au nombre d'éléments à classer,
|
||||
* Le éléments non classés sont organisés dans une /heap data structure/,
|
||||
* A chaque étape, l'élément max/min se trouvant à la racine du /heap/ est déplacé dans le sous-tableau des éléments
|
||||
classés jusqu'à ce qu'il ne reste qu'un élément dans le sous-tableau des éléments non classés,
|
||||
|
||||
* Organisation des éléments dans le tableau
|
||||
#+DOWNLOADED: https://miro.medium.com/max/720/1*KSt2oqlq_mbPK3t1RE-WFQ.png @ 2022-09-28 11:43:09
|
||||
[[file:Organisation des éléments dans le tableau/1*KSt2oqlq_mbPK3t1RE-WFQ_2022-09-28_11-43-09.png]]
|
||||
|
||||
* Implémentation
|
||||
#+BEGIN_SRC python :results output
|
||||
from typing import Any, List
|
||||
|
||||
def heap_sort(array: List[Any]):
|
||||
build_max_heap(array)
|
||||
# start with the ending index all the way to 0
|
||||
for end_index in range(len(array)-1, 0, -1):
|
||||
swap(array, 0, end_index)
|
||||
# reduce heap size by 1
|
||||
# sift down the value we just swapped
|
||||
heapify(0, end_index - 1, array)
|
||||
# return array
|
||||
|
||||
def build_max_heap(array: List[Any]):
|
||||
last_non_leaf_node_index = (len(array) - 2) // 2
|
||||
for index in range(last_non_leaf_node_index, -1, -1):
|
||||
heapify(index, len(array)-1, array)
|
||||
|
||||
# sift down
|
||||
def heapify(current_index: int, end_index: int, array: List[Any]):
|
||||
left_child_index = 2 * current_index + 1
|
||||
while left_child_index <= end_index:
|
||||
right_child_index = 2 * current_index + 2 if (2 * current_index + 2 <= end_index) else -1
|
||||
|
||||
largest_child_index = left_child_index
|
||||
if right_child_index != -1 and array[left_child_index] < array[right_child_index]:
|
||||
largest_child_index = right_child_index
|
||||
|
||||
if array[current_index] < array[largest_child_index]:
|
||||
swap(array, current_index, largest_child_index)
|
||||
current_index = largest_child_index
|
||||
left_child_index = 2 * current_index + 1
|
||||
else:
|
||||
return
|
||||
|
||||
def swap(array: List[Any], i: int, j: int):
|
||||
array[i], array[j] = array[j], array[i]
|
||||
|
||||
array = [1, -15, 22, 40, 9, 91]
|
||||
print(f"Before sorting: {array}")
|
||||
heap_sort(array)
|
||||
print(f"After sorting: {array}")
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: Before sorting: [1, -15, 22, 40, 9, 91]
|
||||
: After sorting: [-15, 1, 9, 22, 40, 91]
|
||||
|
||||
* Référence
|
||||
* [[https://yuminlee2.medium.com/heap-sort-algorithm-6e200dc51845][Heap Sort Algorithm. A in-place sorting algorithm that sorts… - Medium]]
|
||||
|
37
20221001210655-framadate.org
Normal file
37
20221001210655-framadate.org
Normal file
@@ -0,0 +1,37 @@
|
||||
:PROPERTIES:
|
||||
:ID: 8bb29bf5-219f-49ff-b410-e7cc2473337f
|
||||
:mtime: 20221002111411
|
||||
:ctime: 20221001210655
|
||||
:END:
|
||||
#+title: framadate
|
||||
|
||||
* Introduction
|
||||
Service pouvant être hébergé sur son propre server et proposant une alternative à /doodle/.
|
||||
|
||||
* Installation
|
||||
#+BEGIN_SRC shell
|
||||
apt install php-pgsql php php-intl php-mbstring
|
||||
# The following command shall be run using root priviledges (sudo)
|
||||
mysql -u root -p
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC sql
|
||||
CREATE DATABASE IF NOT EXISTS `framadate` DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||
CREATE USER 'framadate'@'localhost' IDENTIFIED BY 'useastrongpassword';
|
||||
GRANT ALL PRIVILEGES ON `framadate`.* TO 'framadate'@'localhost';
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC shell
|
||||
adduser --disabled-login framadate
|
||||
# The following command shall be run using root priviledges (sudo)
|
||||
su - framadate
|
||||
wget https://packages.framasoft.org/projects/framadate/framadate-1.1.19.zip -P .
|
||||
unzip ./framadate-1.1.19.zip
|
||||
|
||||
chown -R www-data: /home/framadate/framadate
|
||||
sudo -u www-data htpasswd -bc /home/framadate/framadate/admin/.htpasswd admin 'admin_password'
|
||||
#+END_SRC
|
||||
|
||||
* Références
|
||||
* [[https://framagit.org/framasoft/framadate/framadate/-/wikis/home][Framadate · GitLab]]
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
Reference in New Issue
Block a user