đź… |
|
|
| |
notes 14/06/2023 inverse 05/10/2023 base64 09/07/2020 pic html 09/07/2020 diffraction 08/03/2022 | ||
# il faut passer à python3 # ressource en français : https://inforef.be/swi/python.htm # en anglais sur le wiki officiel https://wiki.python.org/moin/BeginnersGuide/Programmers # il est de bon ton de commencer programmes et fonction par: ''' une ligne de description encadrée de trois apostrophes ''' # pour voir le contenu d'une bibliothèque import sys dir(sys) # Ĺ“uf de Pâques import this | ||
# en shell la commande suivante n'est pas fiable tac -r -s '.' #! /usr/bin/python3 '''lit un fichiuer binaire Ă l'envers''' import os import sys with open(sys.argv[1], 'rb') as f: n = f.seek(0, os.SEEK_END) while n > 0: n = n - 1 f.seek(n) sys.stdout.buffer.write(f.read(1)) | ||
#! /usr/bin/python3 ''' remplace la commande shell base64 ''' # mais reservé à quelques Mo en * 600 + lent # mais si on ne cherche pas à découper, on peu avoir les memes performances avec : # print(b64encode(open(sys.argv[1], "rb").read()).decode('ascii')) from sys import argv from base64 import b64encode TAILLE = 76 BASE64 = b64encode(open(argv[1], "rb").read()) COUPE = [] while BASE64: COUPE.append(BASE64[:TAILLE]) BASE64 = BASE64[TAILLE:] for LIGNE in COUPE: print(LIGNE.decode('ascii')) | ||
#! /usr/bin/python3 ''' met les images dans le HTML ''' from sys import argv, stdout from os import path from base64 import b64encode if len(argv) < 2: print(argv[0] + " : il faut mettre un nom de ficheir en paramètre") exit(1) if not path.exists(argv[1]): print(argv[0] + " : " + argv[1] + " n'est pas un fichier") exit(2) PAGE = open(argv[1], "r") SRC = "01234" while True: C = PAGE.read(1) if C == '': break stdout.write(C) if C != ' ': SRC = SRC[1:] + C if SRC.lower() == 'src="': C = PAGE.read(1) NOMFIC = "" while C != '"': NOMFIC = NOMFIC + C C = PAGE.read(1) if path.exists(NOMFIC): print("data:image/png;base64,") print(b64encode(open(NOMFIC, "rb").read()).decode('ascii')) else: stdout.write(NOMFIC) stdout.write('"') PAGE.close() | ||
#! /usr/bin/python3 ''' fake diffraction pattern by integer overflow''' ''' incidental tweak on 1985 with Turbo Pascal ''' print ("please wait") import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LogNorm # make these smaller to increase the resolution dx, dy = 1, 1 modulo=1000 # even overflows are fake # generate 2 2d grids for the x & y bounds y, x = np.mgrid[-200:200+dy:dy, -200:200+dx:dx] # less fluffy # z = abs((x**2+y**2)%modulo - modulo/2) z = ((x**2+y**2)%modulo - modulo/2)**2 # x and y are bounds, so z should be the value *inside* those bounds. # Therefore, remove the last value from the z array. z = z[:-1, :-1] fig, ax = plt.subplots() c = ax.pcolor(x, y, z, cmap='RdBu', vmin=0, vmax=z.max()) plt.show() # video fait avec un petit script |