Can environment variables be set when connecting to a server using the Node.js SSH2 client? After investigation, it was found that it is possible. Just marking it here.

Setting Environment Variables

The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
this.conn.shell({
env: {
X_LOGIN_IP: '128.1.1.123',
X_ENVIRONMENT_VARIABLE: "desiredvalue"
}, term: 'xterm-256color', // term: 'dumb',
cols: connectOpts.cols, rows: connectOpts.rows,
}, (err, s) => {
if (err) {
console.log('ssh shell error', err);
throw err;
}
})

Limitations

Read more »

Recently, I received a front-end issue about garbled text caused by the user’s network disconnection and recovery. After investigation, I found that the issue was caused by the WEB’s lack of monitoring and handling of network changes. Here are some methods to mark.

Monitor Network Changes

Monitor network changes through the online/offline events. For example, the offline event is triggered when Wi-Fi is turned off, and the online event is triggered when it is turned on.

1
2
3
4
5
6
window.addEventListener('online', () => {
console.log('Network is online');
});
window.addEventListener('offline', () => {
console.log('Network is offline');
});

Check Network Status

Read more »

If you use the blob object for browser-side file downloads and then call the URL.createObjectURL(blob) method, the file will be downloaded directly. However, the downside is that it only supports small file downloads. How can we solve this without changing the backend? StreamSaver.js was created to address this issue.

Principle

StreamSaver.js uses ServiceWorker to intercept requests. If the result of the request is a stream, it can be continuously written to the local browser side. This breaks the limitation of JS single-thread, allowing large file downloads without blocking the thread.

Usage

1
2
3
4
5
6
7
8
9
10
import streamSaver from 'streamsaver';

streamSaver.mitm = 'https://example.com/custom_mitm.html';

const fileStream = streamSaver.createWriteStream('hello.mkv', { size: 10_000_000 });
const fileWriter = fileStream.getWriter();

fileWriter.write(new Uint8Array(chunk));

fileWriter.close();
Read more »

Due to work needs, I have used many terminals, such as iTerm2, Warp, Tabby, Hyper, etc.

Recently, I researched Wave Terminal and found some highlights, so I’ll introduce it here.

Platform

Wave is a local terminal, not web-based, currently supporting.

  1. Mac (M series also supported)
  2. Linux
  3. Windows WSL (Windows is also supported!)
Read more »

OpenAI released GPT-4o mini. After quickly using it, here is an introduction to its basic features.

Goal

The launch of the GPT-4o mini is to replace the GPT-3.5, as it is 60% cheaper than the 3.5 and smarter. Therefore, all scenarios where we used GPT-3.5 can be directly switched to GPT-4o mini.

Read more »
0%