Monday, October 31, 2016

/dev/random vs. /dev/urandom

There's no noticeable difference of the speed between '/dev/random' and '/dev/urandom' in MacOS as follows::

$ time head -n 1 /dev/random
?^??ݣ??%???8W?~G???Y??m5?
?w?\:b??"?d>r?A?tۦ??9?   k?o??&?%>M10ݠ??M?yH??

real    0m0.010s
user    0m0.001s
sys 0m0.008s
$ time head -n 1 /dev/urandom
,}8????
       ?G^??x??#~?o??%?\?$?PѠr۾????8cT?ښ??????Po??P??Ѐ?0??G??%? ?%.'    ?-Z??(????ϣ?1=??G????Tn?C%?C;?Uߌ?&P?*+C?^??x?L

                                      ??7?g??N_?e?????ļ?k??êN??M?!?@a???  ?tW??"?7R?`?V???VOjD
                  ?ۮj??U???D2?{׍{|
                                    ?\?΢??v2?9n?ZUC'
                                                        ??F&? B???D?/?/}???I???Rk?O?8?Q?K?ݮ?#:ZE?.?@rR=B?l?H?m?

real    0m0.010s
user    0m0.001s
sys 0m0.008s
$

but there's big difference in CentOS as follows:

$ time head -n 1 /dev/random
?I?[k+???ത?y??c?Ϛ-%#M?_?{|?????c?$??^      '>e.    ??.?ӺQێ5o?q?????f8?-<?]ß"?d*i;u@?9r^??`VYyrJ??V?W?[8??$c?O???q/?;QP?p?
                                         ????#&i0?z???<v?ⁱ???̵VH:x??%uТ????hPU?R???`??djԹc?c?   Hz4?a@+?ƹqX???5V??[J
                                   ?發??7AΟbvy]E2?ݍ??4k?'MR??????k#?F????x?)vж??p?-??f%?$7??t?qd?"?<?T?'t~S?@?H?}JA?g???:@b??vԆ@???#??????fZ?j?+?t??J??M ?X?w??I=Kj?yfC
       J(0???MVl????????/N???ަ??yI??1

real    0m43.838s
user    0m0.001s
sys     0m0.004s
$ time head -n 1 /dev/urandom
?1Q:?{?GS?pX?K??,oW%?????????
?ERʧ??????'?N???;@Lvg????T?0???9RZ??ܓ
                                     ???&?????aŃ@?Y???L??WM?O~?,V?h<?3?ļ?j
??!?zdw?-a?????߈?¿ͯ^?Ɍ`tx?d??uN?qO?b?????j?s&A?e?d$?~??24w?_[Da???x???s?5??????????ZR~?,??       *??I?????L???yb7??3vqU???Cଆ~?YN톾?]7n?Q???px[]??ي{??F?- '??+?nDQ??:*?U????̼??hm*F??$<??1;?ؓ??\?.??Cݽ?R???I:?Hq?@?????Ab???(??Vϕɫga?O?ޱz??'??d~M?Z?g?Z???Z??f^ Yv?}?/?@??)N7=?5???0ļJ?n|??M??*??7[???????<?6
                                                         ?%???b????5l???? v?+4k??X?*^+??k????J"??>??s}F?H?-??m

real    0m0.004s
user    0m0.001s
sys     0m0.002s
$

Reference:
https://docs.oracle.com/cd/E13209_01/wlcp/wlss30/configwlss/jvmrand.html

Wednesday, October 19, 2016

Index documents and search them in Elasticsearch

To index documents and search them in Elasticsearch, do as follows:

curl -XDELETE localhost:9200/persons?pretty=true

curl -XPUT localhost:9200/persons?pretty=true -d '
{
  "mappings": {
    "persons": {
      "properties": {
        "firstName": {
          "type":  "string"
        },
        "lastName": {
          "type":  "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}'

curl -XPOST localhost:9200/persons/persons?pretty -d '{firstName: "Johnny", lastName: "Lim", age: 20}'
curl -XPOST localhost:9200/persons/persons?pretty -d '{firstName: "John", lastName: "Kim", age: 30}'

curl localhost:9200/persons/persons/_search?pretty=true -d '{query: {match_all: {}}}'
curl localhost:9200/persons/persons/_search?pretty=true -d '{query: {term: {firstName: "Johnny"}}}'
curl localhost:9200/persons/persons/_search?pretty=true -d '{query: {term: {lastName: "Lim"}}}'
curl localhost:9200/persons/persons/_search?pretty=true -d '{query: {term: {age: 20}}}'
curl localhost:9200/persons/persons/_search?pretty=true -d '{query: {match: {firstName: "Johnny"}}}'

Note that term query with analyzed string doesn't work.

For analyzed string, use match query.

Thursday, October 13, 2016

Run a command on a remote server using SSH

To run a command on a remote server using SSH, do as follows:

ssh izeye@test ls

Monday, October 10, 2016

Setup Checkstyle with properties in IntelliJ

When you setup Checkstyle with properties in IntelliJ, use absolute paths for properties as follows:

/Users/izeye/IdeaProjects/java-utils/config/checkstyle/checkstyle-header.txt
/Users/izeye/IdeaProjects/java-utils/config/checkstyle/checkstyle-suppressions.xml

Wednesday, October 5, 2016