Skip to content

Instantly share code, notes, and snippets.

View antoinelebel's full-sized avatar

Antoine L. antoinelebel

  • Montréal
View GitHub Profile
@antoinelebel
antoinelebel / deco.py
Last active November 6, 2018 23:05
Décorateur
def login_required(f):
def decorated_function(*args, **kwargs):
if g.user is None:
return redirect(url_for('login', next=request.url))
return f(*args, **kwargs)
return decorated_function
@app.route('/api/log')
@login_required
@antoinelebel
antoinelebel / byte_converter.py
Last active May 16, 2023 18:50
Bytes converter python3. Convert bytes to KB, MB, GB, TB, PB and explanation on difference between byte, bit, kB, KiB, KB, kb and ko
def get_printable_size(byte_size):
"""
A bit is the smallest unit, it's either 0 or 1
1 byte = 1 octet = 8 bits
1 kB = 1 kilobyte = 1000 bytes = 10^3 bytes
1 KiB = 1 kibibyte = 1024 bytes = 2^10 bytes
1 KB = 1 kibibyte OR kilobyte ~= 1024 bytes ~= 2^10 bytes (it usually means 1024 bytes but sometimes it's 1000... ask the sysadmin ;) )
1 kb = 1 kilobits = 1000 bits (this notation should not be used, as it is very confusing)
1 ko = 1 kilooctet = 1000 octets = 1000 bytes = 1 kB