批量拉取代码

场景:目录中有多个git项目,想要更新批量拉取一下这些项目的最新代码。

实现如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
for dir in $(ls -d */); do
cd $dir
if [ -d ".git" ]; then
branch=$(git symbolic-ref --short -q HEAD)
if [ "$branch" != "master" ]; then
echo "skip $dir branch: $branch"
else
echo "dir:$dir branch: $branch"
git pull origin $branch
fi
fi
cd ..
done

扫码目录下的所有项目,如果发现当前项目在master分支,那么pull一下代码。

MacOS安装PHP

偶然的机会需要用一下PHP,记录下安装方式。本身mac系统是自带php的,但是自带的修改起来及其不方便,不好安装扩展。所以直接使用brew安装。

brew安装php

1
2
3
4
brew search php  使用此命令搜索可用的PHP版本
brew install php@7.3.21 使用此命令安装指定版本的php
brew install brew-php-switcher 安装php多版本切换工具
brew-php-switcher 7.3.21 切换PHP版本到7.3.21(需要brew安装多个版本)

安装PHP扩展

1
2
3
4
5
pecl version 查看版本信息
pecl help 可以查看命令帮助
pecl search redis 搜索可以安装的扩展信息
pecl install redis 安装扩展
pecl install http://pecl.php.net/get/redis-4.2.0.tgz 安装指定版本扩展

群辉QNAP使用备忘

记录家里的群辉NAS使用备忘,防止忘记了。

IP

192.168.1.13

文件目录

实际文件目录在:/share/…

备忘

很多图片传重复了,抽空写个脚本判断下是否是重复文件,如果是重复的只保留一份就够了,节省磁盘空间,就判断文件的md5即可。

mac iterm2 rz与sz的功能

本文主要介绍mac环境下使用iterm2rz sz功能的安装流程。

1. 安装lrzsz

1
brew install lrzsz

2. 安装执行脚本

iterm2-send-zmodem.shiterm2-recv-zmodem.sh保存到/usr/local/bin目录下。

iterm2-send-zmodem.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
else
FILE=$(osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
fi
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
sleep 1
echo
echo \# Cancelled transfer
else
/usr/local/bin/sz "$FILE" --escape --binary --bufsize 4096
sleep 1
echo
echo \# Received "$FILE"
fi

iterm2-recv-zmodem.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
else
FILE=$(osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
fi

if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
sleep 1
echo
echo \# Cancelled transfer
else
cd "$FILE"
/usr/local/bin/rz --rename --escape --binary --bufsize 4096
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi

3. 赋予这两个文件可执行权限

1
chmod 777 /usr/local/bin/iterm2-*

4. 设置Iterm2的Tirgger特性

设置Iterm2的Tirgger特性,profiles->default->editProfiles->Advanced中的Tirgger

添加两条trigger,分别设置 Regular expression,Action,Parameters,Instant如下:

1
2
3
4
5
6
7
8
9
Regular expression: rz waiting to receive.\*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Instant: checked

Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
Instant: checked

示例图:

5. 使用

  • 上传文件:rz
  • 下载文件:sz + file

参考:

解决nvm加载慢的问题

为了图方便,我使用nvm安装的nodejs。后来发现每当打开terminal的时候都会很慢,开始不知道什么原因,后来分析了下才知道是nvm的锅。

其实我不是每次打开terminal都需要用到nvm,所以我将nvm修改为按需加载,需要的时候手动执行命令去加载,
我使用的是zsh,于是我修改了一下~/.zshrc文件:

修改前:

1
2
3
4
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

修改后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# nvm
export NVM_DIR="$HOME/.nvm"
# 本来每次启动terminal的时候都需要执行下面两行代码的
#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
function _install_nvm() {
unset -f nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This sets up nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # load nvm bash_completion
nvm "$@"
}

function nvm() {
_install_nvm "$@"
}

修改之后,不是每次启动都会去加载nvm.sh仅当需要的时候在terminal中执行一下nvm命令即可,修改之后terminal启动速度明显快了。

参看资料:https://github.com/nvm-sh/nvm/issues/539

在命令行中压缩图片

今天有需求将一些非常大的图片压缩一下,本来想自己写代码进行压缩的,但是觉得这是一个非常常见的需求,应该有现成的解决方案,于是Google了一下,找到了这两个工具:jpegoptim、optipng

安装

我是在MacOS中安装的,Linux上应该也有这个两个工具,请自行摸索

我使用的是brew进行安装,命令如下:

1
2
brew install jpegoptim
brew install optipng

jpegoptim 使用

1
2
3
4
5
6
7
8
# 压缩
jpegoptim file.jpg

# 指定大小压缩
jpegoptim --size=1024k file.jpg

# 移除Exif信息
jpegoptim --strip-exif file.jpg

optipng 使用

1
optipng file.png

mac下,mds_stores占用过高cpu,导致风扇狂转,怎么解决?

网上的以下方法,是不行的:

1
sudo mdutil -a -i off

运行了这一行,mds mds_stores等还是在20% 左右运行中

于是,发现了一个新方法,在终端运行这个:

1
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

等你想开的时候,在终端运行这个就行了:

1
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

哈哈,成功关闭后,世界都变流畅了!!!

相关文章:

https://www.jianshu.com/p/d76dbc097521

AndroidStudio连接mumu模拟器方法

启动mumu模拟器之后在设备列表中找不到模拟器,于是在网上搜索了下教程。

有个教程提供一下方法:

1
adb connect 127.0.0.1:7555 

附模拟器端口:

1
2
3
4
5
6
夜神模拟器:adb connect 127.0.0.1:62001
逍遥安卓模拟器:adb connect 127.0.0.1:21503
天天模拟器:adb connect 127.0.0.1:6555
海马玩模拟器:adb connect 127.0.0.1:53001
网易MUMU模拟器:adb connect 127.0.0.1:7555
原生模拟器:adb connect (你的IP地址):5555

但是这个方法在mac下好像不还用,于是又找到另外一种方法:

1
adb kill-server && adb server && adb shell

这个方法终于生效。

Centos安装mariadb-server

安装

1
yum install mariadb-server

注意:安装之后初始密码为空

常用命令

1
2
3
systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动

初始化

执行命令mysql_secure_installation进行初始化,过程中会让你设置root密码等信息,自己按照提示一步步来即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@iZj6chtv8h63huh6sbynuiZ ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!