编程相关杂项记录

发布于 2022-10-02  583 次阅读


Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

统计代码行数

powershell (win 10):

不统计空格

find . -name "*.py"|xargs cat|grep -v ^$|wc -l

不统计注释 (需要修改)

bash
# exclude the lines begin with #
find . -name "*.py"|xargs cat|grep -v -e ^-e ^\s*#.*|wc -l

这里需要注意的是,注释行未必就以//作为开头,可能N个空格之后才开始的的//,所以匹配时需要加上上面的^\s*放在开头。

原文:
一句shell命令搞定代码行数统计_watl0的博客-CSDN博客

Notepad ++

  1. 正则替换全部空行:^(\s*)\r\n
  2. 查看剩余行:\r\n

统计代码行数_missingMuMu的博客-CSDN博客_notepad统计代码行数
注释依然需要手动删除。

git下统计代码

  1. 显示项目的所有文件列表及行数(已删除的文件显示为空)
    最后一行会显示项目代码的总行数

    git ls-files | xargs wc -l
    
  2. 只统计项目代码的总行数
    git ls-files | xargs cat | wc -l
    
  3. 只查看项目文件列表
    git ls-files
    

gcc (MinGW64安装)

How To Install MinGW 64 Bit Windows 7 10 11 C C++ Fix File Has Been Downloaded Incorrectly! Error - YouTube

MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net

新版可以到如下链接下载(该版本暂未测试)
About | tdm-gcc

  • 下载
  • 解压到c盘
  • 添加环境变量到path (可以手动输入,但在文件浏览器中复制路径到环境变量不容易出错)。
  • 测试
gcc --version

编译

//main.cpp
// Your First C++ Program
#include 

int main() {
    std::cout << "Hello World!";
    return 0;
}

直接使用如下编译

g++ main.cpp

使用gcc的话需要指定标准库

gcc info.C -lstdc++

建议使用g++.

生成dll库

MinGW gcc 生成动态链接库 dll 的一些问题汇总_liyuanbhu的博客-CSDN博客

VS code安装及使用

Installing MinGW Compiler for VSCode on Win 10 x64 - YouTube

Visual Studio Code 如何编写运行 C、C++ 程序? - 知乎

该文内容有参考价值,但是如果仅仅属于编程学习的起步阶段,直接使用VS code的Terminal调用g++编译cpp或者调用gcc编译c文件即可,不需要复杂的配置。在需要相关的内容时再渐进式学习配置方法即可。

git

修改提交人名称及邮箱

Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

git config --global --edit

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

shell 命令

遍历文件夹并对文件进行操作

#!/bin/sh
cd {0%/*} || exit 1    # Run from this directory

for file in ./*
do
    if test -dfile
    then
        cp ./Allclean ./file/Allclean
        cp ./PyFoamFileClean.py ./file/PyFoamFileClean.py
    fi
done

参考:shell编程--遍历目录下的文件 - jihite - 博客园

届ける言葉を今は育ててる
最后更新于 2023-11-28