Skip to content

Instantly share code, notes, and snippets.

View ivanleoncz's full-sized avatar
🔬
Bjarne Stroustrup is someone to admire.

ivanleoncz ivanleoncz

🔬
Bjarne Stroustrup is someone to admire.
View GitHub Profile
@ivanleoncz
ivanleoncz / flask_job_scheduler.py
Last active April 1, 2024 04:06
Demonstrating APScheduler on a Flask App.
#!/usr/bin/python3
""" Demonstrating APScheduler feature for small Flask App. """
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask
def sensor():
""" Function for test purposes. """
print("Scheduler is alive!")
@ivanleoncz
ivanleoncz / loteria_nacional_melate_retro.csv
Created February 13, 2024 01:45
CSV of lottery draws for Melate Retro (Mexico's Loteria Nacional)
NPRODUCTO CONCURSO F1 F2 F3 F4 F5 F6 F7 BOLSA FECHA
30 1398 6 9 26 31 34 37 32 19300000 10/02/2024
30 1397 1 5 12 14 26 31 37 17300000 06/02/2024
30 1396 4 8 20 29 30 35 14 14700000 03/02/2024
30 1395 5 8 17 29 38 39 19 12700000 30/01/2024
30 1394 6 8 26 28 31 33 20 10700000 27/01/2024
30 1393 2 3 18 23 28 29 12 8900000 23/01/2024
30 1392 2 6 20 26 30 32 5 7300000 20/01/2024
30 1391 8 12 14 16 19 29 25 5700000 16/01/2024
30 1390 7 10 18 19 24 25 13 5200000 13/01/2024
@ivanleoncz
ivanleoncz / loteria_nacional_tris.csv
Last active February 2, 2024 03:21
CSV of lottery draws of Tris (Mexico's Loteria Nacional), from 20230101 ~ 20240118
NPRODUCTO CONCURSO R1 R2 R3 R4 R5 FECHA Multiplicador
60 31787 5 5 7 5 1 18/01/2024 NO
60 31786 3 1 8 2 8 18/01/2024 NO
60 31785 4 7 0 8 0 18/01/2024 NO
60 31784 4 9 9 2 3 18/01/2024 NO
60 31783 5 7 3 0 4 18/01/2024 SI
60 31782 4 8 5 1 3 17/01/2024 SI
60 31781 1 6 3 0 7 17/01/2024 NO
60 31780 5 0 5 5 9 17/01/2024 NO
60 31779 8 4 8 2 9 17/01/2024 NO
@ivanleoncz
ivanleoncz / fake_companies.csv
Last active January 21, 2024 02:47
CSV of Fake Companies: for programming and testing purposes
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 9 columns, instead of 2. in line 8.
Index,Organization Id,Name,Website,Country,Description,Founded,Industry,Number of employees
1,FAB0d41d5b5d22c,Ferrell LLC,https://price.net/,Papua New Guinea,Horizontal empowering knowledgebase,1990,Plastics,3498
2,6A7EdDEA9FaDC52,"Mckinney, Riley and Day",http://www.hall-buchanan.info/,Finland,User-centric system-worthy leverage,2015,Glass / Ceramics / Concrete,4952
3,0bFED1ADAE4bcC1,Hester Ltd,http://sullivan-reed.com/,China,Switchable scalable moratorium,1971,Public Safety,5287
4,2bFC1Be8a4ce42f,Holder-Sellers,https://becker.com/,Turkmenistan,De-engineered systemic artificial intelligence,2004,Automotive,921
5,9eE8A6a4Eb96C24,Mayer Group,http://www.brewer.com/,Mauritius,Synchronized needs-based challenge,1991,Transportation,7870
6,cC757116fe1C085,Henry-Thompson,http://morse.net/,Bahamas,Face-to-face well-modulated customer loyalty,1992,Primary / Secondary Education,4914
7,219233e8aFF1BC3,Hansen-Everett,https://www.kidd.org/,Pakistan,Seamless disintermediate collaboration,2018,Publishing Industry,7832
8,ccc
@ivanleoncz
ivanleoncz / postgresql_auto_update_timestamp.sql
Created November 12, 2023 02:44
Demonstrating timestamp auto update on Postgresql, using Triggers.
-- Function which will update 'updated_at' columnd of any table that has it.
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
@ivanleoncz
ivanleoncz / 1_SOLID_srp.py
Last active September 26, 2023 10:06 — forked from dmmeteo/1.srp.py
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
@ivanleoncz
ivanleoncz / .env
Last active January 19, 2023 05:58
Postgresql connector, using psycpg2 and environment variables (.env) loaded via python-dotenv.
# Example data, used for Docke Container environment.
DATABASE_USERNAME='postgres'
DATABASE_PASSWORD='postgres'
DATABASE_IP='172.17.0.2'
DATABASE_PORT='5432'
DATABASE_NAME='postgres'
@ivanleoncz
ivanleoncz / time_ex_1.py
Last active June 28, 2022 00:42
Time Operations in Python
import os
import time
print("Operating System: ", os.uname().sysname)
print("\nTime in UTC since Unix time epoch (1970-01-01 00:00:00).")
print("As seconds: ", time.time())
print("As string: ", time.ctime())
print("Seconds in the future: ", time.ctime(2065944467))
print("One second behind epoch: ", time.ctime(-1))
@ivanleoncz
ivanleoncz / generate_fake_nginx_access_log.py
Created June 23, 2022 02:32
Create FAKE Nginx Access Log File (for simulation, testing and exercising purposes)
from datetime import datetime, timedelta
from ipaddress import ip_network
import random
filename = 'fake_access.log'
number_of_lines = 20
ips = list(ip_network('123.25.44.0/28').hosts())
ips += list(ip_network('25.1.4.128/28').hosts())
@ivanleoncz
ivanleoncz / ex_1.py
Last active March 29, 2022 04:30
Timeit and Understanding how fast different approaches can be
$ python3 -m timeit "'foo' + 'bar'"
50000000 loops, best of 5: 5.31 nsec per loop