async context manager

# async context manager

## __aenter__ & __aexit__

\_\_aenter\_\_ 是 Python 中异步上下文管理器(async context manager)的一个特殊方法。它是异步版本的 \_\_enter\_\_ 方法。当我们使用 async with 语句时,这个方法会被自动调用。

\_\_aexit\_\_ 方法,用于异步清理资源。

完整的调用流程:

```python
async with some_async_context() as context:
    # 在这里使用context
    # __aenter__在进入时被调用
    # __aexit__在退出时被调用
```

可以手动调用 \_\_aenter\_\_ 来手动管理生命周期。

add custom field to contact form 7 mail body

add_action('wpcf7_before_send_mail', function($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if (!$submission) return;

    $post_id = url_to_postid($submission->get_meta('url'));
    if (!$post_id) return;


    $pdf_url = get_field('pdf_file', $post_id);

    if ($pdf_url) {
        $mail = $contact_form->prop('mail');
        $mail['body'] = str_replace('[acf_pdf_url]', $pdf_url, $mail['body']);
        $contact_form->set_properties(['mail' => $mail]);
    }
});

ÉÈÀÇ

`À > alt-0192`

`É > alt-0201 / alt-144`

`È > alt-0200`

`Ç > alt-0199 / alt-128`

Majuscules sous Windows : ÉÈÀÇ

`À > alt-0192`

`É > alt-0201 / alt-144`

`È > alt-0200`

`Ç > alt-0199 / alt-128`

2845. Count of Interesting Subarrays

You are given a 0-indexed integer array nums, an integer modulo, and an integer k. Your task is to find the count of subarrays that are interesting. A subarray nums[l..r] is interesting if the following condition holds: Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k. Return an integer denoting the count of interesting subarrays. Note: A subarray is a contiguous non-empty sequence of elements within an array.
/**
 * @param {number[]} nums
 * @param {number} modulo
 * @param {number} k
 * @return {number}
 */
var countInterestingSubarrays = function(nums, modulo, k) {
    let res = 0; // Stores the count of interesting subarrays
    let pre = 0; // Prefix sum tracking occurrences of nums[i] % mod === k
    let map = new Map([[0, 1]]); // Map to store frequencies of prefix sums modulo 'mod'

    for (let i = 0; i < nums.length; i++) {
        // Increment prefix sum when nums[i] % mod equals k (using i

react_factory_pattern

import { Suspense, lazy } from 'react';

const MyComponent = ({choiceType}) => {
  // Dynamically import the choice component based on choiceType (factory pattern)
  const Choice = lazy(() => {
    switch (choiceType) {
      case 'image':
        return import('./ChoiceImage.jsx');
      case 'default':
        return import('./Choice.jsx');
    }
  });
  
  return (
    <Suspense fallback={'Loading...'}>
      <Choice/>
    <Suspense/>
  );
}

// Could also abstract it to useChoiceFactory hook

rsync_full

rsync -aHvz --force --delete --sparse src dst

lv_create

lvcreate -l 100%FREE -n 

NPM auto-completion in bash

NPM provides autocompletion via the npm completion command. You can add it to your shell configuration
```sh
npm completion >> ~/.bashrc
source ~/.bashrc
```

Pip auto-completion in bash

Pip does not have native bash completion, but you can use tools like argcomplete to enable it
```sh
pip install argcomplete
activate-global-python-argcomplete
```

Twig-Template _headline.html.twig

{# templates/component/_headline.html.twig #}
{% use "@Contao/component/_headline.html.twig" %}

{% block headline_attributes -%}
    {% set headline = headline|merge({attributes: attrs().addClass('foobar').mergeWith(headline.attributes|default)}) %}
    {{ parent() }}
{%- endblock %}

Docker auto-completion in bash

Docker provides its own bash completion script. You can enable it by installing the bash-completion package and sourcing Docker's completion script
```sh
sudo apt install bash-completion
source /usr/share/bash-completion/completions/docker
```

Django auto-completion in bash

Django provides a built-in bash completion script. You can enable it by adding the following to your `.bashrc` or `.bash_profile`. The script uses the `DJANGO_AUTO_COMPLETE` environment variable to determine if it should provide completions.
```sh
_django_completion() {
    COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   DJANGO_AUTO_COMPLETE=1 $1 ) )
}
complete -F _django_completion django-admin
complete -F _django_completion manage.py
```

From url to ip in linux terminal

# From url to ip in linux terminal

```
nslookup <website>
```
Example output: 

```
nslookup facebook.com
Server:        127.0.0.53
Address:    127.0.0.53#53
Non-authoritative answer:
Name:    facebook.com
Address: 157.240.25.35
Name:    facebook.com
Address: 2a03:2880:f10c:83:face:b00c:0:25de
```

2799. Count Complete Subarrays in an Array

You are given an array nums consisting of positive integers. We call a subarray of an array complete if the following condition is satisfied: The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array. Return the number of complete subarrays. A subarray is a contiguous non-empty part of an array.
/**
 * Counts the number of subarrays that contain all distinct elements from the input array.
 * @param {number[]} nums - The input array of numbers.
 * @return {number} - The count of complete subarrays.
 */
var countCompleteSubarrays = function(nums) {
    let count = 0; // Keeps track of the number of complete subarrays
    let set = new Set();

    // Determine the number of distinct elements in the array
    for (let num of nums) {
        set.add(num);
    }
    const numDistinct = set.si

Component props stealing

// my version - inspired by https://michaelnthiessen.com/stealing-prop-types/

// iconDefault.js
export const iconDefaults = {
  size: 'medium',
  shape: 'circle',
  icon: 'default',
  animation: 'none'
};


<!-- Icon.vue -->
<script setup>
import { iconDefaults } from './iconDefaults.js';

const props = defineProps({
  size: { type: String, default: iconDefaults.size },
  shape: { type: String, default: iconDefaults.shape },
  icon: { type: String, default: iconDefaults.icon },
  animation: { t