Hassan Ali
@hassan_ops
About
Site reliability engineer
Q&A Statistics
All Answers
Re: How to create and use Python decorators
import functools import time # Basic decorator def my_decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): print("Before function") result = func(*args, **kwargs) print("After …
Re: How to search text in files using grep
# Basic search grep "pattern" file.txt # Recursive search in directory grep -r "pattern" /path/ # Case insensitive grep -i …
Re: How to manage services with systemd
# Start/stop service sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl reload nginx # …
Re: How to create a class in Python
class User: # Class variable user_count = 0 def __init__(self, name, email): self.name = name self.email = email User.user_count += …
Re: How to create custom Django management commands
Create command file structure myapp/ management/ __init__.py commands/ __init__.py mycommand.py Write the command # myapp/management/commands/mycommand.py from django.core.management.base import BaseCommand class …
Re: How to set up UFW firewall on Ubuntu
Enable UFW # Check status sudo ufw status # Set default policies sudo ufw default deny incoming sudo ufw default …