Skip to content

Instantly share code, notes, and snippets.

View CN-CODEGOD's full-sized avatar
😏
share my thought

CN-CODEGOD

😏
share my thought
View GitHub Profile
@CN-CODEGOD
CN-CODEGOD / gist:574cbdd8203208dafc08e3ea58b278af
Last active December 29, 2024 06:02
How to use linux in windows
1.
download WSL
2.download subsys for WSL
(ubuntu)
PS.
you can use the linux directory
cd /home
you can use linux to download system software(nginx...)
sudo install nginx
@CN-CODEGOD
CN-CODEGOD / 防火墙配置,端口开放
Last active December 29, 2024 07:00
Linux 常用命令
以下是一些常用的 Linux 命令,这些命令可以帮助你在 Linux 系统中进行文件管理、系统监控、网络配置等操作。
### 文件和目录管理
1. **`ls`** — 列出目录内容
- `ls`:列出当前目录的文件和子目录。
- `ls -l`:列出详细信息(权限、所有者、大小、修改日期等)。
- `ls -a`:显示所有文件(包括隐藏文件)。
2. **`cd`** — 改变目录
- `cd /path/to/directory`:切换到指定目录。
@CN-CODEGOD
CN-CODEGOD / gist:8cf66aaae1b3e33cbf96782a310fe699
Created December 18, 2024 11:16
powershell 创建快捷键方式
$Destination = "$home\links\$title.lnk"
$sourcepath =$url
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Destination")
$Shortcut.TargetPath = $sourcepath
@CN-CODEGOD
CN-CODEGOD / gist:a42458ba755bec66f64a26e5e8e1640a
Last active December 14, 2024 06:48
Powershell添加系统环境变量
#获取环境变量
$pspath=[System.Environment]::GetEnvironmentVariable('psModulepath','machine')
#添加环境变量
$pspath+=";$home\modules"
#设置环境变量
[System.Environment]::SetEnvironmentVariable('psmodulepath',$pspath,'machine')
#系统环境变量和用户环境变量的区别
系统环境变量: 'machine'
当前用户环境变量:'User'
@CN-CODEGOD
CN-CODEGOD / gist:7057854cfe45cdd0b81b8b9ed7c78216
Created November 22, 2024 19:53
powershell 参数类型集合
1.parameterset
nction Measure-Lines {
[CmdletBinding(DefaultParameterSetName = 'Path')]
param (
[Parameter(Mandatory, ParameterSetName = 'Path', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'PathAll', Position = 0)]
[string[]]$Path,
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll', ValueFromPipeline)]
@CN-CODEGOD
CN-CODEGOD / gist:6e43d6077e930f71cc70c03f9622ada5
Last active December 17, 2024 09:16
Windows 中文乱码的疑难杂症
windowS常见encoding:有 cp936,UTF-8
确保你和来源字体编码相同
powershell一般使用的是utf-8,确保你来源和终端encoding相同即可
如果来源JavaScript 可以用
iconv-lite 模组进行encoding 转码
实例:
cp936:utf-8
const { exec } = require('node:child_process');
const path = require('node:path');
@CN-CODEGOD
CN-CODEGOD / gist:a4a2987726778c84ba9bfb9b8c1ce621
Created November 18, 2024 09:00
JavaScript via 其他语言
1.via bat:
const { exec, spawn } = require('node:child_process');
exec('my.bat', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
});
@CN-CODEGOD
CN-CODEGOD / gist:2358dea6164fc608fbb110231f05d47c
Last active December 17, 2024 17:45
powershell AUTO completion
1.The ValidateSet attribute specifies a set of valid values for a parameter or variable and enables tab completion. PowerShell generates an error if a parameter or variable value doesn't match a value in the set. In the following example, the value of the Fruit parameter can only be Apple, Banana, or Pear.
[ValidateSet('Apple', 'Banana', 'Pear')]
2.You can use a Class to dynamically generate the values for ValidateSet at runtime. In the following example, the valid values for the variable $Sound are generated via a Class named SoundNames that checks three filesystem paths for available sound files:
Class SoundNames : System.Management.Automation.IValidateSetValuesGenerator {
[string[]] GetValidValues() {
$SoundPaths = '/System/Library/Sounds/',
[Parameter(
Position = 0,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string[] Name
{
get { return this.processNames; }
set { this.processNames = value; }
}
@CN-CODEGOD
CN-CODEGOD / gist:7114970e0e9082f888456c03ea16f26b
Created September 15, 2024 06:21
powershell系统环境变量合集转换为数组
# 获取系统环境变量 PATH 并将其拆分为数组
$pathArray = $env:PATH -split ';'
# 输出数组内容
$pathArray