Hot For Coding
  • Debian错误Can't locate Term/ReadLine.pm

    最近在构建Docker镜像时,总是失败在Can't locate Term/ReadLine.pm,日志如下

    Get:1 http://deb.debian.org/debian bullseye/main amd64 openssl amd64 1.1.1k-1+deb11u1 [851 kB]
    Get:2 http://deb.debian.org/debian bullseye/main amd64 ca-certificates all 20210119 [158 kB]
    debconf: delaying package configuration, since apt-utils is not installed
    Fetched 1009 kB in 25s (41.2 kB/s)
    Selecting previously unselected package openssl.
    (Reading database ... 6772 files and directories currently installed.)
    Preparing to unpack .../openssl_1.1.1k-1+deb11u1_amd64.deb ...
    Unpacking openssl (1.1.1k-1+deb11u1) ...
    Selecting previously unselected package ca-certificates.
    Preparing to unpack .../ca-certificates_20210119_all.deb ...
    Unpacking ca-certificates (20210119) ...
    Setting up openssl (1.1.1k-1+deb11u1) ...
    Setting up ca-certificates (20210119) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.32.1 /usr/local/share/perl/5.32.1 /usr/lib/x86_64-linux-gnu/perl5/5.32 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.32 /usr/share/perl/5.32 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
    debconf: falling back to frontend: Teletype
    Updating certificates in /etc/ssl/certs...
    129 added, 0 removed; done.
    Processing triggers for ca-certificates (20210119) ...
    Updating certificates in /etc/ssl/certs...
    0 added, 0 removed; done.
    Running hooks in /etc/ca-certificates/update.d...
    done.
    Removing intermediate container a19d55490057
     ---> d439938bfcf5
    Step 9/10 : COPY --from=0 /usr/src/myapp/target/release/sso .
    invalid from flag value 0: No such image: sha256:d31713282fd49b05c2c5488678d25fc936b2abdde33bf4e71c869adbb419944f
    Build step 'Execute shell' marked build as failure
    Sending e-mails to: lizhong@uino.com
    Finished: FAILURE
    Cleaning up project directory and file based variables
    00:00
    ERROR: Job failed: command terminated with exit code 1
    

    ...

    READ ALL

  • 构建Docker镜像时全局安装NPM包提示permission denied无权限

    full Docker npm install permission denied

    使用NodeJS镜像node在构建Docker镜像时,总是在npm install -g <package_name>全局安装一些包会提权限被拒绝,虽然是以root用户构建,但仍然有这个错误。目前找到的解决方案就是把项目创建在宿主目录/root下,并多加一个环境变量ENV NPM_CONFIG_PREFIX=/root/.npm-global,然后重新构建镜像就不再提示没权限

    ...

    READ ALL

  • RxJS HTTP轮询拉取例子

    full RxJS http poll

    页面上经常需要每几秒钟轮询服务器接口更新页面状态,这种场景多发生在一些监控页面里,如果不用RxJS可能我们这写轮询代码

    const do_request = () => {
      fetch('https://www.qttc.net/api')
        .then((r) => {
          console.log(r);
        });
    };
    
    setInterval(do_request, 2000);
    

    ...

    READ ALL

  • Rust在VSCode中Debug一次经历

    full Rust debug in VSCode case

    当时正在紧张的编写一个快要必须要在下班前演示的程序,结果在读取Cookie信息时出错了,于是我使用VSCode的Debug模式调试程序,这是个灾难的开始。VSCode配置如下

    launch.json

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "(Windows) Boot",
          "type": "cppvsdbg",
          "request": "launch",
          "program": "${workspaceFolder}/target/debug/rust-debug.exe",
          "args": [],
          "stopAtEntry": false,
          "cwd": "${workspaceFolder}",
          "environment": [],
          "console": "externalTerminal"
        }
      ]
    }
    

    ...

    READ ALL

  • Rust配置crates.io国内镜像,加速依赖更新

    在中国做软件开发,往往需要特殊的技能,这点非常麻烦。crates.io经常因为网络问题会卡在

    $ cargo update
      Updating crates.io index
    

    幸运的话可以通过,最头疼的是等了相当长的时间过后因为网络问题的终止,解决这个问题可以配置crates.io国内镜像,这里以清华大学开源软件镜像站做例子,编辑~/.cargo/config文件,添加以下内容

    [source.crates-io]
    replace-with = 'tuna'
    
    [source.tuna]
    registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
    

    ...

    READ ALL

  • 关于img标签referrerpolicy属性与请求头Referer

    在制作本博客时,有一个文章页生成二维码的一个小需求,简单来说就是传入一个URL返回一个二维码图片。于是自然的就想起了浏览器在发出HTTP请求时通常会默认把来源URL添加到HTTP的请求头Referer字段的这么一个特性

    GET /qrcode HTTP/1.1
    Host: www.qttc.net
    Referer: https://www.qttc.net/about.html
    

    于是页面上显示二维码的代码这么写

    index.html

    <img src="https://static.qttc.net/qrcode" />
    

    ...

    READ ALL

  • Nginx配置项underscores_in_headers

    full nginx logo

    遇到一个比较奇怪的问题,发现经过Nginx反向代理到服务器端时部分头字段被过滤掉了。经过查阅资料,得知HTTP头字段名称在标准下是使用中划线拼接的,例如

    Custom-Header: QTTC

    假如你想使用下划线拼接

    Custom_Header: QTTC

    这是不符合HTTP标准的,默认在Nginx下进行会被drop掉,担心跟CGI变量混淆,以下是官方说明

    missing-disappearing-http-headers

    ...

    READ ALL

  • Rust编译到WebAssembly例子

    full rust webassembly

    随着WebAssembly越来约完善,很多Web应用可以利用它解决性能计算的业务场景,甚至WebAssembly未来还有计划实现调用外部JavaScript方法的计划。

    目前官方推荐使用四种语言编写WebAssembly的源码,它们分别是

    • C/C++ 所有人都知道的语言
    • Rust 我最喜欢的语言
    • AssemblyScript 如果你写C/C++,Rust不舒服,这是最佳的选择
    • WebAssembly 直接编写WebAssembly的格式,难度比较大

    ...

    READ ALL

  • Rust中String与&str互转

    在Rust中字符串是个复杂的概念,String和&str的性质不一样,&str可以使用to_string()转换

    let str: String = "琼台博客".to_string();
    

    如果要把String转回&str,可以使用切片的引用模式

    let str: &str = &"琼台博客".to_string()[..];
    

    ...

    READ ALL

  • JavaScript中encodeURI和encodeURIComponent区别

    在JavaScript中encodeURIencodeURIComponent不少人容易混淆两个的区别与正确用法,从英文单词上理解的话很容易看出来关键性区别的地方,即一个带Component,另一个不带。也就是说带ComponentencodeURIComponent就把输入当作一个完整的部件全部编码。另一个encodeURI则是对URI进行编码,为了保证返回的参数仍然是一个有效的URIhttp://或者https://://不会被编码,来看看例子。

    https://www.qttc.net/Hello World作为入参,分别测试两个函数的返回值

    ...

    READ ALL