USB specifications and aliases of USB3

Specification Previous Term Technical Term Marketing Term
USB 3.2 N/A USB 3.2 Gen 2×2 SuperSpeed USB 20Gbps
USB 3.1 USB 3.1 Gen 2 USB 3.2 Gen 2 SuperSpeed USB 10Gbps
USB 3.0 USB 3.1 Gen 1 USB 3.2 Gen 1 SuperSpeed USB

References:
Forget USB 3.0 & USB 3.1: USB 3.2 Moving Forward
USB 4.0:支援 Thunderbolt 3、DP 2.0、16K 超解像的「一統天下」制式

Two methods to resolve StackExchange.Redis.RedisTimeoutException in C#

StackExchange.Redis.RedisTimeoutException: Timeout performing SETEX (5000ms), next: SETEX AutoOps:PodLauncher:2109:LWSY:75:85001:IsMainServerRunning, inst: 0, qu: 0, qs: 1, aw: False, rs: ReadAsync, ws: Idle, in: 0, in-pipe: 0, out-pipe: 0, serverEndpoint: r-bp1je5yrr7ctdzwhmk.redis.rds.aliyuncs.com:6379, mc: 1/1/0, mgr: 10 of 10 available, clientName: 2109-85001-0, IOCP: (Busy=1,Free=999,Min=4,Max=1000), WORKER: (Busy=2,Free=32765,Min=32,Max=32767), v: 2.1.28.64774 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2616
   at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) in /_/src/StackExchange.Redis/RedisBase.cs:line 54
   at StackExchange.Redis.RedisDatabase.StringSet(RedisKey key, RedisValue value, Nullable`1 expiry, When when, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 2500
   at Q1.Foundation.RepoLibs.RedisLib.StringSet(RedisKey key, RedisValue value, Nullable`1 expiry, When when, CommandFlags flags)
   at GameSvrLauncher.Lib.RedisCache.<>c__DisplayClass27_0.<set_IsMainServerRunning>b__0(ILogger logger)
   at GameSvrLauncher.Lib.Utils.RetryAction(Action`1 func, String actionDesc, ILogger logger, Int32 executeTimes, Int32 sleepTimes, Action`2 warnCallback, Action`2 faultCallback)

Method #1:

Set minimal worker threads:

Way #1: By environment variables

Before .net 6:

COMPlus_ThreadPool_ForceMinWorkerThreads

.net 6

DOTNET_ThreadPool_ForceMinWorkerThreads

NOTES: The value is in hexadecimal format

ref docs:
https://docs.microsoft.com/en-us/dotnet/core/run-time-config/threading
https://github.com/dotnet/runtime/issues/11774

Way #2:By System.Threading.ThreadPool.SetMinThreads methods

Method #2:

Set sync timeout for redis connection.

"172.16.127.229:6379,defaultDatabase=1,syncTimeout=10000"

the default sync timeout is 5000 ms.
ref docs:
https://stackexchange.github.io/StackExchange.Redis/Configuration.html

[Powershell]Clear docker images by Invoke-RestMethod to docker api

# Clear expired docker images with in specific namespace (30 days ago)
(Invoke-RestMethod http://localhost:2375/images/json) | Where-Object { $_.RepoTags -Like '*/q1game/*' -And ((New-TimeSpan -Start (Get-Date '1970-1-1') -End (Get-Date).ToUniversalTime()).TotalSeconds - $_.Created) -GT (30 * 24 * 60 * 60)} | ForEach-Object{ docker.exe rmi $_.RepoTags }

[Powershell] Create folder, copy file and verify file hash, regex usage

Method #1:

$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
Get-FileHash $destFile -Algorithm MD5 | Out-String -Stream | Select-String -Pattern $hashPattern | % {$_.matches.Groups[1]} | % {$_.Value};

Key points:
1. Out-String, single String
2. Out-String -Stream, output each line one by one

Method #2:

$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
certutil.exe -hashFile $destFile MD5 | Out-String | % {($_ -split '\r?\n')[1]};

Create a custom Application icon on Ubuntu

Create text file like below:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=MyApplication
Comment=My fancy new application
Exec=my_application
Icon=my_application.png
Terminal=false

Name it as YOUR_APP_NAME.desktop, and then put it into /usr/share/applications for anyone; or put it into ~/.local/share/applications for current user only. Then you will see it in the Applications list

Ref: https://askubuntu.com/questions/1026528/adding-custom-programs-to-favourites-of-ubuntu-dock

Install nvidia-340 driver on Ubuntu 20.04.3 LTS

在一台旧PC上安装了Ubuntu 20.04.3 LTS, 显卡是”微星N240GT-MD 暴雪512/D5″, 芯片是 Nvidia Geforce GT240, 需要安装显卡驱动

》 先是从nvidia官方网站根据显卡型号下载了NVIDIA-Linux-x86_64-340.108.run 安装过程中提示: asm/kmap_types.h: No such file or directory 没有找到有效解决办法

》 google一番后尝试直接安装nvidia-340驱动

sudo apt install nvidia-340

也是安装失败, 主要的错误是: dpkg: error: version ‘-‘ has bad syntax: revision number is empty

Setting up lib32gcc-s1 (10.3.0-1ubuntu1~20.04) ...
Setting up vdpau-driver-all:amd64 (1.3-1ubuntu2) ...
Setting up nvidia-340 (340.108-0ubuntu5.20.04.2) ...
dpkg: error: version '-' has bad syntax: revision number is empty
dpkg: error: version '-' has bad syntax: revision number is empty
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia-340
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
Adding system user `nvidia-persistenced' (UID 127) ...
Adding new group`nvidia-persistenced' (GID 134) ...
Adding new user `nvidia-persistenced' (UID 127) with group`nvidia-persistenced' ...
Not creating home directory `/'.
Loading new nvidia-340-340.108 DKMS files...
Building for 5.11.0-40-generic Building for architecture x86_64 Building initial module for 5.11.0-40-generic
Error! Bad return status for module build on kernel: 5.11.0-40-generic (x86_64)
Consult /var/lib/dkms/nvidia-340/340.108/build/make.log for more information.
dpkg: error processing package nvidia-340 (--configure):
  installed nvidia-340 package post-installation script subprocess returned error exit status 10
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.11.0-40-generic
I: The initramfs will attempt to resume from /dev/sda2
I: (UUID=de437dbe-e6b9-4aad-a865-3b9c62bcb807)
I: Set the RESUME variable to override this. 
Errors were encountered while processing:
  nvidia-340
E: Sub-process /usr/bin/dpkg returned an error code (1)

》 继续查找资料
* 有说是postinstall scripts中的一个bug: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1853977 第#3个回复
* 有说是nvidia-340不支持Ubuntu 20.04.3 LTS 最新的内核 5.11.0-40-generic, 后来按照 (https://askubuntu.com/questions/1284266/the-installation-of-the-nvidia-display-driver-340-fails-in-kubuntu-20-10)的说法

卸载5.11.0-40-generic, 安装5.4.0-90-generic内核后解决:

sudo apt install linux-generic
sudo apt-get remove --purge linux-*-5.11.*

重启后重新安装nvidia-340:

sudo apt install -y nvidia-340

成功!!

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0 ==
modalias : pci:v000010DEd00000CA3sv00001462sd00002072bc03sc00i00
vendor   : NVIDIA Corporation
model    : GT215 [GeForce GT 240]
driver   : nvidia-340 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

Three patterns to use “if else” statement in dos/batch scripts

  • Pattern #1
@echo off
set var=b
if "%var%" EQU "a" (echo 1) else if "%var%" EQU "b" (  echo 2) else if "%var%" EQU "c" (  echo 3)
  • Pattern #2
@echo off
set var=b
if "%var%" EQU "a" (
  echo 1
) else if "%var%" EQU "b" (
  echo 2
) else if "%var%" EQU "c" (
  echo 3
)
  • Pattern #3
@echo off
set var=b
if "%var%" EQU "a" (
  echo 1
) ^
else if "%var%" EQU "b" (
  echo 2
) ^
else if "%var%" EQU "c" (
  echo 3
)