0%

这篇博客记录一些我比较有用但是的command, 方便自己查询, 标题加入了一些英语翻译,方便CTRL+F。 欢迎补充

  1. curl查询公网出口IP(use curl to query public IP)

    curl ifconfig.me

    some other useful webstite:

    1. ip.cn
    2. ipinfo.io
    3. cip.cc
    4. myip.ipip.net
  1. 设置ssh反向tunnel(ssh reverse tunnel)

    A机器在内网,B机器在外网,C机器可以连接B但是不能连接A。如果C想通过B链接到A机器

    1. 从A登录B机器
      ssh -fNR 8771:localhost:22 [email protected]_MACHINE_IP
    2. 这样C机器就可以访问 ssh -p 8771 [email protected]_MACHINE_IP
  2. 列出监听端口(list all listening port)

    1
    netstat -anlp | grep -w LISTEN

    or

    1
    sudo netstat -tulp
  3. 打开关闭网卡(up and down network interface)

    1
    ip link set eth0 up/down
  4. 用ssh执行远程命令(use ssh to execute remote commands)

    -t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

    1
    ssh -t [email protected] "command1 & command2"

    For example, if you want to simply pull a docker images on multiple servers, you can write a simple bash script like this:

    1
    2
    3
    for remote in 192.168.1.1 192.168.1.2 192.168.1.3; do
    ssh -t [email protected] "docker pull image:tag"
    done

    if you want to execute remote command in background, you can try to use nohup or screen:

    1
    ssh [email protected] screen -d -m ./script

    and you can check the result with

    1
    screen -ls 
  5. Show network interface RX-OK/RX-ERROR

    1
    ip addr show;echo;echo;ip route list table all;echo;echo;netstat -ai

    文件查找和字符操作(counting, searching and string operation)

  6. grep查找包含特定文字的文件(use grep to find all files container specific text)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    grep -rnw '/path/to/somewhere/' -e 'pattern'

    -r or -R is recursive,
    -n is line number, and
    -w stands for match the whole word.
    -l (lower-case L) can be added to just give the file name of matching files.

    Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

    This will only search through those files which have .c or .h extensions:

    grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

    This will exclude searching all the files ending with .o extension:

    grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

    For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

    grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
  7. grep从文件中过滤并统计特定字符数量(use grep to filter string in file and count number)

    1
    grep -n '2018-03-24' /var/log/xxx/xxx/xxx.log  | grep 'stringyouwant'  |     wc -l
  8. find查找并替换文件中内容(use find to filter string and replace)
    stackoverflow

    1
    find . -iname '*.txt' -exec sed -i 's/text-to-search/text-to-replace/g' {} \;
  9. find查找过滤文件中内容(use find to filter string from file)

    1
    find . -iname '*.txt' | xargs -n 1 grep -nR 'text-to-search'
  10. find recursively find all files in current and subfolders based on wildcard matching

    1
    find . -name "foo*"
  11. find exclude a directory

    1. use -prune switch
      1
      find . -path ./misc -prune -o -name '*.txt' -print
    2. use -not -path
      1
      find -name "*.js*" -not -path "./directory/*"
      or
      1
      find -name "*.js*" -not -path "./directory*"
  12. find and do operations(like copy)

    1
    find . -name "*.dae" -not -path "./ignore-directory/*" -exec cp {} ../otherfolder/ \;

    better(not tested)

    1
    find . -name '*.dae' -not -path './ignore-directory/*' -exec cp {} ../otherfolder/ +
  13. 查看当前目录下多少文件(Counting Files in the Current Directory

    1
    2
    ls -1 | wc -l
    ls -l | grep -v ^l | wc -l (exclude symbol file, that's an "L" not a "1" this time)
  14. 遍历当前目录下所有文件名(iterate over filenames in current directory)

    1
    2
    3
    4
    for filename in echo *; do
    echo "Processing $filename"
    # do something on $f
    done
  15. 删除字符串后缀(Remove the string prefix)
    Shell-Parameter_Expansion

    1
    2
    3
    4
    $ x="/foo/fizzbuzz.bar"
    $ y=${x%.bar}
    $ echo ${y##*/}
    fizzbuzz

    Shell

  16. 查看当前shell版本(show which shell are you using)

    1
    echo $0
  17. 如何压缩一个文件名是--开头的文件?
    如果遇到一个文件名是以--开头的,那么在linux命令行中会被认为是参数. 例如文件名--test_abc

    1
    tar cvf test.tar.gz --test_abc

    这时候只要用--来表示参数终结就可以了

    1
    tar cvf test.tar.gz -- --test.abc
  18. Showing Linux Kernel LOG/Query the system journal

    1
    sudo dmesg

    or use journalctl under debian/ubuntu

    1. all dmesg output in the last 2 hours

      1
      sudo journalctl -k 
    2. all journal since last boot

      1
      sudo journalctl -b
    3. list boots in the journal

      1
      journalctl --list-boots
  19. Setting persistent logging for kernel log

    by default the log is written non-persistently to /run/systemd/journal/(a binary file)

    Edit the /etc/systemd/journald.conf and uncomment #Storage=auto and change auto to persistent

    Then you can restart the service

    1
    sudo systemctl restart system-journald
  20. Make a read-only filesystem writable

    remouting it read-write:

    1
    sudo mount -o remount,rw '/mount-point'
  21. Alternative different version of software

    If you have installed multiple versions of gcc, like gcc-6 and gcc-9. your /usr/bin/gcc is probably pointing to gcc-6 by default. You can use the following command to change the version.

    1
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 900

    open the windows for switching version

    1
    sudo update-alternatives --config gcc

Emacs

  1. compile .emacs.d directory

    1
    C-u 0 M-x byte-recompile-directory

    will compile all the .el files in the directory and in all subdirectories below.
    The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.

    From stackoverflow

  2. upgrade emacs packages

    1
    M-x list-packages
    1. press U to mark all upgradable packages to be upgrade
    2. press x to perform the new updates
  1. format code

    select the region you want to format

    1
    M-h
    1
    M-x (indent-region)

    see also : choosing mode

  1. Regex in emacs

Browser

  1. open recent closed tab (chrome)

    There are 3 ways to do it:

    1. Get it back by right-clicking in the tab bar and selecting Reopen closed tab from the menu
    2. By clicking Ctrl+Shift+T.
    3. You can also find a list of recently closed tabs in the Settings menu. Click on the 3 horizontal line icon top right and choose Recent tabs.

Other commands and tools

screen

1. killing all the detached screens    
1
screen -ls | grep detached | cut -d. -f1 | awk '{print $1}' | xargs kill
or inside screen
1
Ctrl-a \

Unclutter

Unclutter hides your X mouse cursor when you do not need it, to prevent it from getting in the way. You have only to move the mouse to restore the mouse cursor. Unclutter is very useful in tiling window managers where you do not need the mouse often.

Extract GPS Info from Photos (Python脚本提取照片中的GPS信息)

  1. pip install pillow

  2. run this code under the folder image

    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
    from PIL import Image
    from PIL.ExifTags import TAGS
    import glob


    types = ('*.JPG',)

    def demo(name):
    exifdata = {}
    imgfile = Image.open(name)
    info = imgfile._getexif()
    if info:
    for (tag, value) in info.items():
    # print(str(tag) + ' : ' + str(value))
    decoded = TAGS.get(tag, tag)
    # print str(decoded)
    exifdata[decoded] = value
    exifgps = exifdata.get('GPSInfo', '')
    if exifgps:
    print('it has founded ; ' + str(name) + " " + str(exifgps))
    def main():
    for t in types:
    filenames = glob.glob(t)
    [demo(f) for f in filenames]
    if __name__=='__main__':
    main()

  3. If you have multiple image types, you can change types tuple to add more, for exmaple, types = ('\*.JPG', '*.png')

时光飞逝,转眼就来到了2019..(标准作文开头…)
感觉时间过的越来越快了,从17年11月入职算起,在日本生活和工作已经超过一年了。

2018的计划

竟然已经找不到去年写的18年计划了…隐约记得这么几项:

  1. 存钱计划完成
  2. 健身计划(基本完成,每周跑步10公里+,还有一些简单的健身房运动,不算意外的出差时间上还是满足了的..只是每次去健身房都是深夜了..)
  3. 投资上股票惨不忍睹,今年A股大盘就跌的很惨。 我又去开了日本的证券账户,碍于日语实在不行还没有下手,默默的观察中,还好刚开户没有剁手,躲过了年底日经和美股的大跌。
  4. side project其实没有做太多,尝试了一些简单的项目但是因为想不到很好的出发点,所以也没有持续。 要完整的做完一个项目还是很难的,希望新年能有更多的朋友提供想法或者能一起合作。
  5. 认识了一些新的同事和朋友,感觉自从工作之后其实交际圈就变的比较小了,再加上生活在日本又不会日语,平时也很少出去玩orz…有小伙伴来玩请找我…
  6. 博客并没有坚持写什么,倒是通过了Google ADSense的审核,请大家不要Adblock我;)
  7. 日语断断续续的,年底也忘记报名考试了..
  8. 工作。现在对整体的系统从前到后都有了完整的认识,各个部分和架构已经基本的知识等。但对于核心的planning和robotics还只是停留在宽泛的认识上,没有太多的深入。工作还是主要集中在backend system,也包括写了一些PLC Library和工具等。去年一年出差的时间比较多,简单的统计了一下大概4个月是在上海/北京的onsite出差。这段时间对系统有了比较全面的认识,对于robotics这个行业来说动手操作还是很重要的,在现场集成和开发的过程中对抽象的只是就有了具体的认识。经常会有更深刻的理解。但是不好的地方就是现场的压力比较大,琐碎的事情也很多,很难静下心做一些开发的工作。
  9. 旅游。去年没去什么地方,本身就不是太在意旅游,基本也就是东京周边。 去了箱根,镰仓还有东京的迪士尼。 中间还有几次朋友来玩一起去了几次秋叶原之类的地方。

2019年的计划

  1. 赚钱(目标太少就不说了….去年的基础上1.5倍)
  2. 继续健身,每周去2次以上健身房,至少10公里跑步。
  3. 希望能继续多开发一些side project, 从中找一些机会
  4. 对于planning和数学有更进一步的学习
  5. 旅游目前只有计划2月去一次北海道
  6. 日语争取7月考一次N2
  7. 继续写博客,多写博客

昨天随手申请了一下google adsense, 没想到就顺利的过了。之前有申请过一次,不过被拒了,要求应该就是有较多的内容之类的,并且网站运行了一段时间。 于是这次就顺利给这个丝毫没有流量的博客加上了广告;)

其实申请非常简单, 到google adsense页面上登陆帐号,然后只要填入网站的URL就可以了。网站需要是自己的,也就是顶级域名,不能是github page之类的。 官方说一周,但是实际我审核也就过了一天就发邮件说通过了。

审核通过之后会给出一段代码:

1
2
3
4
5
6
7
8
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-3897139875615992",
enable_page_level_ads: true
});
</script>

我用的是hexo + Next主题,所以在 themes/hexo-theme-next/layout/_custom/ 下新建一个google_adsense.ejs文件,并把上面的代码复制进去。
最后只需要在 themes/hexo-theme-next/layout/_layout.swig<head>标签中include就可以了,完整的head如下;)

1
2
3
4
5
6
7
8
<head>
{% include '_partials/head.swig' %}
<title>{% block title %}{% endblock %}</title>
{% include '_third-party/analytics/index.swig' %}
<!--google adsense start-->
{% include '_custom/google_adsense.ejs' %}
<!--google adsense ends-->
</head>

这样就自动完成的广告的添加啦 ~ 不过一想到现在人人都用adblocks……..但总算是满足了一个给自己博客加广告的愿望;P

This blog will collect some excerpt and meaningful words or sentences most likely from books I read. Welcome to reply more in the message board ;)

  1. The writer has learned from much experience that this primary emphasis on the logic of the problem, rather than the mathematics, is necessary in the early stages. For modern students, the mathematics is the easy part; once a problem has been reduced to a definited mathematical exercise, most students can solve it effortlessly and extend it endlessly, without futher help from any book or teacher. It is in the conceptual matters(how to make the initial connection between the real-world problem and the abstract mathematics) that they are preplexed and unsure how to proceed. ————————— Probabilty Theory: The logic of science (Preface, Style of presentation)
  1. It takes more than promise to be an artist. Because the only way to be a true artist is to work day and night. Lose yourself in it completely. Do you have any idea how lonely that is. And yet, without great solitude, his serious work is impossible. They ugly truth is this. No one can help you. You have to do it on your own. Just as I did.
    —————— Genius, BBC 毕加索
  1. Technology changes rapidly, people and culture change slowly.
    ————— The DESIGN of EVERYDAY THINGS, DON NROMAN
  1. “Physics is like sex: sure, it may give some practical results, but that’s not why we do it.”
    ―――――― Richard P. Feynman

这本书在大一的时候就看室友读过。 平时经常会看到关于周期的内容,比如股市的牛市熊市, 货币和经济的周期等等。 因此这次干脆就买了这本书来读了一下。 逃不开的经济周期(豆瓣链接)。 内容读起来还是挺轻松的,语言比较直白,是一本面向普通大众的读物。但是其实整本书读下来,感觉里面可以深究的内容很多,书中大多数地方都是蜻蜓点水一般的提到了一些内容,比如某种资产和另一种的关系,列出了数据来源和一些研究论文等。所以我想通过写博客记录来在第二遍阅读的过程中尽量的去挖掘更多的内容。

从书名想到的问题

这本书的英文名字是“Business Cycles: History, Theory and Investiment Reality”。所以更加直白的中文翻译可能是“经济周期:历史,理论和投资现实”吧。 但是在正式版的翻译中, 加入了”逃不开“ 这三个字,这就不经会让人认为中文翻译对于经济周期的发生是很肯定的。

“周期”一词感觉是带有魔力的, 说的更东方魔幻一些,可以叫做“轮回”。 就好像一个人过了一生,然后去投胎转世,继续下一辈子一样的轮回。 又像西西弗斯将巨石推上山顶又滚轮的循环。

因此这就不禁让我想到:

  1. 周期(繁荣-萧条)是否是资本经济的一种内在性质。也就是说只要是资本主义经济,就一定会存在周期?
  2. 如果是内在的性质, 那么是否是因为其它必须存在的特点,例如股份制公司,纸币等其他因素而决定的。
  3. 如果不是内在性质,那么是否有办法打破这样的周期, 也就是避免萧条的发生,让人类社会的经济活动一直处于上升通道?
  4. 如果存在(2)中所存在的其他特点决定了周期这一属性,那么是否有办法进行修正?
  5. 可能也是对个人来说最重要的,如何识别周期,并且历史的周期中学习到经验, 利用周期来赚钱或者在萧条的时期正确的应对。
  6. 纸币到底是什么,带来了怎么样的影响和决定性因素?(原谅我非经济专业科班出身 ;) )

第一章 发现经济周期–繁荣与崩溃

密西西比泡沫的发起和繁荣开始,作者带我们进入了第一个周期。 这个事件的主角是约翰劳, 撇开他的风流韵事,在1700年,劳29岁的时候,他返回了故乡爱丁堡,开始推销自己在欧洲大陆游历期间形成的理念:国家要繁荣,就要发行纸币。在维基百科的第一句也简明的说出了他的思想: Money was only a means of exchange that did not constitute wealth in itself and that national wealth depended on trade。这句话其实本质意思是说,我们卖商品去获得白银,并不是为了获得白银的价值,而是期待下一次用白银去换取其他商品的价值。 也就是本质上用物品去换另一种我们需要的物品, 只是用白银(货币)作为媒介和价值的暂存对象。

同时他出版了书来解释他的思想。从今天来看可能很多概念很自然,但当时人们还是靠白银或者黄金来进行交易的。 他提出了以下几个问题:

  1. 要查明货币的性质以及为什么白银比其他物品更适合充当货币。
  2. 要研究贸易,以及货币对贸易所产生的深远影响
  3. 要对一经采用的用于维护和增加货币供应量的办法以及现在所提到的这些问题加以检验。

总结一下就是, 为什么要用白银?用白银对社会贸易的影响以及是不是有其他更好的替代品。

除此之外他对价值和价格的区别也做了很经典的解释,以前也在其他地方看到过: 水的作用大但是价值小, 因为人们拥有的水远大于需求。钻石作用小但是价值大,因为需求远远超出了供应量。

这也就是我们现在都很熟悉的, 在市场上, 决定价格的是需求而不是实际的价值大小。(to be continued)