0%

准备

  • haxm

    intel开源的加速qemu驱动

  • tap-windows

    用于虚拟网卡

    创建新的虚拟网卡

    • tap-windows: Add a new Tap virtual ethernet adapter
    • 修改名字为tap0
    • 将本地连接(有网络)共享给tap0

创建虚拟机


1
2
3
4
5
6
7
8
## 创建盘
qemu-img create -f raw centos.img 30G

## 启动虚拟机
qemu-system-x86_64.exe -name test -m 2048 -machine accel=hax -net nic -net tap,ifname=tap0 -cdrom e:/download/CentOS-7-x86_64-Minimal-1810.iso .\centos.img
## -m 2048 设置内存
## -machine accel=hax 加速
## -net nic -net tap,ifname=tap0 网络设置,tap0为上面创建的虚拟网卡

使用hax后,启动速度会快很多
但在win下,与virtualbox(vagrant)相比,管理起来不是很方便,最终放弃

参考文档

  1. https://www.cnblogs.com/bingzhu/p/10746102.html

在备份个人资料的时候,zip文件解压时中文出现乱码
网上搜索获得三个解决方案:

  1. 使用unzip -O选项
    但是大部分的发行版中的unzip软件都没有这个参数,至少debian是没有的

  2. 安装unzip-iconv
    源中都搜索不到这个软件

  3. 使用unar替代unzip(正确方案)

    1
    2
    sudo apt install unar
    unar -e utf8 xxx.zip

问题

今天看到一个mysql行转列的问题

表1 转换为 表2

表1

year month amount
2011 1 1.1
2011 2 1.2
2011 3 1.3
2011 4 1.4
2012 1 2.1
2012 2 2.2
2012 3 2.3
2012 4 2.4

表2

year m1 m2 m3 m4
2011 1.1 1.2 1.3 1.4
2012 2.1 2.2 2.3 2.4
阅读全文 »

erlang函数返回的几种方式

case

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case A of
true ->
case B of
true ->
case C of
true ->
ok;
false ->
error
end;
false ->
error
end;
false ->
error
end.

如果判断很多的话, 那么代码可读性就太差了

if

1
2
3
4
5
6
if
A -> ok;
B -> ok;
C -> ok;
true -> error
end

虽然代码看起来规整了,但是变量A,B,C必须先算出结果
性能是个问题

catch-1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
test() ->
catch test_f1().
test_f1() ->
case A of
false -> throw(error);
_ -> ok
end,
case B of
false -> throw(error);
_ -> ok
end,
case C of
false -> throw(error);
_ -> ok
end.

如果test_1/0存在逻辑报错,也会被catch
需要手动在test/0再加判断

catch-2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

-define(RETURN(Ret), throw({catch_return, Ret})).
-define(CATCH(A), mycatch(catch (A))).

mycatch({catch_return, Ret}) -> Ret;
mycatch({'EXIT', _Ret} = Catch) -> throw(Catch);
mycatch(Ret) -> Ret.

test() ->
?CATCH(
begin
case A of
false -> ?RETURN(error);
_ -> ok
end,
case B of
false -> ?RETURN(error);
_ -> ok
end,
case C of
false -> ?RETURN(error);
_ -> ok
end
end).

个人感觉这个比较好
catchcatch
throw的也throw

安装

1
yum install autojump

CENTOS/LINUX使用

安装后,重新打开终端,或执行source etc/profile.d/autojump.sh才可使用
在使用j xxxx前,要先cd xxx/xxxx一次
然后就可以愉快的使用j xxxx进行跳转了

查看记录/配置文件: j --stat

WIN使用

autojumpWINDOWS没有安装成功,而且个人习惯使用PowerShell

PowerShell下有一个替代者

1
2
3
4
Install-Module ZLocation -Scope CurrentUser

cd xxxx
z xxxx

使用方法和autojump类似,只是j换成了z

查看记录: Get-ZLocation
配置文件: C:\Users\Administrator\z-location.txt

参考文档

  1. https://github.com/vors/ZLocation.git
  2. https://github.com/wting/autojump.git
  3. https://github.com/vors/ZLocation/pull/42

自己写了一个rebar3插件,用于格式化代码,基于erl_tidy
链接地址: rebar3_plugin_fmt
无意中发现一个宏定义的问题

源代码:

1
-define(CALC_PERIOD_RATE, 0.6). %% 权重概率

格式化后代码:

1
-define(CALC_PERIOD_RATE, 5.99999999999999977796e-1). %% 权重概率

因此,若是小数, 请使用(6/10)这种格式

安装

1
2
3
4
5
6
7
8
9
10
11
## 
git clone https://github.com/rofl0r/proxychains-ng
## 自行选择版本
git checkout -b v4.13

cd proxychains-ng
./configure --prefix=/usr --sysconfdir=/etc
make
make install
## 生成配置文件
make install-config

配置

1
2
3
4
5
6
7
8
9
10
11
vim /etc/proxychains.conf

dynamic_chain
proxy_dns
localnet 127.0.0.0/255.0.0.0
localnet 10.0.0.0/255.0.0.0
localnet 172.16.0.0/255.240.0.0
localnet 192.168.0.0/255.255.0.0

[ProxyList]
socks5 192.168.70.71 1080

运行

proxychains4 git clone https://github.com/rofl0r/proxychains-ng

问题

  1. 不是所有的都能够代理,至少ping就不行(据说是不支持对icmp代理)

参考文档

  1. https://www.hi-linux.com/posts/48321.html