Skip to content

Instantly share code, notes, and snippets.

@etigui
etigui / netbox_migration.md
Last active January 25, 2024 17:31
Netbox showmigrations with Netbox v3.4.3
(venv) $ python3 manage.py showmigrations
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
@etigui
etigui / netbox_migration.md
Last active January 25, 2024 17:31
Netbox showmigrations with Netbox v3.7.1
(venv) $ python3 manage.py showmigrations
account
 [X] 0001_initial
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
@etigui
etigui / db_import.md
Last active January 25, 2024 17:08
Netbox DB import
DROP DATABASE
CREATE DATABASE
ALTER DATABASE
You are now connected to database "netbox" as user "postgres".
GRANT
SET
SET
SET
SET
@etigui
etigui / scripts.sh
Created October 17, 2020 20:02
Python (linux) - get execution time
# https://stackoverflow.com/questions/1557571/how-do-i-get-time-of-a-python-programs-execution
time -v python yourprogram.py
@etigui
etigui / random.sh
Last active October 14, 2020 12:35
Bash - random string
#!/bin/bash
function rand() {
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $1 | head -n 1
}
echo $(rand 20)
## OUTPUT
# w4QS0zoS9yUUAEc6dlMJ
@etigui
etigui / copy.sh
Last active October 14, 2020 12:09
Bash - find all files under a directory, copy them to another directory named after their parent directory
# https://stackoverflow.com/questions/40959708/find-all-log-files-under-a-directory-copy-them-to-another-directory-named-af
find /stack-exchange/ -type f -iname "*.log" -exec sh -c 'cp "$0" "./logs/$(basename "$(dirname "$0")").log"' {} \;
@etigui
etigui / main.py
Created October 13, 2020 16:33
Python class property
import math
class Test:
def __init__(self):
self.radius = 0
@property
def perimeter(self):
return self.radius
@etigui
etigui / main.py
Last active October 9, 2020 22:14
Python - instance, class and static methods and attributes
# https://pythonguide.readthedocs.io/en/latest/python/unix.html
class Test:
public_class_attribute = 1
_protected_class_attribute = 2
__private_class_attribute = 3
def __init__(self):
self.public_instance_attribute = 4
self._protected_instance_attribute = 5
@etigui
etigui / main.py
Created October 8, 2020 15:01
Pyhton - custom exception
class MyException(Exception):
def __init__(self, message):
super().__init__(message)
@etigui
etigui / main.py
Last active October 8, 2020 15:21
Python - logger configuration to log to file and print to stdout
import sys
import logging
from logging import handlers
from logging.handlers import RotatingFileHandler
LOG_PYTH = '/var/log/logging.log'
LOG_LEVEL = logging.DEBUG
LOG_BACKUP_COUNT = 10
LOG_MB = 1048576
LOG_MAX_BYTES = MB * 10