無限グミ

メモとか備忘録とか日記

Chainerのモデルのセーブとロード

Chainerのモデルのセーブ・ロードについて

Chainerは作成したモデルを書き出すためのserializersを含んでいます。しかし、セーブの方法は多くのページに書いてありますが、ロードの方法がよくわからなかったため自分の環境でうまく行った方法をまとめます。

続きを読む

MarkDown形式の文書からPDFを生成

pandocを使ってMarkDown文書をPDFに変換

私は今年に入ったあたりからMarkDown形式でメモをとっているのですが、これがとっても書きやすくて気に入ったので報告書やレポートもこの形式で書きたいと思いました。

調べてみると pandoc というツールを使うと様々な形式の文書を相互に変換することができることを知りました。pandocではMarkDown形式の文書をTeX形式に変換したあとPDFを生成するという流れで直接変換する方法もあるようですが、今回は自分でスタイルなどを設定するためにpandocとlatexmkを使った方法について紹介します。

続きを読む

【vim】 deinでプラグインを管理

dein

これまでNeoBundleを使っていたがdeinの方が早いらしいのでdeinでプラグインの管理をしてみる。

インストーラーでdeinを導入

% curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh
% sh ./installer.sh ~/.vim/dein

.vimrc に設定

" ------------------ dein setting -------------------------
if &compatible
    set nocompatible
endif
set runtimepath^=$HOME/.vim/dein/repos/github.com/Shougo/dein.vim


" neobundle の設定
call dein#begin(expand('$HOME/.vim/dein'))
call dein#add('Shougo/dein.vim')

" ==================== plugins ===============================
call dein#add('Shougo/unite.vim') " ファイル操作とか
call dein#add('Shougo/neocomplete.vim') " 補完
call dein#add('Shougo/neosnippet.vim') " スニペット
call dein#add('Shougo/neosnippet-snippets') " スニペット
call dein#add('itchyny/lightline.vim') " 情報を見やすく
call dein#add('nathanaelkane/vim-indent-guides') " インデントを色分け
call dein#add('Townk/vim-autoclose') " カッコを自動で閉じる
call dein#add('honza/vim-snippets') " スニペット
call dein#add('ujihisa/neco-look') " 英単語の補完
" ============================================================
call dein#end()
filetype plugin indent on

" 未インストールのプラグインをインストール
if dein#check_install()
    call dein#install()
endif

これで次回起動時に未インストールのプラグインを導入してくれる。 それぞれのプラグインには設定が必要なものもあるので注意。

Neocompleteとuniteはよく使うので必須。
lightlineは今のモードや開いているファイル名を表示してくれるのでとても便利。
vim-indent-guidesはインデントが色分けされるので管理がしやすい。
pythonとかだととってもわかりやすい。
neo-lookは報告書とかREADMEに英語で書くときに保管してくれるのでめちゃくちゃ助かる。

今のところの.vimrc

" syntax
syntax enable
colorscheme jellybeans
" lightline
set laststatus=2
let g:lightline = {
    \ 'colorscheme' : 'wombat'
    \ }
" indent colors
let g:indent_guides_enable_on_vim_startup=1
" indent setting
set autoindent
set expandtab
set shiftwidth=4
set tabstop=4

" disp setting
set number
set ruler
set list
set listchars=tab:>-,trail:-,nbsp:%,extends:>,precedes:<,eol:<
set scrolloff=5

" cursor setting
set whichwrap=b,s,<,>,[,]
set backspace=indent,eol,start

" encoding
set encoding=utf8
set fileencoding=utf8

" hilight setting
set matchtime=3

" set binary mode
augroup BinnaryXXD
  autocmd!
  autocmd BufReadPre  *.bin let &binary =1
  autocmd BufReadPost * if &binary | silent %!xxd -g 1
  autocmd BufReadPost * set ft=xxd | endif
  autocmd BufWritePre * if &binary | %!xxd -r | endif
  autocmd BufWritePost * if &binary | silent %!xxd -g 1
  autocmd BufWritePost * set nomod | endif
augroup END

" .mdファイルをmarkdownとして認識してもらう
autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mark*} set filetype=markdown
" -------------------------------------------------------------
" -------------- dein setting ----------------------------
if &compatible
    set nocompatible
endif
set runtimepath^=$HOME/.vim/dein/repos/github.com/Shougo/dein.vim


" neobundle の設定
call dein#begin(expand('$HOME/.vim/dein'))
call dein#add('Shougo/dein.vim')

" ==================== plugins ===============================
call dein#add('Shougo/unite.vim')
call dein#add('Shougo/neomru.vim')
call dein#add('Shougo/neocomplete.vim')
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')
" NeoBundle 'Shougo/vimproc')
call dein#add('itchyny/lightline.vim')
call dein#add('nathanaelkane/vim-indent-guides')
call dein#add('Townk/vim-autoclose')
call dein#add('honza/vim-snippets')
call dein#add('ujihisa/neco-look')
" ============================================================
call dein#end()
filetype plugin indent on

" 未インストールのプラグインをインストール
if dein#check_install()
    call dein#install()
endif

" ------------------------------------------------------------
" ### neocomplete
    let g:acp_enableAtStartup=0
    let g:neocomplete#enable_at_startup=1
    let g:neocomplete#enable_smart_case=1
    let g:neocomplete#sources#syntax#min_keyword_lenth=2
    let gLneocomplete#lock_buffer_name_pattern='\*ku\*'
    if !exists('g:neocomplete#keyword_patterns')
       let g:neocomplete#keyword_patterns={}
    endif
    let g:neocomplete#keyword_patterns['default']='\h\w*'
    inoremap <expr><C-g> neocomplete#undo_completion()
    inoremap <expr><C-l> neocomplete#complete_common_string()
    inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"

" ### neco-look
    if !exists('g:neocomplete#text_mode_filetypes')
        let g:neocomplete#text_mode_filetypes={}
    endif
    let g:neocomplete#text_mode_filetypes={
        \ 'rst' : 1,
        \ 'markdown' : 1,
        \ 'gitrebase' : 1,
        \ 'gitcommit' : 1,
        \ 'vcs-commit' : 1,
        \ 'hybrid' : 1,
        \ 'text' : 1,
        \ 'help' : 1,
        \ 'tex' : 1,
        \ }

filetype plugin indent on

【vim】 vim 7.4 を+luaでインストール

vim

最初に使ったターミナルベースのエディタがvimだったのでそれ以降vimを使っている。
新しくUbuntu16.04を入れたので、vimを7.4でインストールしようと思う。
NeoCompleteを使いたいので+luaにしておこう。

環境

Ubuntu 16.04
vim 7.4

まずはvim7.4を入れよう

ubuntu16.04はデフォルトでvimが入っていない。
せっかくなのでソースコードからvimを導入した。

ソースコードの入手

何はともあれソースコードの入手して解凍。

% wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
% tar xvf vim-7.4.tar.bz2
% cd vim74

+luaのために必要なものを用意

NeoCompleteをつかうためには+luaにする必要があるので、必要なものをインストール

% sudo apt-get install libncurses5-dev liblua5.1-dev luajit libluajit-5.10-dev

configure & make

% ./configure --withfeatures=huge \
               --enable-multibyte \
               --enable-luainterp \
               --with-luajit \
               --with-fontset \
               --enable-fail-if-missing

最後のenable-fail-if-missingをつけないとlua周りで失敗してもスルーされてわかりにくいのでつけておくことをおすすめ。
サーバーとかにインストールする場合は--prefix=$HOME/software/binとかにインストールしてる。

あとはmakeしてインストールするだけ

% make
% sudo make install

バージョンの確認

インストールできたらバージョンが7.4になっていることを確認しよう。

% vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun  4 2016 16:47:06)
Compiled by tnishi@gintonic-VB
通常 版 without GUI.  機能の一覧 有効(+)/無効(-)
-arabic          +file_in_path    -mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           -mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl

こんな感じでバージョンと機能がずらっと出てくるので+luaになっていることを確認しよう。 こんなコマンドでやるとわかりやすいかも。

% vim --version | grep lua