https://www.gravatar.com/avatar/206912d6900c65386f24516df605c206?s=240&d=mp

Kourtney's Space

Pipenv Notes

Why Pipenv

When maintaining many Python projects,
different projects might use different versions of the same Python libraries.
Not using a virtual environment and installing all Python modules directly on your machine will lead to version conflicts.

In the past, the mechanism of virtualenv + requirements.txt allowed different projects to use different versions of the same package,
and also enabled new developers or production environments to quickly install the packages required by the project.

Stateless HTTP, Stateful Session and Cookies

Stateless HTTP

HTTP is a stateless protocol,
meaning that each request/response is independent,
and is unrelated to previous or subsequent requests/responses.
The same request will always receive the same response,
and will not differ based on the content of previous requests/responses.

This allows the server to save a large amount of database and server storage space because it doesn’t need to store user information.
It also speeds up response times and saves considerable network bandwidth because the client doesn’t always have to connect to the same socket.

WSL 2 on Windows Part 2 - Terminal Interface Settings

/images/wsl2_terminal_screenshot.png

Bringing the terminal settings from Linux and Mac to Windows for easier operation.

Windows Terminal Features

With Windows Terminal, you can:

  • Enable multiple tabs (quickly switch between multiple Linux CLIs, Windows CLIs, PowerShell, etc.)
  • Customize key bindings (shortcuts for opening/closing tabs, copy/paste, etc.)
  • Use search functionality
  • Customize themes

These features offer much more than native WSL support, and allow for a setup similar to my Linux or Mac development environments, which is why I decided to use Windows Terminal.

WSL 2 on Windows Part 1 - Installation and Activation

I’m used to using Linux or Mac terminals for work.
I took some time to set up the WSL environment on my home PC to easily switch work environments.

Differences between WSL 2 and WSL 1

WSL 2 is based on Hyper-V and runs a full Linux kernel in a virtual machine.
WSL 1 is a simulation of Linux functionalities on the Windows system.
Therefore, WSL 2 supports more native Linux features and system calls than WSL 1.

Deep Copy and Shallow Copy

Shallow Copy

Copies as little as possible.
A new structure created by a shallow copy has the same structure as the old one,
and they share the memory address of elements.

For example, in Java:

int[] arr1 = {1, 2, 3};
int[] arr2 = arr1;

arr2 is a shallow copy of arr1.

C++ Container Characteristics and Usage Scenarios - array, vector, deque, list, forward_list

Introduction

C++ provides various containers to store and manage data,
each with its unique characteristics and applicable scenarios.
This article will delve into five common sequence containers: array, vector, deque, list, and forward_list,
comparing their features, performance, and offering selection advice.

Array

std::array is a fixed-size array introduced in C++11,
combining the performance of C-style arrays with the interface of STL containers.

Characteristics

  • Fixed Size: Size is determined at compile time and cannot be changed dynamically.
  • Stack Allocation: Typically allocates memory on the stack, offering high performance.
  • Random Access: Supports O(1) time complexity for random access.
  • Iterator Support: Provides iterators, allowing use with STL algorithms.

When to Use

  • When the data size is known and fixed.
  • When pursuing ultimate performance, avoiding heap allocation overhead.
  • When interoperability with C-style arrays is required.

Example

#include <array>
#include <iostream>
#include <numeric> // For std::accumulate

int main() {
    std::array<int, 5> my_array = {1, 2, 3, 4, 5};

    // Access elements
    std::cout << "Element at index 2: " << my_array[2] << std::endl; // Output: 3

    // Iteration
    for (int& x : my_array) {
        x *= 2;
    }

    // Sum
    int sum = std::accumulate(my_array.begin(), my_array.end(), 0);
    std::cout << "Sum of elements: " << sum << std::endl; // Output: 30

    return 0;
}

Vector

std::vector is a dynamic array that can change its size dynamically at runtime.
It is the most commonly used and flexible sequence container in C++.