Skip to content

Instantly share code, notes, and snippets.

View luisgdev's full-sized avatar
🎧
Listening to music

Luis Ch. luisgdev

🎧
Listening to music
View GitHub Profile
@luisgdev
luisgdev / visual_n.py
Last active June 19, 2021 00:40
Turns any bare float number into an easy readable amount.
# In: 12345678.90 (Float)
# Out: 12,345,678.90 (String)
number = float(12345678.90)
n_digits = str(number).find('.')
z_groups = int(n_digits/3)
k_digits = n_digits % 3
group_separator = ','
print(f'Number: {number}')
@luisgdev
luisgdev / unixtime.py
Created June 19, 2021 00:34
Convert unixtime, usually found on sms backups timestamps, to human readable format.
from datetime import datetime
def decode_unixtime(utime):
utime = int(str(utime)[:10])
res = datetime.fromtimestamp(utime)
return res.strftime('%a %Y-%m-%d %H:%M:%S')
if __name__ == '__main__':
@luisgdev
luisgdev / count_days.py
Created June 19, 2021 01:28
Returns how many days there are between 2 given dates.
from datetime import date
def format_date(plain_date):
sep_date = plain_date.split('/')
# Convert string numbers into int variables
# sep_date = [int(item) for item in sep_date]
sep_date = list(map(int, sep_date))
# plain date is DD/MM/YYYY, so ...
day, month, year = sep_date
@luisgdev
luisgdev / main.py
Created September 1, 2022 22:44
Convert image to base64
import base64
image_path = 'IMG_01.jpg'
with open(image_path, 'rb') as image:
result = base64.b64encode(image.read()).decode('utf-8')
print(result)
@luisgdev
luisgdev / fee_calc.py
Created September 7, 2022 21:37
Paypal Fee Calculator
def paypal_fee() -> None:
"""
Paypal Fee Calculator
"""
FEE_RATE: float = 0.054
TRANSACTION_CHARGE: float = 0.3
print("Let's calculate a paypal transaction fee.")
amount = float(input("Amount ($): "))
@luisgdev
luisgdev / ve_datetime.py
Created September 23, 2022 18:40
Get timezone of certain location
def get_vzla_date() -> str:
"""
Get Venezuela time in format DD/MM/YYYY.
:return: String with the date.
"""
dt = datetime.now(pytz.timezone("America/Caracas"))
day = dt.day if dt.day > 9 else f"0{dt.day}"
month = dt.month if dt.month > 9 else f"0{dt.month}"
return f"{day}/{month}/{dt.year}"