blog icon indicating copy to clipboard operation
blog copied to clipboard

红日初升,其道大光:sun_with_face::house_with_garden:请star或watch,不要fork

Results 100 blog issues
Sort by recently updated
recently updated
newest added

[Shadow DOM ](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_shadow_DOM)是在 web component 中常提到的概念,其核心作用就是做到与 shadow host 之外的代码做到隔离,把内部结构、样式、行为做隐藏,相当于是一个沙箱的。早期浏览器会用这个特性来封装一些内部标签,比如 video 标签: 在 chrome dev tool 中可以在设置中配置我们允许查看 shadow dom,设置路径为:settings -> preferences -> Elements -> show user agent shadow DOM ![image](https://user-images.githubusercontent.com/15937065/182904051-b3d1b17f-be2a-4030-9737-70aae8f39b24.png) 开启前:...

使用js的ai应用集合:https://aijs.rocks/

[gin](https://github.com/gin-gonic/gin) 是 golang 中最流行的 web 框架,拥有高性能的路由,官网中介绍的主要特点包括快速、支持中间件、crash 处理、json 验证、支持路由组等,这些特性可以类比 node 的 koa 框架。 ![image](https://user-images.githubusercontent.com/15937065/116857024-b0d2a500-ac2e-11eb-8e65-41d80ceba94d.png) ### 快速开始 安装: ```bash go get -u github.com/gin-gonic/gin ``` 返回一个 json 的路由: ```go package main import (...

Node-inspect(https://github.com/nodejs/node-inspect)有个好处就是可以不重启线上 nodejs 应用,只需要发一个信号给 nodejs 应用的进程,nodejs 应用就开启了 debug 模式,就可以开始调试线上了,如我们的 nodejs 应用跑在了 3000 端口,我们找到对应的进程: ```bash lsof -i tcp:3000 ``` ![image](https://user-images.githubusercontent.com/15937065/114511489-8bbfc780-9c6a-11eb-90ff-47e8a59c4e38.png) 我们发现对应的 pid 是 35294,使用 node-inspect 发信号给对应的 node 进程 ```bash node-inspect -p 35294...

在并发操作中,原子操作是非常现实的问题,典型的就是多个 CPU 对同一个内存的值进行操作,如 i++,很可能两次 i++,这个 i 只增加了一次,sync/atomic 就是为了解决这个问题的。具体的实现在不同的操作系统的实现是不同的, Intel 的 CPU 架构机器上,主要是使用总线锁的方式实现的。 在 AMD 的 CPU 架构机器上就是使用 MESI 一致性协议的方式来保证原子操作。 Atomic 提供了对简单类型进行操作,这些类型包括 int32, int64, uint32, uint64, uintptr, unsafe.Pointer,共6个。这些函数的原子操作共有5种:增或减,比较并交换、载入、存储和交换 如,当我们不使用原子操作的时候: ```go package...

node-prune 是 tj 大神用 go 写的用来删除 node_modules 里不必要的文件(如 .md、.eslintrc)以更快地部署 serverless 应用。 这是一个命令行工具,安装之后只需要运行一下 node-prune 就可以删除掉这些文件。 ![image](https://user-images.githubusercontent.com/15937065/113560069-fd798f00-9634-11eb-9faa-4d06a1ce18e3.png) 本身命令比较简单,因此没有使用到类似 https://github.com/urfave/cli 这种命令行第三方库,直接使用了内置的 flag 库来实现 ![image](https://user-images.githubusercontent.com/15937065/113560076-01a5ac80-9635-11eb-923f-79dab0ad4c35.png) 同时支持 verbose flag 作为定位bug时的输出,同时支持 exclude 和 include option 来支持指定不包括和包括删除的文件(文件夹)...

Golang 的 flag 包能够帮助我们轻松实现一个命令行程序的参数解析,如: ```go package main import ( "flag" "fmt" ) func main() { debug := flag.Bool("verbose", false, "Verbose log output.") name := flag.String("name", "", "your Name") flag.Parse() fmt.Println(*debug)...

strconv 包是 go 中做类型转换的包,可以做各种类型与字符串类型的转换。 ### 布尔值和字符串的转换 #### 使用 FormatBool 将布尔值转化为字符串 true 转化为字符串 true,false 转化为字符串 false ```go package main import ( "fmt" "strconv" ) func main() { t := true f...

在 thrift idl 定义会使用到 int64 这种数据类型,但是 javascript 只支持 IEEE 754 double-precision floats,因此无法支持 int64,再以下这段代码中 int64 被输出成了 buffer ![image](https://user-images.githubusercontent.com/15937065/109380899-39248900-7912-11eb-818b-47615e42e0ad.png) idl ![image](https://user-images.githubusercontent.com/15937065/109380912-46417800-7912-11eb-90c0-294f853b4087.png) ![image](https://user-images.githubusercontent.com/15937065/109380916-4b9ec280-7912-11eb-809a-4cc25086f0c9.png) node.js 中通过 [node-int64](https://www.npmjs.com/package/node-int64) 处理,同时由于 JSON.stringify 支持一个 replacer 参数,可以再这个参数中指定处理 int64: ```js...

![](https://user-gold-cdn.xitu.io/2019/5/6/16a8bc24178e8667?w=2045&h=809&f=jpeg&s=371900) tree shaking 是由 rollup 作者提出并带火的,webpack 在版本2 的时候引入,tree shaking 属于性能优化的一种,国内通常翻译为摇树优化,tree shaking 本身属于 DCE 的一种(dead code elimination),其将未使用到的代码移除,从而使打包后的 js 文件体积变小。 tree shaking 之所以能够实现的原因是得益于 ES module 的提出,因为 ES 的模块规范是只允许 import 时的模块名是字符串常量,且模块的引用是一种强绑定,一种动态只读引用,也就是说 ES 的模块规范不依赖于运行时的状态,这使得静态分析能够是可靠的。...