情文のBLOG

记录点点滴滴

问题

今天看到一个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

目前项目中将record结构转换为KVList, 然后保存到mongodb中
由于record_info(fields,Record)不支持传入参数,处理从record转换为kvlist比较麻烦

阅读全文 »

Erlang项目,其他成员使用Idea开发,唯独我使用vim开发
并不是自己zhuangbility,试着转过去,各种不舒服,再转一次

阅读全文 »
0%