Latex

Latex tutorial Greek numbers, for instance \textlambda. https://www.overleaf.com/learn/latex/List_of_Greek_letters_and_math_symbols Superscript: ^ and subscript: _, example: $a_i$ Basic bold text: https://www.overleaf.com/learn/latex/Bold%2C_italics_and_underlining \textbf{} Greek Letters Greek Letters and Math Symbols. Table How to write a table in Latex: https://www.overleaf.com/learn/latex/Tables A little complicated. \begin{center} \begin{tabular}{ |c|c|c| } \hline cell1 & cell2 & cell3 \\ cell4 & cell5 & cell6 \\ cell7 & cell8 & cell9 \\ \hline \end{tabular} \end{center} Linux Commands This is how to add Linux commands: ...

March 12, 2025

XCS330 ProtoNet

In the 3rd assignment of XCS330, we will implement prototypical neworks (protonets) for few-shots image classification on the Omniglot dataset. Protonets Algorithm This is the protonet in a nutshell, and the example comes from the assignment: In this example, we compute three class prototypes c1, c2, c3 from the support features. The decision boundaries are computed using Euclidean distance. When there’s a new query, we can determine which class it belongs to. ...

March 8, 2025

Threat Model Field Research

In this blog post, I will share the findings of my research in the field of threat modeling. What Is Threat Modeling Threat modeling is a process used to identify, assess, and address potential security threats and vulnerabilities in a system. The STRIDE Model There are numerous threat modeling methodologies, and the one I am interested in is the STRIDE model: Category Description Spoofing Impersonating another user or device. For example, IP spoofing: altering the source IP address in a packet header to make it appear as though the packet is coming from a trusted source. Tampering Malicious modification of data. For example, altering the data as it flows between two computers over the internet. Repudiation User denies having performed an action. For example, a user denies making a billion dolar transaction, and the system lacks the evidence to prove the transaction was indeed made by the user. Information Disclosure exposure of information to individuals who are not supposed to have access to it. For example, users read a file that they were not granted access to. Denial of service Denial of service (DoS) attack Elevation of Privilege An unprivileged user gains privileged access and thereby has sufficient access to compromise or destroy the entire system. Tooling There are many toolings for threat modeling and here are some of them: ...

March 8, 2025

Azure Resources Visualization

Introduction In this blog, I want to talk about how to leverage az cli to visualize a graph in Python. Note that Azure portal has a tab that shows the visualization of the resources. The reason why I am still interested in this topic is that I want to turn azure resource definition into a data structure, which can then be leveraged to generate different form of diagrams: dependency graph of azure resources data flow diagram (for threat modeling) mermaid diagram (for documentation) sequence diagram (need to get sequence information from users) There are also other tools for visualizing azure resources: ...

March 6, 2025

SQLAlchemy

Intro SQLAlchemy is a very popular ORM Python library. Key Concepts Engine See Engine Configuration. The engine is the starting point for SQLAlchemy application. The very basic usage is to create an engine from a postgresql url: from sqlalchemy import create_engine engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:5432/mydatabase") Session See Session Basics. A session is a “holding zone” for the orm-mapped objects and the database. we can configure properties like autocommit and autoflush, and these settings can impact the performance of the application. ...

March 4, 2025

Pydantic

Pydantic Why do we have multiple classes for the same model? For example: from pydantic import BaseModel class UserBase(BaseModel): name: str email: str class UserCreate(UserBase): password: str class User(UserBase): id: int class Config: orm_mode = True Here’s the response from copilot: In Pydantic, we often define multiple schemas like UserBase, UserCreate, and User to handle different use cases and ensure clear separation of concerns. Here’s why we do this: ...

March 3, 2025

Precommit Hook

pre-commit hooks are a way to add hooks that run before the commit process. They are a great way to make sure your code is ready to be committed. Installation Follow platform-specific instructions for installing pre-commit. Or if you have pip installed in your machine. Run: pip install pre-commit Initialization Run the following command to initialize the git hook: pre-commit install Configuration Add a .pre-commit-config.yaml config file in the root folder. Here’s an example: ...

March 3, 2025

Format

There are many tools for linting and formatting Python codes: package usage isort sort imports black format code pylint lint code pep8 lint code autoflake lint code ruff lint and format code Ruff Basic configuration: [tool.ruff] line-length = 120 [tool.ruff.lint] select = ["E501", "I"] [tool.ruff.format] docstring-code-format = true docstring-code-line-length = 88 Since Ruff format doesn’t support sorting import currently, we need to run the linter to sort import: ruff check --select I --fix ruff format

March 3, 2025

FastAPI

Overview FastAPI is a modern, fast web framework for building APIs with Python. It can provide high performance on par with Node.js and Go. Starlette & Uvicorn Both Starlette and Uvicorn are essential components in the FastAPI ecosystem. Starlette starlette is a lightweight ASGI (Async Server Gateway Interface) framework for building web apps FastAPI is built on top of starlette and pydantic, and it abstracts most of the complexity of starlette starlette provides core functionality for handling web requests, responses, routing, middleware and more. Uvicorn: ...

March 3, 2025

Poetry

Overview Poetry is a dependency management and packaging tool for Python. I have been using it for a while and I really love it since it help simplify the process of managing dependencies and virtual environments. Installation If you have pip installed in your machine. Run the following command to install Poetry. Otherwise, follow this guide. pip install poetry Check if Poetry is installed successfully: $ poetry --version Poetry (version 1.8.2) Create New Project To create a new project: ...

March 3, 2025