利用Git Hook实现服务器端文件提交大小限制

利用git hooks,在服务器端每次接收到push的时候进行文件信息检查,若超过限制则拒绝提交。 具体实现:在update hook中对提交的文件进行检查,利用git log命令查询所有新提交的分支,利用git cat-file 命令递归查询文件树、查询文件大小,若超限则返回1拒绝提交。 #!/bin/bash # # An example hook script to block unannotated tags from entering. # Called by "git receive-pack" with arguments: refname sha1-old sha1-new # # To enable this hook, rename this file to "update". # # Config # ------ # hooks.allowunannotated # This boolean sets whether unannotated tags will be allowed into the # repository. By default they won't be. # hooks.allowdeletetag # This boolean sets whether deleting tags will be allowed in the # repository....

May 7, 2022 · 3 min · Andyliu

Debug golang program in vscode

Basic config install delve use debug config template in vscode Debug with stdin input The default delve debug mod doesn’t support stdin input. To tackle this issue, use the method of launching a delve debug server and attach program to debug server instead. tasks.json { "tasks": [ { "label": "Delve debug server", "type": "shell", "command": "cd \"${fileDirname}\" && source /etc/profile && ~/go/bin/dlv debug --headless --listen=:2346 --api-version=2", "problemMatcher": [], "group": { "kind": "build", "isDefault": false } } ], "version": "2....

May 1, 2022 · 1 min · Andyliu

Linux环境下使用vscode进行c/c++语言debug

VScode中debug运行逻辑概述 工作区 VScode由两种运行模式:单文件打开模式和文件夹打开模式。界面上最明显的区分是VScode底部的颜色条如果是紫色的,说明在单文件打开模式,如果为天蓝色,即处于文件夹打开模式。 在文件夹打开模式下,左侧文件浏览器界面可以看到当前文件夹路径下的所有文件以及文件夹。这个所谓的“当前文件夹路径”在VScode中被称为“工作区路径”。如果不清楚当前的工作区路径,在VScode中新建——注意不是显示之前隐藏的终端——一个终端后所处在的路径就是当前的工作区路径,由VScode自动帮你切换好了。可以在打开后不更改路径的情况下使用pwd命令打印当前的绝对路径。 Debug相关配置文件 以${workspaceFolder}表示当前工作区文件夹,则与这个工作区相关的所有VScode的配置文件都放在${workspaceFolder}/.vscode文件夹下,若要进行c语言程序的debug,需要用到两个文件: launch.json 这个文件里面记录的是与debug直接相关的配置,包括debug任务名称、debug程序(c语言对应gdb)、相关参数等等。对于python这种不需要编译的解释性语言,仅用这个文件就够了。但是c语言是编译型语言,在调用gdbdebug之前还需要调用gcc进行编译,对应到launch.json里面就要配置一个参数"preLaunchTask",里面调用接下来要说的tasks.json文件里的配置进行编译。 tasks.json 这个文件就是一些常用任务的配置,写成配置文件后就可以一键运行,而不用每次都敲繁琐的命令行了。在debug的相关配置中常用来填写编译(build)任务的相关配置,里面可以指定使用的编译器、使用的语言版本、编译参数等等。 debug相关设置以及快捷键 F5在debug启动前为“启动debug”命令,在debug启动后为“继续”命令(继续运行直到遇到下一个断点暂停) F9在光标所在的行设置断点 F10下一步,遇到函数不会进入 F11下一个语句,遇到函数会进入函数 shift + F11单步跳出,即执行完当前函数并返回后暂停程序 shift + F5停止debug 或者在遇到断点后点击debug工具栏里的按钮也可以 有可能启动debug之后弹出的终端界面在debug console中,而非terminal中,此时进行的输入不会被引导到stdin中,而是会交给调试器。点击下图中红框圈起来的terminal(中文翻译应该是“终端”)即可回到正常的终端,此时进行的输入将直接进入stdin交给程序。 更多进阶玩法参见微软官方文档 一次C语言Debug的流程(配合下文给出的配置) 在左侧的debug面板中选择debug任务名称(由于下文给出的配置中实际上只含有1个配置,会被默认选中,这步可以被跳过。但是如果有多个debug配置则需要先选中一个。) 打开含有main函数的c语言源文件,待会编译的时候默认当前打开的文件中含有main函数 摁下F5键,启动一个debug流程 vscode按照选择的任务名称读取${workspaceFolder}/.vscode/launch.json文件,发现里面有参数"preLaunchTask" 于是vscode调用${workspaceFolder}/.vscode/tasks.json文件中指定的编译任务,调用gcc完成c程序的编译 完成编译后,vscode继续按照${workspaceFolder}/.vscode/launch.json文件中定义的debug配置调用gdb启动debug过程 程序遇到断点后暂停,此时可以在左侧debug面板中查看变量、调用栈等等信息 按下弹出的debug工具栏最右侧的红色方块停止debug 配置文件 windows和linux下的配置文件有所不同,请根据运行环境选择。在写入配置文件前请确认在终端中可以正常使用gcc和gdb命令。 Linux tasks.json { "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc build active file", "command": "/usr/bin/gcc", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "-lpthread" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": ["$gcc"], "group": "build", "detail": "compiler: /usr/bin/gcc" } ], "version": "2....

April 30, 2022 · 2 min · Andyliu

Config Raspi after Reinstallation

Download system and write disk 64-bit Raspi images 64-bit Full Raspi images Enable SSH create empty file named ssh under the disk named boot Connecting wifi for the 1st time create wpa_supplicant.conf under disk named boot, write followings: country=CN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="<wifi name>" psk="<wifi passwd>" key_mgmt=WPA-PSK } then, plug the SD card to pi and start the pi. You should be able to connect to Pi using SSH....

January 29, 2022 · 1 min · Andyliu

Offline TTS

TTS by Mozilla Using open source code https://github.com/mozilla/TTS.git Direct Installation TTS supports python >= 3.6, <3.9. If you are only interested in synthesizing speech with the released TTS models, installing from PyPI is the easiest option. pip install TTS If you plan to code or train models, clone TTS and install it locally. git clone https://github.com/mozilla/TTS pip install -e . Custom installation However, the version is lower in github than in Pypl, losing many models and features....

January 29, 2022 · 1 min · Andyliu

树莓派更换镜像源

更换为清华镜像源,参考清华Raspbian 镜像使用帮助 对于Debian 11 (bullseye): # 编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代: deb [arch=armhf] http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi # 如果需要 arm64 软件源,在 `/etc/apt/sources.list` 中加上 deb [arch=arm64] http://mirrors.tuna.tsinghua.edu.cn/raspbian/multiarch/ bullseye main # 编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代: deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main 保存后运行sudo apt-get update 运行后出现 W: GPG error: http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian bullseye InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 9165938D90FDDD2E 需要手动添加公钥:sudo apt-key adv --keyserver keyserver....

January 29, 2022 · 1 min · Andyliu

Configuring FTP server on raspberry

Install vsftpd on raspberry: sudo apt-get install vsftpd Config vsftpd sudo nano /etc/vsftpd.conf Simplest config: anonymous_enable=NO 匿名帐号 local_enable=YES 本地帐号 write_enable=YES 允许使用任何可以修改文件系统的FTP的指令 local_umask=022 屏蔽权限即本地用户上传的文件权限 anon_upload_enable=NO 允许匿名用户上传文件 anon_mkdir_write_enable=NO 允许匿名用户创建新目录 dirmessage_enable=YES 允许为目录配置显示信息 ascii_upload_enable=YES 管控是否可用ASCII 模式上传 ascii_download_enable=YES 管控是否可用ASCII 模式下载 others: anonymous_enable=YES 是否允许匿名帐号 local_enable=YES 是否允许本地帐号 write_enable=YES 是否允许使用任何可以修改文件系统的FTP的指令 local_umask=022 本用户的文件掩码 anon_upload_enable=YES是否允许匿名用户上传文件 anon_mkdir_write_enable=YES是否允许匿名用户创建新目录 dirmessage_enable=YES 是否显示欢迎信息 xferlog_enable=YES 开启日记功能 connect_from_port_20=YES 设定ftp服务数据端口 chown_uploads=YES是否允许修改上传文件的属主 chown_username=whoever如果允许,输入该属主的用户名 xferlog_file=/var/log/xferlog日志文件位置 xferlog_std_format=YES 使用标准的日志格式 idle_session_timeout=600空闲连接超时 data_connection_timeout=120数据传输超时 nopriv_user=ftpsecure当服务器运行于最底层时使用的用户名 async_abor_enable=YES是否允许使用\"async ABOR\"命令,一般不用,容易出问题 ascii_upload_enable=YES是否可用ASCII 模式上传。默认值为NO ascii_download_enable=YES是否可用ASCII 模式下载。默认值为NO ftpd_banner=Welcome to blah FTP service login时显示欢迎信息 deny_email_enable=YES如果匿名用户需要密码,那么使用banned_email_file里面的电子邮件地址的用户不能登录 banned_email_file=/etc/vsftpd/banned_emails禁止使用匿名用户登陆时作为密码的电子邮件地址 chroot_list_enable=YES如果启动这项功能,则所有列在chroot_list_file中的使用者不能更改根目录 chroot_list_file=/etc/vsftpd/chroot_list定义不能更改用户主目录的文件 userlist_enable=YES 若启用此选项,userlist_deny选项才被启动 unfinished....

January 6, 2022 · 1 min · Andyliu

Configuring rclone in Windows

Install Rclone rclone download link rclone relies on winfsp to work winfsp download link install winfsp unzip downloaded rclone files config path: add the path where rclone.exe is in. check rclone config state:rclone --version Config rclone drives git bash is recommended for mounting drives Add a remote rclone config and follow the interactive config process Mount remote as a disk rclone mount Pi:/ Q: --cache-dir "C:\Users\liush\Documents\rclone_cache" --vfs-cache-mode writes

January 6, 2022 · 1 min · Andyliu

树莓派挂载onedrive

Steps: install rclone: sudo apt install rclone authorize onedrive: rclone authorize "onedrive" log into onedrive in the prompted page. access token will be generated. copy and remember access token. config rclone clients: rclone config this will leads to an interactive configuration process check config: rclone config show mount to local dir: rclone mount <remote name>: <local dir>

December 28, 2021 · 1 min · Andyliu

Git Notes

Delete branchs local: git branch -d <localBranchName> remote: git push origin --delete <remoteBranchName>

December 22, 2021 · 1 min · Andyliu