Git Code Snippet

建立独立的分支 当想在项目中使用一个独立分支进行项目文档的管理时,或者当我们想要发布一个软件的开源版本但又不希望将软件的版本历史暴露给外界时,都可以使用以下的方法建立一个独立分支: git help checkout # git checkout --orphan <new-branch> <start-point> 修改提交时间 # 指定本次提交时间 git commit -m "fix..." --date=`date -R` git commit -m "fix..." --date="$(date -R)" git commit -m "fix..." --date="Tue, 11 Jun 2019 17:50:50 +0800" # 修改上次提交时间 git commit --amend --date=`date -R` # 风险操作。会修改 history hash. 忽略文件权限修改 # Git 默认会记录文件权限的修改,可关闭 git config core.filemode false git status 中文文件名乱码 git config --global core.quotepath false 当 core.quotepath 设置为 false 时,Git 将不会对路径名进行 quoting,这意味着路径名中的特殊字符将不被转义。 Git 中文显示问题解决 工作区中删除未跟踪的文件 # 查看文档 git help clean git clean -h # git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] [<pathspec>...] # 【查看】有哪些文件将被删除 git clean -n # 【查看】删除 Git【忽略】的文件与文件夹 git clean -Xn # 【查看】删除【src 路径下】下的【未跟踪】文件以及文件夹 git clean -d -- src # 如果想执行删除 -n 替换为 -f,注意风险。 Git 清除未跟踪文件 | github.io ...

October 1, 2022 · 1 min · 173 words · Me

MySQL 实战 45 讲 Part2

MySQL 实战 45 讲 | 林晓斌

September 14, 2022 · 1 min · 6 words · Me

MySQL 实战 45 讲 Part1

MySQL 实战 45 讲 | 林晓斌 01 | 基础架构:一条 SQL 查询语句是如何执行的? 连接器:跟客户端建立连接、获取权限、维持和管理连接。 SHOW PROCESSLIST; 137462239 db 10.135.4.7:41261 db Query 0 starting show processlist -- 一个空闲连接 137462293 db 10.130.128.1:47174 db Sleep 24 -- 客户端如果太长时间没动静,连接器就会自动将它断开 select @@wait_timeout; show variables like 'wait_timeout'; -- 28800 8h 通过执行 mysql_reset_connection 来重新初始化连接资源,这是个接口函数,不是一个 SQL 语句。 查询缓存:不建议使用。在一个表上有更新的时候,跟这个表有关的查询缓存都会失效。 select @@query_cache_type; -- OFF sysvar_query_cache_type | mysql 分析器:词法分析、语法分析。进行分词和验证语法规则。解析器和预处理器。 解析器处理语法和解析查询,生成一课对应的解析树。 预处理器进一步检查解析树的合法。比如: 数据表和数据列是否存在,别名是否有歧义等。如果通过则生成新的解析树,再提交给优化器。 优化器:决定使用哪个索引,决定各个表的连接顺序。 执行器:有没有执行查询的权限,操作引擎,返回结果。执行器调用的次数(rows_examined)与引擎总共扫描行数可能是不等的,后文有例子。 读写、存取数据在 engine 引擎层,连接、鉴权、计算在 server 服务层。 ...

August 14, 2022 · 6 min · 1198 words · Me

Shell Code Snippet

Package Management Find Packages with pkgs.org pkgs.org is a Linux package search website that helps you find software packages for various Linux distributions. # Check installed package versions (Red Hat/CentOS) rpm -qa | grep docker Process Management Run Commands in Background # Run in background (will stop when terminal closes) cmd & # Run in background (continues after terminal closes) nohup cmd & Control Background Jobs Ctrl + Z - Pause the current foreground job and move it to background jobs - List all background jobs (jobs -l shows PIDs) fg - Bring the most recent background job to foreground fg %N - Bring job number N to foreground bg - Resume the most recent job in the background bg %N - Resume job number N in the background Using fg Command # Restore the most recent background job fg # Restore a specific job by number fg 1 # Restore using % syntax fg %2 # Restore by process name fg %vim # List all background jobs jobs DNS Operations Lookup CNAME Records CNAME (Canonical Name) records map one domain name to another, commonly used for subdomains or third-party hosted services. ...

July 28, 2022 · 4 min · 754 words · Me

Front-end Code Snippet

库推荐 nrm Pana/nrm nrm can help you easy and fast switch between different npm registries, now include: npm, cnpm, taobao, nj(nodejitsu). npm install -g nrm nrm ls nrm use tencent Website W3Techs - World Wide Web Technology Surveys nodejs release schedule 安装 Node.js 推荐使用 proto 安装管理 Node.js。proto 是一个现代化的多语言版本管理工具,支持 Node.js、Bun、Deno、Go、Rust 等多种语言运行时。 安装 proto # macOS / Linux curl -fsSL https://moonrepo.dev/install/proto.sh | bash # Windows irm https://moonrepo.dev/install/proto.ps1 | iex 安装完成后重启终端或执行 source ~/.bashrc(或对应的 shell 配置文件)。 ...

July 26, 2022 · 2 min · 349 words · Me

GROUP_CONCAT 截断

今日在生产环境发生了:因为 GROUP_CONCAT 聚合的数据列发生截断导致异常,原来 GROUP_CONCAT 是有大小限制的。 SELECT @@GROUP_CONCAT_MAX_LEN; -- 1024 bytes References group_concat_max_len | mysql – EOF –

January 10, 2022 · 1 min · 17 words · Me

回顾 2021

直到对的人来 · 追星族乐队 我想跟他说:那家餐厅太美了,我一定要和你去一次。但是那个菜其实很一般的,那个老板娘戴的耳环特别漂亮。 – EOF –

December 31, 2021 · 1 min · 7 words · Me

PHP 安装 gRPC

ENV cat /etc/redhat-release CentOS Linux release 7.2 (Final) uname -a Linux xxx-xxx 3.10.107-1-tlinux2_kvm_guest-0052 #1 SMP Wed Jan 15 18:42:19 CST 2020 x86_64 x86_64 x86_64 GNU/Linux PECL pecl install grpc 如果遇到: Connection to `ssl://pecl.php.net:443′ failed: 参考: PHP Swoft 框架环境配置 | ZYF.IM Build 通用手动安装 PECL 扩展 For this to work, you’ll need to have root access to your server, and you’ll most probably need developer tools installed as well. https://pecl.php.net/ # 创建临时目录 mkdir /tmp/download/ && cd /tmp/download/ # 下载 wget http://pecl.php.net/get/[extension].tgz # 解压 tar -xvf [extension].tgz cd [extension] # 配置 phpize # 查看参数 ./configure --help # 设置参考 以实际情况为准 ./configure --enable-[extension] # 编译 make && make test # 安装 make install # 查看 ini 路径 php --ini # 开启 vi [php-ini].ini extension=[extension].so gcc is currently not installed yum install gcc ...already installed and latest version... gcc ...gcc is currently not installed. yum reinstall gcc # 重新安装后解决 GrpcLb::TokenAndClientStatsAttribute::ToString() const 原因:gcc 版本过低。 ...

October 13, 2021 · 1 min · 175 words · Me

分组聚合 OVER PARTITION BY

在 HIVE 中 最近在使用 HIVE,需要统计 当年累计和 这样的指标,请教同事后发现了 OVER(PARTITION BY) 开窗函数。 分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返回多行,而聚合函数对于每个组只返回一行。 开窗函数指定了分析函数工作的数据窗口大小,这个数据窗口大小可能会随着行的变化而变化。 测试语句: CREATE TABLE default.test_over_partition ( `fdate` Date, `year` Int, `month` Int, `category1` String, `category2` String, `income` Double ); INSERT INTO hdp_fin_dash_ods.test_over_partition (`fdate`,`year`,`month`,`category1`,`category2`,`income`) VALUES ('2020-01-01',2020,1,'3C','电脑','1010'), ('2020-01-01',2020,1,'3C','手机','1011'), ('2020-02-01',2020,2,'3C','电脑','1012'), ('2020-02-01',2020,2,'3C','手机','1013'), ('2020-03-01',2020,3,'3C','电脑','1014'), ('2020-03-01',2020,3,'3C','手机','1015'), ('2021-04-01',2021,4,'3C','电脑','1016'), ('2021-04-01',2021,4,'3C','手机','1017'), ('2021-05-01',2021,5,'3C','电脑','1018'), ('2021-05-01',2021,5,'3C','手机','1019'); -- 查询每年每 category2 日累计 income SELECT `fdate`,`year`,`month`,`category1`,`category2`,`income` ,SUM(income) OVER (PARTITION BY `year`,`category1`,`category2` ORDER BY fdate) AS ttl_year_income FROM hdp_fin_dash_ods.test_over_partition; 在 MySQL 中 Before MySQL 8.0 you can’t use window functions like ROW_NUMBER. ...

September 14, 2021 · 1 min · 97 words · Me

PHP __invoke 使用

why they are magic? Because they are magically called by PHP when specific actions happen. The __invoke() method is called when a script tries to call an object as a function. <?php class CallableClass { public function __invoke($x) { var_dump($x); } } $obj = new CallableClass; $obj(5); var_dump(is_callable($obj)); int(5) bool(true) 使用明显的操作方法初始化 例如,当我们有一个提供者时,就会发生这种情况。 aws-sdk-php/src/Endpoint/PatternEndpointProvider.php public function __invoke(array $args = []) { $service = isset($args['service']) ? $args['service'] : ''; $region = isset($args['region']) ? $args['region'] : ''; $keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"]; foreach ($keys as $key) { if (isset($this->patterns[$key])) { return $this->expand( $this->patterns[$key], isset($args['scheme']) ? $args['scheme'] : 'https', $service, $region ); } } return null; } 它使用 invoke 使用一些参数提供端点。我们如何使用这个类? ...

July 20, 2021 · 2 min · 305 words · Me