Table des matières
- 2026:
- 2025:
13 billet(s) pour novembre 2026
| Réseaux - protocole QUIC mieux que TCP | 2026/11/17 21:26 | Jean-Baptiste |
| Notes conversion JSON YAML | 2026/11/13 11:16 | Jean-Baptiste |
| Git commit perdu | 2026/11/12 18:16 | Jean-Baptiste |
| Notes mojo lang | 2026/11/11 20:34 | Jean-Baptiste |
| Notes rust lang compilation | 2026/11/11 18:35 | Jean-Baptiste |
| Mémoire VSIZE VMSIZE SEGV lang C | 2026/11/11 15:59 | Jean-Baptiste |
| Ansible-navigator utilisation de ansible-vault | 2026/11/06 11:33 | Jean-Baptiste |
| Err Ansible - Module result deserialization failed No start of json char found | 2026/11/06 09:09 | Jean-Baptiste |
| Script Python conversion JSON vers CSV | 2026/11/06 08:14 | Jean-Baptiste |
| Filter Incoming IPv4 Packets Containing IP Options - cve-2026-98432 mitigation - Kernel TCP Use-After-Free | 2026/11/04 21:04 | Jean-Baptiste |
| Notes ZFS | 2026/11/03 18:04 | Jean-Baptiste |
| Diff image container | 2026/11/03 16:30 | Jean-Baptiste |
| Notes processus multi-thread | 2026/11/03 10:59 | Jean-Baptiste |
Cloud Terraform / OpenTofu AWS role policy
# Définition des rôles rattachés aux machines EC2
# Chaque machine a son propre rôle ce qui permet d'affiner au cas par cas
# Référence à la policy managée AWS pour les Agent Cloudwatch
# Commun à tous les rôles des machines EC2
data "aws_iam_policy" "AWSCloudWatchAgentServerPolicy" {
arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}
# Définition une seule fois pour le document d'assume rôle
# Réutilisé dans toutes les policies ci-dessous
data "aws_iam_policy_document" "policy-assume-role-ec2" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [ "ec2.amazonaws.com" ]
}
}
}
# serveur1
resource "aws_iam_role" "role-ec2-serveur1" {
name = "${var.prefix}-role-ec2-serveur1"
assume_role_policy = data.aws_iam_policy_document.policy-assume-role-ec2.json
}
resource "aws_iam_instance_profile" "profile-serveur1" {
name = aws_iam_role.role-ec2-serveur1.name
role = aws_iam_role.role-ec2-serveur1.name
}
resource "aws_iam_role_policy_attachment" "attach-CloudWatchAgentServerPolicy-serveur1" {
role = aws_iam_role.role-ec2-serveur1.name
policy_arn = data.aws_iam_policy.AWSCloudWatchAgentServerPolicy.arn
}
Python - callback2
https://pythonexamples.org/python-callback-function/
def callbackFunc(s): print('Length of the text file is : ', s) def printFileLength(path, callback): f = open(path, "r") length = len(f.read()) f.close() callback(length) if __name__ == '__main__': printFileLength("sample.txt", callbackFunc)
def callbackFunc1(s): print('Callback Function 1: Length of the text file is : ', s) def callbackFunc2(s): print('Callback Function 2: Length of the text file is : ', s) def printFileLength(path, callback): f = open(path, "r") length = len(f.read()) f.close() callback(length) if __name__ == '__main__': printFileLength("sample.txt", callbackFunc1) printFileLength("sample.txt", callbackFunc2)
https://www.localsolver.com/docs/last/technicalfeatures/callbacks.html
class CallbackExample: def __init__(self): self.last_best_value = 0 self.last_best_running_time = 0 def my_callback(self, ls, cb_type): stats = ls.statistics obj = ls.model.objectives[0] if obj.value > self.last_best_value: self.last_best_running_time = stats.running_time self.last_best_value = obj.value if stats.running_time - self.last_best_running_time > 5: print(">>>>>>> No improvement during 5 seconds: resolution is stopped") ls.stop() else: print(">>>>>> Objective %d" % obj.value) ls = localsolver.LocalSolver() cb = CallbackExample() ls.add_callback(localsolver.LSCallbackType.TIME_TICKED, cb.my_callback)
https://www.askpython.com/python/built-in-methods/callback-functions-in-python
def called(n): return n[0]*n[1] def caller(func, n): return func(n) #tuple num = (8, 5) ans = caller(called, num) print("Multiplication =", ans)
https://www.delftstack.com/howto/python/python-callback-function/
def Func_CallBack(c): print("File Length : ", c) def File_Len(filepath, callback): i = open(filepath, "r") file_length = len(i.read()) i.close() callback(file_length) if __name__ == "__main__": File_Length("randomfile.txt", Func_CallBack)
https://stackoverflow.com/questions/40843039/how-can-i-write-a-simple-callback-function
def callback(n): print("Sum = {}".format(n)) def main(a, b, _callback = None): print("adding {} + {}".format(a, b)) if _callback: _callback(a+b) main(1, 2, callback)
https://www.ionos.fr/digitalguide/sites-internet/developpement-web/quest-ce-quun-callback/
def get_square(val): return val ** 2 def caller(func, val): return func(val) caller(get_square, 5)
Python - callback
Voir :
Introduction
Exemple d'une fonction sans callback
#! /usr/bin/env python3 from functools import reduce def calcfact(i): assert i >= 0 return reduce(lambda a, b: a * b, range(1, i+1) if i > 1 else [1]) print(calcfact(3))
Exemple de la même fonction avec callback optionnel
#! /usr/bin/env python3 from functools import reduce def calcfact_called(i, res): print(i, '! = ', res, sep='') def calcfact(i, callback=None): assert i >= 0 res = reduce(lambda a, b: a * b, range(1, i+1) if i > 1 else [1]) if callback is None: return res else: callback(i, res) # Sans Callback print(calcfact(3)) # Avec Callback calcfact(4, calcfact_called)
Exemple avec async / asyncio / await
#! /usr/bin/env python3 import asyncio def waitplop_called(i): print(i) async def waitplop(i, callback=None): await asyncio.sleep(i) if callback is None: return i else: callback(i) async def main(): async with asyncio.TaskGroup() as tg: # Asynchronous with callback tg.create_task(waitplop(3, waitplop_called)) tg.create_task(waitplop(3, waitplop_called)) # Synchronous / sequential without callback task1 = await tg.create_task(waitplop(4)) print(task1) asyncio.run(main())
$ time ./plop.py 3 3 4 real 0m4.120s user 0m0.095s sys 0m0.024s
Autre façon de faire un callback avec asyncio
Voir :
#! /usr/bin/env python3 import asyncio def waitplop_called(task): print(task.result()) async def waitplop(i): await asyncio.sleep(i) return i async def main(): task = asyncio.create_task(waitplop(3)) task.add_done_callback(waitplop_called) await asyncio.gather(task) asyncio.run(main())
Autres
Voir :
# Call 'print("Future:", fut)' when "fut" is done. fut.add_done_callback( functools.partial(print, "Future:"))
Script effacer plusieurs fichiers, sauf les n derniers
Voir aussi logrotate
script
purge_keep_only_last_recent.sh
#! /bin/bash set -o nounset # Parametres CHEMIN=~/backup/ # ADD 1; If KEEP_LAST=5 => Only 4 will be kept KEEP_LAST=10 purge() { local FICHIER=$1 NEWER_THAN=$(ls -1t $CHEMIN/$FICHIER | sed -ne "${KEEP_LAST}p") if [[ ! -z "$NEWER_THAN" ]] then find $CHEMIN -depth -maxdepth 1 -type f -not -newer $(ls -1t $CHEMIN/$FICHIER | sed -ne "${KEEP_LAST}p") -name "$FICHIER" -delete fi } purge 'information_schema-*.sql.gz' purge 'mysql-*.sql.gz' purge 'performance_schema-*.sql.gz' purge 'zabbix-*.sql.gz'
Notes sur "-delete" de find
-delete Effacer les fichiers, et renvoyer vrai si l'effacement a réussi. Si l'effacement échoue, un message d'erreur est envoyé. Si -delete échoue, le statut de sortie de find sera différent de zéro (si jamais il s'interrompt). L'utilisation de l'action -delete active automatiquement l'option -depth.
Attention : N'oubliez pas que la ligne de commande de find est évaluée
comme une expression. Écrire -delete en premier forcera find à essayer d'effacer tout ce qui se trouve dans les points de départ que vous avez indiqué. Lorsque vous testez une ligne de commande de find qui utilisera -delete, vous devriez préciser l'option -depth afin d'éviter les sur‐ prises plus tard. Puisque -delete entraîne -depth, vous ne pouvez pas utiliser en même temps -prune et -delete.
Source : man find
