This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num1 = 13 | |
num2 = 16 | |
# Tuple | |
print(("Odd", "Even")[num1 % 2 == 0]) | |
print(("Odd", "Even")[num2 % 2 == 0]) | |
# Dict | |
print({True: "Even", False: "Odd"}[num1 % 2 == 0]) | |
print({True: "Even", False: "Odd"}[num2 % 2 == 0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import memory_profiler as mem_profile | |
import random | |
import time | |
names = ["John", "Corey", "Adam", "Steve", "Rick", "Thomas"] | |
majors = ["Math", "Engineering", "CompSci", "Arts", "Business"] | |
print(f"Memory (Before): {mem_profile.memory_usage()}Mb") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def my_logger(orig_func): | |
import logging | |
logging.basicConfig( | |
filename="{}.log".format(orig_func.__name__), level=logging.INFO | |
) | |
@wraps(orig_func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker --version [list docker version] | |
docker run hello-world | |
docker container ls | |
docker container ls -a | |
docker contianer rm -f $(docker container ls -aq) [remove all container] | |
docker image ls | |
docker images | |
docker image rm <image-name> [remove docker image] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# static code analysis (mypy) | |
# mypy main.py [check miss match] | |
from typing import List, Dict, Set, Optional, Any, Sequence, TypeVar | |
def add_numbers(a: int, b: int, c: int) -> None: | |
print(a + b + c) | |
add_numbers(1, 2, 3) | |
x: List[List[int]] = [[1, 2, 3], [1, 2, 3]] # nested list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run using docker image | |
docker run --name db --rm -e POSTGRES_PASSWORD="mypasswd" -d postgres:alpine | |
docker exec -it db bash --> get inside container | |
# Copy file to docker container | |
docker cp foo.txt container_id:/foo.txt | |
docker run | |
--name postgresql | |
-e POSTGRES_USER=myusername |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Configuration files: /etc/nginx | |
Binary / executable files: /usr/sbin | |
Log directory of files: /var/log/nginx | |
Data or Document directory files: /usr/share/nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create ssh server | |
sudo apt install openssh-server | |
sudo ufw allow ssh | |
# Connect | |
ssh username@host --> give password | |
ssh-copy-id user@host | |
ssh user@host |
OlderNewer