软件开发 Archives - 峰哥分享 https://www.dengnz.com/category/software-develop/ 昨天,今天,明天,每天的每天,都多懂一点点... Thu, 02 Sep 2021 11:17:28 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.5.4 https://www.dengnz.com/wp-content/uploads/2020/02/cropped-logo-32x32.png 软件开发 Archives - 峰哥分享 https://www.dengnz.com/category/software-develop/ 32 32 在 ipad 上使用code-server (vscode) 加 neovim 实现生产力 https://www.dengnz.com/2021/09/02/%e5%9c%a8-ipad-%e4%b8%8a%e4%bd%bf%e7%94%a8code-server-vscode-%e5%8a%a0-neovim-%e5%ae%9e%e7%8e%b0%e7%94%9f%e4%ba%a7%e5%8a%9b/ https://www.dengnz.com/2021/09/02/%e5%9c%a8-ipad-%e4%b8%8a%e4%bd%bf%e7%94%a8code-server-vscode-%e5%8a%a0-neovim-%e5%ae%9e%e7%8e%b0%e7%94%9f%e4%ba%a7%e5%8a%9b/?noamp=mobile#respond Thu, 02 Sep 2021 11:13:18 +0000 http://www.dengnz.com/?p=82983 需要用到的工具: 一台 linux 服务器 code-server docker 版 webssh neovi… 阅读更多 »在 ipad 上使用code-server (vscode) 加 neovim 实现生产力

The post 在 ipad 上使用code-server (vscode) 加 neovim 实现生产力 appeared first on 峰哥分享.

]]>
017C0CBD-D6CA-4710-87C9-D24231A8CE49.jpeg

需要用到的工具:
一台 linux 服务器
code-server docker 版
webssh
neovim
ipados safari
蓝牙键盘

注:本教程需要 linux,ssh, docker 相关知识。

注:我开始是使用 chrome, 但是chrome里面经常会有问题,常常输入没有反应。

不用 vim的小伙伴不装 neovim即可,不是必须的。

1、在ipad上安装webssh, 连接到linux服务器, 安装 code-server docker版

运行 docker 容器的时候要把代码文件夹映射进去, 这样才能在 code-server 的vscode里找到文件夹进行开发。

还要记得把端口映射出来,下一步才能从IPAD映射过去。

2、用 webssh的 tunnel 功能把ipados本机的端口映射到 code-server 的端口。

3、在 sarafi里打开 code-server的网址,比如我是 localhost:8083, 按提示找到密码, 然后输入密码

4、在 code-server 里安装 neovim 插件。然后在 code-server的terminal 里安装 neovim

在 code-server 的 docker 里安装 neovim要注意。 因为我使用的官方 docker-server docker镜像里面没有neovim, 所以我需要自己安装, 但是直接用 apt-get install 会安装到很旧的版本, 好像是0.34. 这样neovim插件是不会工作的, 因为插件相求最低 0.5 的版本。

需要到以下网站下载安装。 可以先用 apt-get 安装 wget, 再用wget下载安装包, 然后根据提示安装即可。

https://github.com/neovim/neovim/releases/tag/v0.5.0

code-server 设置文件参考

{
“wokbench.colorTheme”: “Default Dark+”,
“vskode-neovim.neovimPath”: “/home/coder/squashfs-root/usr/bin/nvim”,
“files.autoSave”: “off”
}

复制问题

安装了 neovim 以后, 在vscode 的界面无法正常的选择文字内容进行复制,这的确是一个非常头痛的问题。 不管是使用 “+Y, 还是 ”*Y都没有办法把VISUAL mode 选中的文字复制到IPADOS的剪贴板。

我最后的方法就是把需要复制的文字放在一个单独的文件里面, 然后使用 cmd+A, cmd+C 进行复制。还好 CMD+A 全选是工作的。

The post 在 ipad 上使用code-server (vscode) 加 neovim 实现生产力 appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2021/09/02/%e5%9c%a8-ipad-%e4%b8%8a%e4%bd%bf%e7%94%a8code-server-vscode-%e5%8a%a0-neovim-%e5%ae%9e%e7%8e%b0%e7%94%9f%e4%ba%a7%e5%8a%9b/feed/ 0
使用谷歌 Dialogflow 快速制作一个 Slack 机器人 https://www.dengnz.com/2020/06/29/%e4%bd%bf%e7%94%a8%e8%b0%b7%e6%ad%8c-dialogflow-%e5%bf%ab%e9%80%9f%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aa-slack-%e6%9c%ba%e5%99%a8%e4%ba%ba/ https://www.dengnz.com/2020/06/29/%e4%bd%bf%e7%94%a8%e8%b0%b7%e6%ad%8c-dialogflow-%e5%bf%ab%e9%80%9f%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aa-slack-%e6%9c%ba%e5%99%a8%e4%ba%ba/?noamp=mobile#respond Mon, 29 Jun 2020 03:18:54 +0000 https://www.dengnz.com/?p=2592 好久以前, 我用谷歌的Dialogflow 写了一个 Telegram 的机器人。 就是长下面这样的。 这个机… 阅读更多 »使用谷歌 Dialogflow 快速制作一个 Slack 机器人

The post 使用谷歌 Dialogflow 快速制作一个 Slack 机器人 appeared first on 峰哥分享.

]]>
好久以前, 我用谷歌的Dialogflow 写了一个 Telegram 的机器人。 就是长下面这样的。

这个机器人是由 Dialogflow 来提取自然语言中的关键字, 也就是地点。 拿到地点以后, 它会把地点作为参数传到我的服务器上。 我的服务器上会调用 OpenWeatherMap 的API 来拿到天气信息,再返回。 非常简单的一个机器人, 但是因为用了Dialogflow, 就有了智能的属性, 可以处理自然语言,也就是人类平常说话的方式。
除了可以从自然语言中抓取需要的参数,使用 Dialogflow 还有一个很大的好处就是你可以非常快速的把功能集成到其它平台的机器人上。
Dialogflow 官方支持以下机器人, 所以只要轻轻一点,你就拥有一个新的机器人! 当然那是不可能的。
但是还是非常的简单, 当你点开开关以后, 唯一要做的就是在相应的平台创建 (就是点点点)一个机器人, 然后把这个机器人的参数抄过来填上就可以了。 而 dialogflow 会给你详细的操作步骤。 只要跟着做就可以了。

当你创建好你的 slack app 后, 把这个页面的信息抄到dialogflow


你的 Slack 机器人就做好了, 然后你需要把这个机器人安装到你的 slack workspace 里面。然后它就神奇的工作了。

如果你要添加其它平台的机器人, 如法炮制就可以。
不过我现在只知道怎么用 Dialogflow 的 fullfillment 发文字消息, 如果要发图片和视频啥的, 就抓瞎了

The post 使用谷歌 Dialogflow 快速制作一个 Slack 机器人 appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/06/29/%e4%bd%bf%e7%94%a8%e8%b0%b7%e6%ad%8c-dialogflow-%e5%bf%ab%e9%80%9f%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aa-slack-%e6%9c%ba%e5%99%a8%e4%ba%ba/feed/ 0
Nodejs debug 模块在 VSCODE debug console 里不工作的问题 https://www.dengnz.com/2020/06/20/nodejs-debug-%e6%a8%a1%e5%9d%97%e5%9c%a8-vscode-debug-console-%e9%87%8c%e4%b8%8d%e5%b7%a5%e4%bd%9c%e7%9a%84%e9%97%ae%e9%a2%98/ https://www.dengnz.com/2020/06/20/nodejs-debug-%e6%a8%a1%e5%9d%97%e5%9c%a8-vscode-debug-console-%e9%87%8c%e4%b8%8d%e5%b7%a5%e4%bd%9c%e7%9a%84%e9%97%ae%e9%a2%98/?noamp=mobile#respond Sat, 20 Jun 2020 03:00:00 +0000 https://www.dengnz.com/?p=2463 我在Nodejs里使用 debug 这个模块来记录日志 https://www.npmjs.com/packa… 阅读更多 »Nodejs debug 模块在 VSCODE debug console 里不工作的问题

The post Nodejs debug 模块在 VSCODE debug console 里不工作的问题 appeared first on 峰哥分享.

]]>
我在Nodejs里使用 debug 这个模块来记录日志

https://www.npmjs.com/package/debug

直接在命令行里面运行的时候,日志可以正确显示。 而当我直接在 VSCODE 里面运行的时候, 用 debug 模块输出的日志则无法显示。 但是用 console.log 输出的日志则正常显示。

这里有两个问题需要解决, 首先 ,要正确的设置 DEBUG 这个环境变量。 然后, 需要在集成的命令行底下运行程序 ,而不是在 debug console.

所以在 launch.json 文件里, 应该是类似这样的设置。


 {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "env": {"NODE_ENV":"development", "DEBUG":"*"},
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\bin\\www",
            "console": "integratedTerminal"
        }

然后, 你就可以在 vscode 里看到正常的 debug 日志了

The post Nodejs debug 模块在 VSCODE debug console 里不工作的问题 appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/06/20/nodejs-debug-%e6%a8%a1%e5%9d%97%e5%9c%a8-vscode-debug-console-%e9%87%8c%e4%b8%8d%e5%b7%a5%e4%bd%9c%e7%9a%84%e9%97%ae%e9%a2%98/feed/ 0
Youtube Google Script Bot Broken checklist https://www.dengnz.com/2020/04/19/youtube-google-script-bot-broken-checklist/ https://www.dengnz.com/2020/04/19/youtube-google-script-bot-broken-checklist/?noamp=mobile#respond Sun, 19 Apr 2020 08:33:05 +0000 https://www.dengnz.com/?p=2419 1. Check whether the mlab is exceed quota 2. Bind the b… 阅读更多 »Youtube Google Script Bot Broken checklist

The post Youtube Google Script Bot Broken checklist appeared first on 峰哥分享.

]]>
1. Check whether the mlab is exceed quota
2. Bind the bot to ngork
3. ngrok forward to fiddler
4. Fiddler to point to google app script to test
5. Point to uni account to check stackdriver log
6. delete not important data from db
7. remember to repair the db to release disk

The post Youtube Google Script Bot Broken checklist appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/04/19/youtube-google-script-bot-broken-checklist/feed/ 0
potato 回声机器人 https://www.dengnz.com/2020/04/13/potato-%e5%9b%9e%e5%a3%b0%e6%9c%ba%e5%99%a8%e4%ba%ba/ https://www.dengnz.com/2020/04/13/potato-%e5%9b%9e%e5%a3%b0%e6%9c%ba%e5%99%a8%e4%ba%ba/?noamp=mobile#comments Mon, 13 Apr 2020 10:42:45 +0000 http://www.dengnz.com/?p=2407 const token = '123:abctoke'; // 这里键入你得token const BASE_… 阅读更多 »potato 回声机器人

The post potato 回声机器人 appeared first on 峰哥分享.

]]>
const token = '123:abctoke'; // 这里键入你得token const BASE_URL = 'https://api.rct2008.com:8443/' + token + '/'; const myID = token.slice(0, token.indexOf(':')) function setWebhook() { // 这里写入setWebhook 然后先run 一次这个函数 才能将机器人接入GAS var setWebhook = { method: 'setWebhook', payload: { url: 'https://script.google.com/macros/s/hojpoicsihjnvsopalL-kjeg/exec' //这里键入你得GS 发布地址 } } Logger.log(postPotato(setWebhook)) } function doGet(e) { return HtmlService.createHtmlOutput("Hello World!! No, this link should be hidden!!!"); } function doPost(e) { var bodys = JSON.parse(e.postData.contents); bodys.forEach(element => { if (element) { payload = preparePayload(element); toPotato(payload) } }); } function toPotato(payload) { if (Array.isArray(payload)) { payloads = payload; } else { payloads = [payload]; } Logger.log(payloads) for (var i = 0; i < payloads.length; i++) { payload = payloads[i]; if (payload) { var res = postPotato(payload); Logger.log(res) } } } function postPotato(payload) { let url = BASE_URL + payload.method delete payload.method var data = { 'contentType': 'application/json', "method": "post", "payload": JSON.stringify(payload) } var response = UrlFetchApp.fetch(url, data); var res = JSON.parse(response); return res; } function preparePayload(body) { if (body.message && body.message.text) { if (body.message.from.id == myID) { //判断信息来源是自己得 然后返回空对象 return null } let mes = body.message.text; var sendTextMessage = { method: 'sendTextMessage', chat_type: body.message.chat.type, chat_id: body.message.chat.id, text: mes, // markdown: true, } if (mes == '小掌门') { const hello = ['你好', 'hi'] sendTextMessage.text = hello[Math.floor(Math.random() * hello.length)] } else { sendTextMessage.text = mes } return sendTextMessage } }

项目代码我也上传了gitee 无需翻墙直接访问?

The post potato 回声机器人 appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/04/13/potato-%e5%9b%9e%e5%a3%b0%e6%9c%ba%e5%99%a8%e4%ba%ba/feed/ 4
Fix android emulator offline https://www.dengnz.com/2020/03/31/fix-android-emulator-offline/ https://www.dengnz.com/2020/03/31/fix-android-emulator-offline/?noamp=mobile#respond Mon, 30 Mar 2020 20:32:29 +0000 https://www.dengnz.com/?p=2386 My android studio keep waiting to connect the the emula… 阅读更多 »Fix android emulator offline

The post Fix android emulator offline appeared first on 峰哥分享.

]]>
My android studio keep waiting to connect the the emulator, so that I couldn’t debug.
Using adb to check, the device is always offline. Stop and start the emulator doesn’t help.


Here is the trick, after I code boot the device, the problem gone.

The post Fix android emulator offline appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/03/31/fix-android-emulator-offline/feed/ 0
How to batch run npm install on Windows 10 https://www.dengnz.com/2020/02/13/how-to-batch-run-npm-install-on-windows-10/ https://www.dengnz.com/2020/02/13/how-to-batch-run-npm-install-on-windows-10/?noamp=mobile#respond Thu, 13 Feb 2020 02:04:28 +0000 https://www.dengnz.com/?p=2163 If for some reasons, npm update doesn’t fit you n… 阅读更多 »How to batch run npm install on Windows 10

The post How to batch run npm install on Windows 10 appeared first on 峰哥分享.

]]>
If for some reasons, npm update doesn’t fit you need and you need to update some npm packages one by one.

You will want to write a batch command to do it. It seems that a simple bat or cmd file with all the npm installl command listed will work.

But the truth on windows is, only the first command is run.

The reason is that npm itself is not a command but a batch file too. Too make sure all the npm commands will be run, you can add a call in the front of the command.

Check the example below:

call npm install @angular/core@latest
call npm install @angular/forms@latest
call npm install @angular/platform-browser@latest
call npm install @angular/platform-browser-dynamic@latest
call npm install @angular/platform-server@latest
call npm install @angular/router@latest
call npm install @angular/tsc-wrapped@latest
call npm install @angular/core@latest
call npm install angular2-notifications@latest
call npm install bootstrap@latest
call npm install codelyzer@latest
call npm install elements-zone-strategy@latest
call npm install extract-text-webpack-plugin@latest
call npm install html-webpack-plugin@latest
call npm install karma-webpack@latest
call npm install webpack-dev-middleware@latest
call npm install ng-pick-datetime@latest
call npm install ng2-img-max@latest
call npm install ngx-file-drop@latest
call npm install ngx-mask@latest
call npm install tsickle@latest

The post How to batch run npm install on Windows 10 appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/02/13/how-to-batch-run-npm-install-on-windows-10/feed/ 0
How to use a different nodejs version on atlassian bamboo build agent https://www.dengnz.com/2020/01/17/how-to-use-a-different-nodejs-version-on-atlassian-bamboo-build-agent/ https://www.dengnz.com/2020/01/17/how-to-use-a-different-nodejs-version-on-atlassian-bamboo-build-agent/?noamp=mobile#respond Thu, 16 Jan 2020 21:40:52 +0000 https://www.dengnz.com/?p=2157 When you build a nodejs app, you may need to use a spec… 阅读更多 »How to use a different nodejs version on atlassian bamboo build agent

The post How to use a different nodejs version on atlassian bamboo build agent appeared first on 峰哥分享.

]]>
When you build a nodejs app, you may need to use a specific version of node for building. Either you want to match the running env or your node packages require a certain nodejs version.

On Azure DevOps, you can easily choose the node version by adding a nodejs installer step. With bamboo, there is no nodejs install, but this can be achieved easily if you have admin access to the build agent.

In the build steps, add a script step, and add the following inline script. This script will switch the node version for you. For first time running, you need to uncomment all the lines to install nvm first.


node -v
#curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#nvm install 13.6.0
nvm use 13.6.0
nvm list
node -v

Then you can add a npm install step, it will use the new node version. Or you can simply add node install command to the script.

More about nvm, read this https://github.com/nvm-sh/nvm/blob/master/README.md

The post How to use a different nodejs version on atlassian bamboo build agent appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/01/17/how-to-use-a-different-nodejs-version-on-atlassian-bamboo-build-agent/feed/ 0
Create a azure app service for nodejs app https://www.dengnz.com/2020/01/13/create-a-azure-app-service-for-nodejs-app/ https://www.dengnz.com/2020/01/13/create-a-azure-app-service-for-nodejs-app/?noamp=mobile#respond Sun, 12 Jan 2020 22:15:19 +0000 https://www.dengnz.com/?p=2134 1. Click the top left corner burger icon to popup the m… 阅读更多 »Create a azure app service for nodejs app

The post Create a azure app service for nodejs app appeared first on 峰哥分享.

]]>
1. Click the top left corner burger icon to popup the menu sidebar

2. Fill the basics form

3. You can change the side to B1 so that you can get your first 30 days free

4. If you are deployed from a docker registry such as docker hub or azure registry, choose “Docker Container”, otherwise choose Code then specify the runtime stack.

5. Leave Monitoring unchanged

6. Leave tags unchanged

7. Review and Create

8. Waiting for deployment

9. Once done, click “Go to resource”

10. Now you are on the app service resource page. You can manage it from here.

11. You can always come back to the app service resource page by clicking the link from the home page.


12. Click the “browse” button to check your website.

13. Great, you azure app service is running. But it runs a default nodejs app from microsoft. You can follow the “Quickstart” button to create and deploy your first node js app. Click the “Deployment Center” to go back to the portal.
Next Step: Use Azure Dev Ops to setup continuous deployment for your app service.

 

The post Create a azure app service for nodejs app appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2020/01/13/create-a-azure-app-service-for-nodejs-app/feed/ 0
A simple javascript threading experiment with setTimeout https://www.dengnz.com/2019/09/11/a-simple-javascript-threading-experiment-with-settimeout/ https://www.dengnz.com/2019/09/11/a-simple-javascript-threading-experiment-with-settimeout/?noamp=mobile#respond Wed, 11 Sep 2019 03:13:18 +0000 https://www.dengnz.com/?p=2049 I am going to add a global queue object to my nodejs ex… 阅读更多 »A simple javascript threading experiment with setTimeout

The post A simple javascript threading experiment with setTimeout appeared first on 峰哥分享.

]]>
I am going to add a global queue object to my nodejs express program, then this raises a concern of thread safety.

I am implementing a queue with only 10 elements, the older elements will be throw away. So I wrote the following code to test.

In the following code, the if (queue.length > 10) can cause problem. Because when both thread run into this block and both finish pushing the element, we will have 12 elements in the queue.

For example
[12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

The new elements in this queue is 22, and 23.

Now thread 1 will do a slice and make the queue to be

[13, 14, 15, 16, 17, 18, 19, 20, 21, 22]

At this point, because the queue length is 10, then the thread 2 will not do the slice. The pushed element 23 is gone.

If thread 2 read the queue length before thread 1 slice it. Then thread 2 will slice it again.

the array become

[14, 15, 16, 17, 18, 19, 20, 21, 22]

Only 9 element in the queue, 13 is gone.


let queue = [];
let threads = 100000;
for (let i = 0; i < threads; i++) {
    setTimeout(() => {
        queue.push(i);
        // This line can have a dirty read
        if (queue.length > 10) {
            queue = queue.slice (1, 11);
        }

        if (i >= threads - 10) {
            console.log(queue);
        }
    }, 1000);
}

But when I tested this in the browser. it never failed. It’s very interesting.

A small improvement is using a temp variable to hold the original queue outside the if block, then use the temp var in the if block. It will make sure only 1 element will be missing.


let queue = [];
let threads = 100000;
for (let i = 0; i < threads; i++) {
    setTimeout(() => {
        queue.push(i);
       let tempQueue = queue;
        // This line can have a dirty read
        if (queue.length > 10) {
            queue = tempQueue.slice (1, 11);
        }

        if (i >= threads - 10) {
            console.log(queue);
        }
    }, 1000);
}

The post A simple javascript threading experiment with setTimeout appeared first on 峰哥分享.

]]>
https://www.dengnz.com/2019/09/11/a-simple-javascript-threading-experiment-with-settimeout/feed/ 0