Total Pageviews

Friday 31 January 2020

《57爆新聞》精選篇 武漢病毒震央「致命巧合」? 陸建「P4實驗室」別有用心?


TLDR 页-Linux 手册页的简化替代品

人们创建了手册页man page,(手册 —— man 是 manual 的缩写)。首先,它是用英文写成的,包含了大量关于不同命令的深入信息。有时候,当你在寻找命令的基本信息时,它就会显得有点庞杂。为了解决这个问题,人们创建了TLDR 页

什么是 TLDR 页?

TLDR 页的 GitHub 仓库将其描述为简化的、社区驱动的手册页集合。在实际示例的帮助下,努力让使用手册页的体验变得更简单。如果还不知道,TLDR 取自互联网的常见俚语:太长没读Too Long Didn’t Read。
如果你想比较一下,让我们以 tar 命令为例。 通常,手册页的篇幅会超过 1000 行。tar 是一个归档实用程序,经常与 bzip 或 gzip 等压缩方法结合使用。
而另一方面,TLDR 页面让你只是浏览一下命令,看看它是如何工作的。 tar 的 TLDR 页面看起来像这样,并带有一些方便的例子 —— 你可以使用此实用程序完成的最常见任务。
让我们再举一个例子,向你展示 TLDR 页面为 apt 提供的内容。

如何在 Linux 上安装和使用 TLDR 页?

最成熟的 TLDR 客户端是基于 Node.js 的,你可以使用 NPM 包管理器轻松安装它。如果你的系统上没有 Node 和 NPM,请先安装Nodejs环境。
现在,通过在终端中运行以下命令,在 Linux 机器上安装 TLDR 客户端:
npm install -g tldr 
一旦安装了此终端实用程序,最好在尝试之前更新其缓存。 为此,请运行以下命令:
tldr  --update 
执行此操作后,就可以阅读任何 Linux 命令的 TLDR 页面了。 为此,只需键入:
tldr   
你还可以运行其帮助命令,以查看可与 TLDR 一起使用的各种参数,以获取所需输出。 像往常一样,这个帮助页面也附有例子。

TLDR 的 web、Android 和 iOS 版本

你会惊喜地发现 TLDR 页不仅限于你的 Linux 桌面。 相反,它也可以在你的 Web 浏览器中使用,可以从任何计算机访问。
要使用 TLDR Web 版本,请访问 tldr.ostera.io 并执行所需的搜索操作。
或者,你也可以下载 iOS 和 Android 应用程序,并随时随地学习新命令。
你觉得这个很酷的 Linux 终端技巧很有意思吗? 请尝试一下,让我们知道您的反馈。

世界排箫大师赞菲尔,一曲《孤独的牧羊人》,台下观众潸然泪下


中国网上追究“隐瞒真相”的呼声越来越高,习近平“亲自指挥”的麻烦大了


唉,又是庚子年


fileboy,文件变更监听通知工具,使用 Go 编写


Build Status Go Report Card
适用于 Hot Reload (典型的如开发go项目,无需每次手动执行 go build;又比如前端 node 打包) 或者 系统监控的场景。

特性

  • 极简的用法和配置
  • 支持多平台,Windows/Linux/MacOS
  • 支持自定义文件监听范围,监听指定文件夹/不监听指定文件夹/指定后缀文件
  • 支持自定义监控事件(write/rename/remove/create/chmod)
  • 支持设置多条命令
  • 命令支持变量占位符
  • 支持冗余任务丢弃,自定义冗余任务范围
  • 支持 http 通知
  • 更多...

编译环境

go version 1.13

更新日志

运行

下载二进制文件

下载已经编译好的对应平台二进制文件,重命名为fileboy, 加入系统 Path 中即可。

源码编译

clone 该项目,进入主目录,运行命令:
## 安装依赖
go get -u gopkg.in/fsnotify/fsnotify.v1
go get -u gopkg.in/yaml.v2
## 编译
go build
## 运行
./fileboy

使用

fileboy 的正常运行依赖于 filegirl.yaml 配置文件,因此首次在项目中使用需要初始化 filegirl.yaml
  • 进入你想要 hot reload 的项目主目录下;
  • 运行 fileboy init,会在该目录下生成 filegirl.yaml文件;
  • 查看 filegirl.yaml,修改为适合自己项目的配置项;
  • 运行 fileboy即可.
如果你定义了 command -> exec命令,想事先确认是否能正常执行,可以运行 fileboy exec命令,系统会尝试运行你的自定义命令。
你可以使用 fileboy help查看使用帮助。

filegirl.yaml 配置文件说明

# 主配置
core:
    # 配置版本号
    version: 1

# 监控配置
monitor:
    # 要监听的目录
    # test1       监听当前目录下 test1 目录
    # test1/test2 监听当前目录下 test1/test2 目录
    # test1,*     监听当前目录下 test1 目录及其所有子目录(递归)
    # .,*         监听当前目录及其所有子目录(递归)
    includeDirs:
        - .,*

    # 不监听的目录
    # .idea   忽略.idea目录及其所有子目录的监听
    exceptDirs:
        - .idea
        - .git
        - .vscode
        - node_modules
        - vendor

    # 监听文件的格式,此类文件更改会执行 command 中的命令
    # .go   后缀为 .go 的文件更改,会执行 command 中的命令
    # .*    所有的文件更改都会执行 command 中的命令
    types:
        - .go

    # 监听的事件类型,发生此类事件才执行 command 中的命令
    # 没有该配置默认监听所有事件
    # write   写入文件事件
    # rename  重命名文件事件
    # remove  移除文件事件
    # create  创建文件事件
    # chmod   更新文件权限事件(类unix)
    events:
        - write
        - rename
        - remove
        - create
        - chmod

# 命令
command:
    # 监听的文件有更改会执行的命令
    # 可以有多条命令,会依次执行
    # 如有多条命令,每条命令都会等待上一条命令执行完毕后才会执行
    # 如遇交互式命令,允许外部获取输入
    # 支持变量占位符,运行命令时会替换成实际值:
    #    {{file}}    文件名(如 a.txt 、test/test2/a.go)
    #    {{ext}}     文件后缀(如 .go)
    #    {{event}}   事件(上面的events, 如 write)
    #    {{changed}} 文件更新的本地时间戳(纳秒,如 1537326690523046400)
    # 变量占位符使用示例:cp {{file}} /root/sync -rf  、 myCommand --{{ext}} {{changed}}
    exec:
        - go version
        - go env

    # 文件变更后命令在xx毫秒后才会执行,单位为毫秒
    # 一个变更事件(A)如果在定义的延迟时间(t)内,又有新的文件变更事件(B),那么A会取消执行。
    # B及以后的事件均依次类推,直到事件Z在t内没有新事件产生,Z 会执行
    # 合理设置延迟时间,将有效减少冗余和重复任务的执行
    # 如果不需要该特性,设置为 0
    delayMillSecond: 2000

# 通知器
notifier:
    # 文件更改会向该 url 发送请求(POST 一段 json 文本数据)
    # 触发请求的时机和执行 command 命令是一致的
    # 请求超时 15 秒
    # POST 格式:
    #    Content-Type: application/json;charset=UTF-8
    #    User-Agent: FileBoy Net Notifier v1.12
    #    Body: {"project_folder":"/project/path","file":"main.go","changed":1576567861913824940,"ext":".go","event":"write"}
    # 例: http://example.com/notifier/fileboy-listener
    # 不启用通知,请留空 ""
    callUrl: ""

TODO

  •  命令支持变量占位符
  •  支持多命令
  •  支持监听指定文件夹
  •  支持不监听指定文件夹
  •  支持监听指定后缀文件
  •  支持自定事件监听
  •  支持 http 通知
  •  支持冗余任务丢弃
  •  支持 http 合并任务的通知

QA

很多框架都自带了 hot reload 的功能,为什么还要单独写个 fileboy 呢?

这个是一款通用的 hot reload 的软件,理论上适用于任何需要 hot reload 的场景,并不局限于语言层面上。只要灵活的配置filegirl.yaml文件就行了

fileboy 可以应用在那些具体的场景?

在开发中,我们很需要一款可以帮助我们自动打包编译的工具,那 fileboy 就非常适合这样的场景。比如 go 项目的热编译,让我们可以边修改代码边运行得到反馈。又比如 PHP Swoole 框架,由于常驻进程的原因,无法更改代码立即reload,使用 fileboy 就可以辅助做到传统 PHP 开发的体验。
对于一些需要监控文件日志或者配置变动的场景, fileboy 同样适合。你可以事先编写好相应的通知报警脚本,然后定义filegirl.yaml中的command命令,交由 fileboy 自动运行监控报警。

通知器在什么时候会发送 http 请求 ?

通知器发送 http 通知的前提是在配置文件中设置了 callUrl 参数(不为空即为已设置)。触发请求的时机和执行 command 命令是一致的,command -> delayMillSecond 参数对于触发器同样有效。请求超时默认15秒.

idea 下更改文件,为什么会执行两次或者多次 command ?

由于 idea 系列软件特殊的文件保存策略,他会自动创建一些临时文件,并且在需要时多次重写文件,所以有时反映在文件上就是有多次的更改,所以会出现这种情况。1.5之后的版本增加了 delayMillSecond 参数,可以解决这个问题。

filegirl.yaml 里面的 command 如何配置复杂命令?

fileboy 目前支持 命令 + 参数这种形式的 command,而且 参数中不能有""符号或者有空格。如:
go build:支持;
go env:支持;
php swoole start --daemon:支持
cat a.txt | grep "q" | wc -l:不支持
对于不支持的命令,可以把它写到一个文件里,然后在 command 中执行这个文件来解决。

为什么起名为 fileboy,又把配置名叫做 filegirl ?

因为爱情~~ (◡ᴗ◡✿)

一个基于nodejs的记笔记的程序-Trilium Notes


Trilium Notes是一款开源的笔记应用程序,专注于建立大型个人知识库。支持树状笔记、笔记加密、全文搜索、自托管服务器,还可生成可视化笔记的关系图和链接图等。基于Javascript编写,遵守AGPL-3.0开源协议。

功能特色:

    笔记可整理成为树形结构,单个笔记可以放置到多个结构树中。
    富文本支持,包括表格,图片,markdown数据公式等
    支持编程代码高亮
    快速导航,全文搜索F
    无感的笔记历史版本记录
    笔记属性可用来组织,查询等功能
    同步笔记至自己的同步服务器
    共享/发布笔记至公共网络
    笔记加密功能,每个笔记可单独加密
    快速创建各种图表(笔记类型 “canvas”)
    笔记关系图谱
    支持脚本
    支持REST API自动化
    触控优化,支持手机,平板。
    暗夜主题模式Night theme
    支持Evernote和Markdown文件导入导出
    网页粘贴板

源码:https://github.com/zadam/trilium

------------------------------------------------

Build your personal knowledge base with Trilium Notes.

Join the chat at https://gitter.im/trilium-notes/Lobby 
Trilium Notes is a hierarchical note taking application with focus on building large personal knowledge bases.

Features

Builds

Trilium is provided as either desktop application (Linux and Windows) or web application hosted on your server (Linux). Mac OS desktop build is available, but it is unsupported.
  • If you want to use Trilium on the desktop, download binary release for your platform from latest release, unzip the package and run trilium executable.
  • If you want to install Trilium on server, follow this page.
    • Currently only recent Chrome and Firefox are supported (tested) browsers.

Documentation

You can also read Patterns of personal knowledge base to get some inspiration on how you might use Trilium.

Contribute

Use a browser based dev environment
Open in Gitpod
Or clone locally and run
npm install
npm run start-server

Shoutouts

  • CKEditor 5 - best WYSIWYG editor on the market, very interactive and listening team
  • FancyTree - very feature rich tree library without real competition. Trilium Notes would not be the same without it.
  • CodeMirror - code editor with support for huge amount of languages
  • jsPlumb - visual connectivity library without competition. Used in relation maps and link maps

---------------------------------------------------

Requirements

Trilium is a node.js application. Supported (tested) version of node.js is latest 14.X.X and 16.X.X. Trilium might work with older versions as well.

You can check your node version with this command (node.js needs to be installed):

node --version

If your Linux distribution has only an outdated version of node.js, you can take a look at the installation instruction on node.js website, which covers most popular distributions.

Dependencies

There are some dependencies required. You can see command for Debian and its derivatives (like Ubuntu) below:

sudo apt install libpng16-16 libpng-dev pkg-config autoconf libtool build-essential nasm libx11-dev libxkbfile-dev

Installation

Download

You can either download source code zip/tar from latest release or clone git repository from stable branch with

git clone -b stable https://github.com/zadam/trilium.git

Installation

cd trilium

# download all node dependencies
npm install

# make sure the better-sqlite3 binary is there
npm rebuild

Run

cd trilium

# using nohup to make sure trilium keeps running after user logs out
nohup TRILIUM_ENV=dev node src/www &

The application by default starts up on port 8080, so you can open your browser and navigate to http://localhost:8080 to access Trilium (replace "localhost" with your hostname).

TLS

Don't forget to configure TLS, which is required for secure usage!

from https://github.com/zadam/trilium/wiki/Manual-server-installation

------------------------------------------------------------------------------------

Desktop installation

If you want to use Trilium on the desktop, download binary release for your platform from latest release, unzip the package and run trilium executable.

Startup scripts

There are also some other options to start Trilium:

  • trilium-no-cert-check - Trilium will not validate the certificates, useful e.g. when you're syncing against a sync server with self-signed certificate
    • Alternatively you can set NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable to the Trilium process.
  • trilium-portable - Trilium will try to create data directory in the trilium's directory
  • trilium-safe-mode - start up in "safe mode" which disables any startup scripts which might e.g. crash the application

Synchronization

If you are using a desktop instance and would like to sync with your server instance: Synchronization.

from  https://github.com/zadam/trilium/wiki/Desktop-installation

 

 
 
 

年代向錢看 武漢肺炎重創中國芯!全球電子供應鏈大洗牌?蘋果、星巴克、麥當勞關中國門市?


武汉的“光谷”会变成鬼谷。唉,共匪啊,共匪,俺真觉得你快寿终正寝。

解决目录占用超大空间的问题

查找占用情况
$ df -h #查看磁盘占用情况
$ du -h --max-depth=1 ./ #查看当前目录的文件/目录占用大小
然后就是手动一层一层的找到最大的那个目录。
最后找到一个隐藏杀手:/var/spool/postfix/maildrop/。这个目录下面存在3000W个小文件,占用33GB。主要它还不是tmp之类的目录,没遇见过,真是很难查找。

究其原因是crontab任务日志发送到所有者的邮箱导致的问题

解决方案
方法1
编辑crontab顶部首行写上 MAILTO="",这样就会把邮箱信息赋空,也就不会发送了。

图片5030-linux查找maildrop目录超大空间占用

如果有非root用户的crontab任务也需要在顶部声明MAILTO="".
默认crontab -e是编辑的当前登录的用户定时任务配置,若是以root登录则为/var/spool/cron/root
同理www用户的定时任务文件就是/var/spool/cron/www

方法2
其次就是每条cron任务的最后把输出信息赋空 >/dev/null 2>&1

* * * * * /root/do.sh >/dev/null 2>&1

p.s.
记下以后排查的顺序:
web程序日志
nginx/apache日志
tmp
crontab 错误邮件发送日志
/var/spool/postfix/maildrop
/var/log 类型的log目录
/var/log/journal 启动目录的文件很多
...

参考:
https://www.jianshu.com/p/a0aa43707476
https://my.oschina.net/qimhkaiyuan/blog/1631028

基于Nodejs的博客程序:N-blog


使用 Express + MongoDB 搭建多人博客

开发环境

  • Node.js: 8.9.1
  • MongoDB: 3.4.10
  • Express: 4.16.2

目录