我在知乎回答問題不多,這個問題: "
對你職業生涯幫助最大的習慣是什么?它是如何幫助你的?",我還是主動回答了一下.
做筆記記憶是靠不住的,會自然淘汰長時間不用的數據,一旦需要重新加載,如果從0開始那成本就太高了,而筆記和思維導圖是自己思考方式的組織的,可以快速加載;
- 一開始筆記軟件做的不好的時候就發郵件給自己,然后不斷的回顧更新筆記;
- 后來用OneNote,由於這玩意當時不是雲同步的,硬盤壞掉的時候丟了一些數據,打擊還是挺大,好多事情要從頭開始
- 再后來用過一段時間Google Wave,還以和朋友分享討論筆記,結果,你們知道關閉服務了,費力導出來
- 現在轉戰Evernote和思維導圖Conceptdraw
我一直認為"做筆記"對於我這種資質平庸的人是一個非常有威力的武器,加上經常性的回顧更新,能夠看到自己能力成長過程,能夠幫我把一個宏大的目標變成一件件具體的事情.經常的回顧可以讓我把一個個知識點融入到自己的知識體系中.胡適先生說功不唐捐,但願如此.
下面這些內容零零散散記錄了很久,當時記錄的時候可能還是新東西,過了那么久新東西也都成常識了,算不得"新"了;刪之可惜,繼續放在Erlang雜記里面吧,無論如何都是一個知識積累的記錄;另外,分享記錄還可以發現盲點,比如下面代碼就是我曾經的盲點之一,我曾經使用非常繞的方法解決ETS進程依賴Shell進程的問題,很快就有朋友指出其實只需要執行下catch_exception(true)就可以搞定.
Eshell V6.0 (abort with ^G) 1> self(). <0.33.0> 2> 1/0. ** exception error: an error occurred when evaluating an arithmetic expression in operator '/'/2 called as 1 / 0 3> self(). %% 注意這里 已經重啟 <0.36.0> 4> catch_exception(true). false 5> 1/0. * exception error: an error occurred when evaluating an arithmetic expression in operator '/'/2 called as 1 / 0 6> self(). <0.36.0> 7>
比起"你應該知道的XX","你必須知道的XX","原來你不知道XX","XX原來可以這樣用","你可能不知道的XX",這些名字,"Erlang雜記"這個不招搖的名字能讓我們更關注內容而不是糾結於"誰說我不知道了,你才不知道呢,就你知道",當然了
"XX的76個原則"這種偽裝人生導師頤指氣使的雞湯標題就更惹人厭了.
ETS 數據壓縮
版本: R14B01 ERTS5.8.2
compressed If this option is present, the table data will be stored in a more compact format to consume less memory. The downside is that it will make table operations slower. Especially operations that need to inspect entire objects, such as match and select, will get much slower. The key element is not compressed in current implementa
如果使用了compressed選項,表數據在內存中會更緊密的排列,占用更少的內存.代價就是一些操作變慢,比如match,select.另外,因為壓縮本身的開銷,數據量不大的情況下做壓縮可能適得其反,下面的第一個例子就是這樣,test2表在壓縮之后占用內存反而多了.目前的版本中Key沒有做壓縮.
官方曾表示對於復雜數據可以達到50%甚至更高的壓縮比.如果全局應用壓縮策略可以使用
erl +ec
Eshell V6.0 (abort with ^G) 1> catch_exception(true). false 2> ets:new(test,[named_table]). test 3> [ ets:insert(test,{N,1,1,2}) || N <- lists:seq(1,10) ]. [true,true,true,true,true,true,true,true,true,true] 4> 4> ets:info(test). [{compressed,false}, {memory,389}, {owner,<0.33.0>}, {heir,none}, {name,test}, {size,10}, {node,nonode@nohost}, {named_table,true}, {type,set}, {keypos,1}, {protection,protected}] 5> ets:new(test2,[named_table,compressed]). test2 6> [ ets:insert(test2,{N,1,1,2}) || N <- lists:seq(1,10) ]. [true,true,true,true,true,true,true,true,true,true] 7> 7> ets:info(test2). [{compressed,true}, {memory,399}, {owner,<0.33.0>}, {heir,none}, {name,test2}, {size,10}, {node,nonode@nohost}, {named_table,true}, {type,set}, {keypos,1}, {protection,protected}]
Eshell V6.0 (abort with ^G) 1> catch_exception(true). false 2> ets:new(t,[named_table]). t 3> [ ets:insert(t,{N,[1,1,2],[a,b],{2,1,1024}}) || N <- lists:seq(1,100000) ]. [true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true|...] 4> ets:info(t). [{compressed,false}, {memory,2314637}, {owner,<0.33.0>}, {heir,none}, {name,t}, {size,100000}, {node,nonode@nohost}, {named_table,true}, {type,set}, {keypos,1}, {protection,protected}] 5> ets:new(t2,[named_table,compressed]). t2 6> [ ets:insert(t2,{N,[1,1,2],[a,b],{2,1,1024}}) || N <- lists:seq(1,100000) ]. [true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true|...] 7> [ ets:insert(t2,{N,[1,1,2],[a,b],{2,1,1024}}) || N <- lists:seq(1,100000) ]. [true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true,true,true,true,true,true,true, true,true,true,true,true,true|...] 8> ets:info(t2). [{compressed,true}, {memory,1414637}, {owner,<0.33.0>}, {heir,none}, {name,t2}, {size,100000}, {node,nonode@nohost}, {named_table,true}, {type,set}, {keypos,1}, {protection,protected}] 9>
檢查是否有舊版本的代碼
R14B04 Erts 5.8.5 添加
-module(a). -compile(export_all). v()-> 1.0. Eshell V6.0 (abort with ^G) 1> c(a). {ok,a} 2> a:v(). 1.0 3> c(a). %% 代碼已經修改過了 {ok,a} 4> erlang:check_old_code(a). true 5> a:v(). 2.0 6>
erlang:external_size
R14B04 Erts 5.8.5 添加
erlang:external_size(Term) -> integer() >= 0
7> B= <<"binary_test_demo">>. <<"binary_test_demo">> 8> erlang:external_size(B). 27 9> byte_size(B). 16 10>
process_limit
Returns the maximum number of simultaneously existing processes at the local node as an integer. This limit can be configured at startup by using the
+P command line flag of erl(1).
The previous default of a maximum of 32768 simultaneous processes has been raised to
262144.
Tuple insert_element delete_element
erlang:insert_element(2, {one, two, three}, new).
{one,new,two,three}
> erlang:delete_element(2, {one, two, three}).
{one,three}
{one,new,two,three}
> erlang:delete_element(2, {one, two, three}).
{one,three}
float integer
> float_to_list(7.12, [{decimals, 4}]). "7.1200" > float_to_list(7.12, [{decimals, 4}, compact]). "7.12" > float_to_binary(7.12, [{decimals, 4}]). <<"7.1200">> > float_to_binary(7.12, [{decimals, 4}, compact]). <<"7.12">> 13> erlang:binary_to_integer(<<"10204">>). 10204 14> erlang:integer_to_binary(10204). <<"10204">> 15>
Non-blocking code loading. Erts 5.10
Earlier when an Erlang module was loaded, all other execution in the VM were halted while the load operation was carried out in single threaded mode. Now modules are loaded without blocking the VM. Processes may continue executing undisturbed in parallel during the entire load operation. The load operation is completed by making the loaded code visible to all processes in a consistent way with one single atomic instruction. Non-blocking code loading will improve realtime characteristics when modules are loaded/upgraded on a running SMP system.
這個有意思,后面我會做更詳細的梳理.
Runtime's maximum number of ETS tables.
Erts 5.10.4
16> erlang:system_info(ets_limit) .
2053
17>
2053
17>
顏色RGB 表示與16進制表示轉換
這個並沒有什么難度,只是提醒想想問題的本質是什么,是不是手頭的工具就可以搞定
1> Color = 16#F09A29. 15768105 2> Pixel = <<Color:24>>. <<240,154,41>>
io:printable_range
This flag affects what is interpreted as string data when doing heuristic string detection in the shell and in io/io_lib:format with the "~tp" and ~tP formatting instructions, as described above. [
Doc]
[root@nimbus record]#
erl +pc unicode
Eshell V6.0 (abort with ^G)
1> io:printable_range().
unicode
2> io:format("~tp",["開心"]).
"開心"ok
1> io:printable_range().
unicode
2> io:format("~tp",["開心"]).
"開心"ok
2014-4-19 11:41:35補充
Run distributed Erlang through a firewall?
The simplest approach is to make an a-priori restriction to the TCP
ports distributed Erlang uses to communicate through by setting the
(undocumented) kernel variables 'inet_dist_listen_min' and
'inet_dist_listen_max':
The simplest approach is to make an a-priori restriction to the TCP
ports distributed Erlang uses to communicate through by setting the
(undocumented) kernel variables 'inet_dist_listen_min' and
'inet_dist_listen_max':
application:set_env(kernel, inet_dist_listen_min, 9100). application:set_env(kernel, inet_dist_listen_max, 9105).
This forces Erlang to use only ports 9100--9105 for distributed Erlang
traffic.
traffic.
好,就到這里吧,昨天兒子鬧了一晚上,今天真累了,晚安!