Skip to content

Instantly share code, notes, and snippets.

Avatar
💬
I dream about Python.

ivanleoncz ivanleoncz

💬
I dream about Python.
View GitHub Profile
@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)
View generate_fake_nginx_access_log.py
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 / time_ex_1.py
Last active June 28, 2022 00:42
Time Operations in Python
View time_ex_1.py
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 / ex_1.py
Last active March 29, 2022 04:30
Timeit and Understanding how fast different approaches can be
View ex_1.py
$ python3 -m timeit "'foo' + 'bar'"
50000000 loops, best of 5: 5.31 nsec per loop
@ivanleoncz
ivanleoncz / inheritance.cpp
Last active February 28, 2022 02:53
OOP Pillars (Inheritance)
View inheritance.cpp
#include <iostream>
using namespace std;
class Vehicle {
public:
int number_of_wheels = 0;
public:
string turn_on_engine() {
@ivanleoncz
ivanleoncz / encapsulation.cpp
Last active February 28, 2022 02:57
OOP Pillars (Encapsulation, and how Python is not good on that).
View encapsulation.cpp
/* C++ demonstration of OOP Encapsulation principle. */
#include <iostream>
using namespace std;
class Car {
public:
int number_of_wheels = 0;
int door_angle_opening_degrees = 85;
@ivanleoncz
ivanleoncz / 1_generate_keypair.sh
Last active January 13, 2022 02:10
PubkeyAuthentication on SSH
View 1_generate_keypair.sh
# LOCAL MACHINE
ssh-keygen -t rsa -b 4096 -f /home/ivanleoncz/.ssh/mykey
# Generating public/private rsa key pair.
# Enter passphrase (empty for no passphrase):
# Enter same passphrase again:
# Your identification has been saved in /home/ivanleoncz/.ssh/mykey
# Your public key has been saved in /home/ivanleoncz/.ssh/mykey.pub
# The key fingerprint is:
# SHA256:1ATgW9Ly+FZU+gkX44mHKSYFp+/JAwHQHDpPkKoQRzg ivanleoncz@ilex-an5
# The key's randomart image is:
@ivanleoncz
ivanleoncz / file.txt
Created December 2, 2021 16:08
Audit PyPi Packages with pip-audit
View file.txt
# Release Dec 1st, the stable release: https://pypi.org/project/pip-audit/
# Announced by Dustin Ingram: https://twitter.com/di_codes/status/1466109133711724551
# Output of executing pip-audit
$ pip-audit
WARNING:pip_audit._service.pypi:Warning: pip 20.0.2 doesn't support the `cache dir` subcommand, unable to reuse the `pip` HTTP cache and using "/home/ivanleoncz/.pip-audit-cache" instead
\ Auditing webencodings (0.5.1)
Found 26 known vulnerabilities in 4 packages
Name Version ID Fix Versions
@ivanleoncz
ivanleoncz / postgres_1_date_time_timestamp_cast_and_calculations.sql
Last active November 30, 2021 03:58
Demonstration of calculation and casting of DATE, TIME and TIMESTAMP on Postgresql.
View postgres_1_date_time_timestamp_cast_and_calculations.sql
CREATE TABLE ordered_products (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
department VARCHAR(50),
price INTEGER,
weight NUMERIC);
# Let's add some columns with TIMESTAMP data.
ALTER TABLE ordered_products ADD COLUMN created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE ordered_products ADD COLUMN updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
@ivanleoncz
ivanleoncz / database.sql
Created July 5, 2021 02:11
Simple database schema for SQL studies on https://pg-sql.com/ (Udemy Course)
View database.sql
-- Database Schema for simple studies of SQL, from Udemy's couse:
-- "SQL and Postgresql: The Developers Complete Developer's Guide"
-- This schema is used on the following website: https://pg-sql.com/
CREATE TABLE users(
id SERIAL PRIMARY KEY,
username VARCHAR(50)
);
CREATE TABLE photos (
@ivanleoncz
ivanleoncz / iterable_custom_loop_limit.py
Last active June 14, 2021 02:28
Custom iterator object examples.
View iterable_custom_loop_limit.py
class MyIterator:
def __init__(self, limit):
self.limit = limit
def __iter__(self):
self.a = 1
return self
def __next__(self):