2017年9月20日星期三

递归修改文件夹下所有文件的fileencoding和fileformat

修改文件编码和文件格式,脚本如下:
#!/usr/bin/env bash

function walk()
{
  for file in `ls $1`
  do
    local path=$1"/"$file
    if [ -d $path ]
     then
      echo "DIR $path"
      walk $path
    else
      echo "FILE $path"
      vi +":set fileencoding=utf-8" +":set fileformat=unix" +":wq" $path
    fi
  done
}

if [ $# -ne 1 ]
then
  echo "USAGE: $0 TOP_DIR"
else
  walk $1
fi

vim的一些配置

vim ~/.vimrc,
保存后自动删除行尾空格:
autocmd BufWritePre * :%s/\s\+$//e

显示行尾空格:
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

显示tab键:
set list
set listchars=tab:>-,trail:-

设置缩进:
set autoindent
set shiftwidth=2
set cindent

tab转为空格:
set expandtab
set tabstop=2

显示高亮:
syntax on

yarn的几个命令

杀掉任务:
yarn application -list
yarn application -kill <Application ID>

查看log:
yarn logs -applicationId application_1451022530184_0001

2017年9月19日星期二

linux shell每隔一段时间保存cpu和memory使用情况到文件

#!/usr/bin/env bash

while true
do
    top -n 1 -b | grep -E "PID|java" > cpu_mem$(date -d "today" +"%Y%m%d_%H%M%S").txt
    sleep 300
done

该脚本会保存所有的java进程cpu和内存使用情况。

2017年9月18日星期一

linux下压缩文件

tar
tar chf bazel-genfiles/data/uploader/uploader.tar -C bazel-out/host/bin/data/uploader uploader uploader.runfiles
其中,-C是切换工作目录。

zip没有tar的-C功能,可以通过下面的trick实现:
(cd bazel-out/host/bin/data/uploader && zip -qr - uploader uploader.runfiles) > bazel-out/local-fastbuild/genfiles/data/uploader/uploader.zip

2017年9月13日星期三

spring boot结合hibernate使用中的一些问题

org.hibernate.MappingException: composite-id class must implement Serializable
如果指定了多个@Id,这个类必须implement Serializable


org.xml.sax.SAXException: null:11: Element <defaultCache> does not allow attribute "maxEntriesLocalHeap".
因为ehcache版本过低,需要在maven中单独引入,不能用hibernate默认的版本


org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
参考https://stackoverflow.com/questions/26203446/spring-hibernate-could-not-obtain-transaction-synchronized-session-for-current
必须要指定@EnableTransactionManagement