# 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_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`
`À > alt-0192`
`É > alt-0201 / alt-144`
`È > alt-0200`
`Ç > alt-0199 / alt-128`
/**
* @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
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 -aHvz --force --delete --sparse src dst
lvcreate -l 100%FREE -n
```sh
npm completion >> ~/.bashrc
source ~/.bashrc
```
```sh
pip install argcomplete
activate-global-python-argcomplete
```
{# 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 %}
```sh
sudo apt install bash-completion
source /usr/share/bash-completion/completions/docker
```
```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
```
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
```
/**
* 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
// 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