0%

1、JavaScript包括哪些数据类型,请分别编写3种以上类型的判断函数,如 isString()

function isString(n) {
if (typeof n == 'string') {
return true;
}
else {
return false;
}
}
function isBoolean(n) {
if (typeof n == 'boolean') {
return true;
}
else {
return false;
}
}

2、编写一个JavaScript函数,试试显示当前时间,格式“年-月-日 时:分:秒”

function showTime() {
var date = new Date();

function toDou(n) {
if (n < 10) {
return '0' + n;
}
else {
return n;
}
}
var dateParts = date.getFullYear() + '年' + toDou(date.getMonth()) + '月' + toDou(date.getDate()) + '日';
var timeParts = toDou(date.getHours()) + ':' + toDou(date.getMinutes()) + ':' + toDou(date.getSeconds());

return dateParts + ' ' + timeParts;
}

3、如何显示隐藏一个DOM元素

document.getElementById('n').style.display = 'block'
document.getElementById('n').style.display = 'none'
阅读全文 »

众所周知,在中国大陆 git clone/pull/push 代码时非常慢。终端卡在那里,半天没有任何反应,不知道在干什么;好不容易连上 git 服务器,下载也是龟速。

使用命令 检测连接速度 正常情况是没什么反应的

ssh -T git@github.com

SSH 形式

对于 SSH 方式,我们可以在 ~/.ssh/config 对 SSH 设置代理,提高 git clone/pull/push 的速度。

Host github.com
User git
HostName github
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
  • User 可以改成自己用户名 也可以不改
  • 代理端口根据自己代理改
  • 如果私钥权限有问题 需要加私钥地址 IdentityFile ~/.ssh/id_rsa

设置好执行一下
Alt text

HTTP 形式

对于 HTTP 形式的仓库地址,可以在终端里输入以下两行命令,为 Git 设置全局的 HTTP 代理,从而提高 git clone/pull/push 的速度。

git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "http://127.0.0.1:7890"

执行完后 ~/.gitconfig 会多出几行。

[http]
proxy = http://127.0.0.1:7890
[https]
proxy = http://127.0.0.1:7890

Compiler Options

一级属性 Top Level

files,extends,include,exclude andreferences

compilerOptions

类型检查 Type Checking

allowUnreachableCode, 默认值: false 不报告执行不到的代码错误 (不建议修改此选项)
allowUnusedLabels, 默认值: false 不报告未使用的标签错误
alwaysStrict, 默认值: false 以严格模式解析并为每个源文件生成 “use strict”语句
exactOptionalPropertyTypes
noFallthroughCasesInSwitch, 默认值: false 报告 switch 语句的 fallthrough 错误。(即,不允许 switch 的 case 语句贯穿)
noImplicitAny, 默认值: false(strict 会开启) 是否可以使用 any 类型
noImplicitOverride,
noImplicitReturns,
noImplicitThis,默认值: false(strict 会开启) 当 this 表达式的值为 any 类型的时候,生成一个错误
noPropertyAccessFromIndexSignature,
noUncheckedIndexedAccess,
noUnusedLocals,默认值: false 报告未使用的本地错误
noUnusedParameters,
strict,默认值: false 开启相当于开启所有 strict 选项和 noImplicitAny、noImplicitThis
strictBindCallApply,
strictFunctionTypes,对函数类型启用严格检查
strictNullChecks,启用严格的 NULL 检查
strictPropertyInitialization
useUnknownInCatchVariables

模块 Modules

allowUmdGlobalAccess,
baseUrl,一般为’.’
module,默认值 target === ‘ES6’ ? ‘ES6’ : ‘commonjs’, 可选 commonjs,amd,umd,system,esnext,node12,nodenext。一般为lib为commonjses为esnext
moduleResolution,可选’classic’、’node’ 一般为’node’
noResolve,
paths,基于 baseUrl 的路径映射的列表
resolveJsonModule,默认值: false 模块导入 import 可以导入 .json 文件
rootDir,
rootDirs,
typeRoots
types,Array 取@types 的包

输出 Emit

declaration,默认值: false 构建 ts 文件时 生成相应的 .d.ts 文件
declarationDir,
declarationMap,
downlevelIteration,
emitBOM,
emitDeclarationOnly,
importHelpers, 默认值: false import 提示,建议打开
importsNotUsedAsValues,
inlineSourceMap,
inlineSources,
mapRoot,
newLine,
noEmit,默认值: false 不生成输出文件
noEmitHelpers,
noEmitOnError,
outDir,编译目录
outFile,
preserveConstEnums,
preserveValueImports,
removeComments, 默认值: false 是否删除注释
sourceMap,默认值: false 生成相应的 .map 文件。
sourceRoot,
stripInternal

JavaScript Support

allowJs,允许 js
checkJs,检查 js
maxNodeModuleJsDepth

Editor Support

disableSizeLimit andplugins

Interop Constraints

allowSyntheticDefaultImports,
esModuleInterop,开启后默认开启 allowSyntheticDefaultImports,建议开启
forceConsistentCasingInFileNames,
isolatedModules
preserveSymlinks

Backwards Compatibility

charset,
keyofStringsOnly,
noImplicitUseStrict,
noStrictGenericChecks,
out,
suppressExcessPropertyErrors
suppressImplicitAnyIndexErrors

语言和环境 Language and Environment

emitDecoratorMetadata,
experimentalDecorators,默认值: false 为 ES 装饰器启用实验性支持 建议开启
jsx,react 为 react-jsx
jsxFactory,
jsxFragmentFactory,
jsxImportSource,
lib, Array [“esnext”, “dom”, “dom.iterable”, “scripthost”]
noLib,
reactNamespace,
target: 默认 ‘es3’,推荐 ‘esnext’
useDefineForClassFields

Compiler Diagnostics

diagnostics,explainFiles,extendedDiagnostics,generateCpuProfile,listEmittedFiles,listFiles andtraceResolution

Projects

composite,disableReferencedProjectLoad,disableSolutionSearching,disableSourceOfProjectReferenceRedirect,incremental andtsBuildInfoFile

Output Formatting

noErrorTruncation,
preserveWatchOutput
pretty

Completeness

skipDefaultLibCheck
skipLibCheck,默认值: false 跳过所有声明文件的类型检查(*.d.ts)

示例

{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "react-jsx",
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
// "noImplicitAny" 必要时关掉
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
}

简单启动

正常用 js 文件启动是

> node src/index

改成 ts 后

> ts-node src/index.ts

使用 nodemon

> nodemon --watch 'src/**' --exec ts-node

使用 alias

使用 alias 后 ts 识别不出来,需要用到 tsconfig-paths 和 tscpaths

> nodemon --watch 'src/**' --exec ts-node -r tsconfig-paths/register src/index.ts --files

tsc 编译时

> tsc && tscpaths -p tsconfig.json -s ./src -o ./dist

起因

科学上网大家用的最多的应该是小飞机和 V2RAY,配置起来方便,用起来还挺好用的。不过最近因工作需要,经常要切 vpn 来访问不同的网络,每次切换挺麻烦的。同事给安利了一个神器 ClashX,简单来说可以根据不用域名来自动匹配对应的 vpn

准备工作

下载安装,选择配置文件这些就不详细介绍了,网上很多教程,本文主要讲述配置文件

情景模拟

现在假设我们需要满足以下需求

  • 访问 google(科学上网)
  • 使用一个 ss 访问 xx.example1.com
  • 使用一个 v2ray 访问 xx.example2.com

配置文件结构

示例

# 基础配置(一般不需要修改)
mixed-port: 7890
external-controller: 127.0.0.1:9090
allow-lan: false
mode: rule
log-level: warning
# 代理配置
proxies:
- name: "vpn1" #名称
type: ss # 类型ss
server: 1.1.1.1 # 服务器ip
port: 8888 # 端口
cipher: aes-256-cfb # 加密方式
password: "mima" # 密码

- name: "vpn2"
type: vmess
server: xx.example.com
port: 83
uuid: 1as23-ad2a-23fs-sdf3-23dfdv3f
alterId: 0
cipher: auto
tls: true
skip-cert-verify: true
network: ws
ws-path: /
ws-headers:
Host: xx.example.com # 填你的主机名
# 代理组配置
proxy-groups:
- name: "自动选择"
type: url-test
proxies:
- "vpn1"
- "vpn2"
url: "https://www.google.com/"
interval: 300

- name: "PROXY1"
type: url-test
proxies:
- "vpn1"
url: "https://xx.example1.com/"
interval: 300

- name: "PROXY2"
type: url-test
proxies:
- "vpn2"
url: "https://xx.example2.com/"
interval: 300
# 匹配规则
rules:
# xx.example1.com使用PROXY1
- DOMAIN,xx.example1.com,PROXY1

# xx.example2.com使用PROXY1
- DOMAIN,xx.example2.com,PROXY2

# 使用自动选择
- DOMAIN-SUFFIX,google.com,自动选择
- DOMAIN-SUFFIX,facebook.com,自动选择
- DOMAIN-SUFFIX,twitter.com,自动选择

# 没匹配到的不用代理,一般放最后
- GEOIP,CN,DIRECT
- MATCH,DIRECT

基础配置和代理配置就不多说了,前者不需要改,后者从小飞机或 v2ray 把配置贴到对应的位置就好了

代理组配置

域名匹配后直接对应的是代理组
配置项

  • name: 随意字符
  • type: url-test 通过指定的 URL 测试并选择延迟最低的节点 | select 手动选择节点
  • proxies: 选择对应代理,可以一个也可以多个
  • url: 测试的 url url-test 配置
  • interval: 300 url-test 配置

匹配规则

结构

${type},${domain},${group}

type 可以根据全域名或者域名后缀来设置,也可以通过 IP 设置
DOMAIN: 全域名
DOMAIN-SUFFIX; 域名后缀,相当于 pac 里的*.域名

IP 匹配结构
IP-CIDR,${ip}/${32},${group}

32 代表全匹配
24 代表前三位匹配
16 代表前二位匹配
8 代表第一位匹配

机场

https://cocoyunxyz.github.io
https://xxcer.com
https://jisumax.net