Build vim in Ubuntu with the source code.
Memo for building vim in Ubuntu with the source code.
$ wget http://ftp.debian.org/debian/pool/main/v/vim/vim_7.4.335.orig.tar.gz $ tar xf vim_7.4.335.orig.tar.gz $ cd vim-7.4.335 $ ./configure --prefix=/usr/local --mandir=/usr/local//man --enable-multibyte --with-tlib=ncurses --enable-cscope --with-features=huge --enable-luainterp --enable-rubyinterp --enable-pythoninterp --enable-gui=no --without-x $ make ... checking --with-tlib argument... empty: automatic terminal library selection checking for tgetent in -ltinfo... no checking for tgetent in -lncurses... no checking for tgetent in -ltermlib... no checking for tgetent in -ltermcap... no checking for tgetent in -lcurses... no no terminal library found checking for tgetent()... configure: error: NOT FOUND! You need to install a terminal library; for example ncurses. Or specify the name of the library with --with-tlib. make[1]: *** [config] Error 1 make[1]: Leaving directory `/home/vagrant/Downloads/vim-7.4.335/src' make: *** [first] Error 2 $ sudo aptitude install ncurses-dev # To resolve the error $ make $ sudo make install
HomebrewにおけるFormulaの作成方法
目標
Emacsを使ったタイピングソフトTRR をHomebrewで簡単に入れられるようにする。
Homebrewについて
Homebrew は「ユーザが自らパッケージをビルドして使用する」ことのメタファーで 「ビールを自家醸造して保存する・飲む」ことを意味しています。 そのため、独特なキーワードを用いるので下記で表にしておきます。
キーワード 本来の意味 たとえ Brew ビールを醸造する makeする Homebrew 自家醸造 ユーザ自らがビルドする Celler セラー(ワインセラーとかのアレ),ビール貯蔵庫 インストール(保存)先 Keg 樽,醸成用 材料 Formula 調理法、手順 ビルド方法・手順が書かれたスクリプト Quote: http://qiita.com/b4b4r07/items/6efebc2f3d1cbbd393fc#1-3
作成手順
Formulaのテンプレートの作成
$ # trrという名前で配布するFormulaを作成 $ brew create --set-name trr https://trr22.googlecode.com/files/trr22_0.99-5.tar.g://trr22.googlecode.com/files/trr22_0.99-5.tar.gz
テンプレートの編集
createすると自動的に編集モードになりますが、以下でも編集可能です。
$ # brewのコマンドで $ brew edit trr
$ # ファイルパスから $ # $(brew --repository)は基本的には/usr/local $ vim $(brew --repository)/Library/Formula/trr.rb
テンプレートは以下のように作られます。
require "formula"
# Documentation: https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook # /usr/local/Library/Contributions/example-formula.rb # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! class Trr < Formula homepage "" url "https://trr22.googlecode.com/files/trr22_0.99-5.tar.gz" sha1 ""
# depends_on "cmake" => :build depends_on :x11 # if your formula requires any X11/XQuartz components def install # ENV.deparallelize # if your formula fails when building in parallel # Remove unrecognized options if warned by configure system "./configure", "--disable-debug", "--disable-dependency-tracking", "--disable-silent-rules", "--prefix=#{prefix}" # system "cmake", ".", *std_cmake_args system "make", "install" # if this fails, try separate make/make install steps end
test do #test do
will create, run in and delete a temporary directory. # # This test will fail and we won't accept that! It's enough to just replace # "false" with the main program this formula installs, but it'd be nice if you # were more thorough. Run the test withbrew test trr22_0.99
. Options passed # tobrew install
such as--HEAD
also need to be provided tobrew test
. # # The installed folder is not in the path, so use the entire path to any # executables being tested:system "#{bin}/program", "do", "something"
. system "false" end end
インストールコマンドの追加
以下のようにshellコマンドを追加できます。
system "sed -i -e "s,old,new," Makefile" # ファイルの書き換え system "make", "all" # make
Homebrew TapsによるFormulaの公開
brew tap [formula-tap-name]
でbrewでのインストールができるようにする方法です。
この方法では非公式のものになるので、他の人が普段通りsearch
やinstall
を使ってインストール
をするには、まずbrew tap [formula-tap-name]
をする必要があります。
- Githubでhomebrew-[作成したFormula名]というリポジトリを作る。 (例: Homebrew/science)
- 作成したリポジトリへ
[作成したFormula名].rb
をpush
(例:trr.rb
)
インストールをしてもらうときは、
brew tap [Githubのユーザ名]/[作成したFormula名]
とすることで、brew install [作成したFormula名]
などができるようになります。
(例: brew tap homebrew/science
)
Homebrew/homebrewリポジトリへのpull request
Tapでの公開だけでなく、公式リポジトリへの反映をリクエストすることができます。
リクエスト方法
- Homebrew/homebrewをForkする。
cd $(brew --repository) && git remote add [Githubのユーザ名] https://github.com/[Githubのユーザ名]/homebrew
- 変更をローカルリポジトリでコミット。
git push [Githubのユーザ名] master
で変更をForkしたリポジトリへ反映。- Githubでpull requestを送る。
リクエストが受理されるために
Wikiに書かれている事項などを守る必要があります。
例としては以下の様なものがあります。
sudo
を使わない。- インストールの際に追加されるファイルは基本的に
/usr/local/Cellar/[作成したFormula名]
以下に置く。
最後に
結果、EmacsのタイピングソフトtrrのFormulaは以下のようになりました。 https://github.com/greeeenkew/homebrew/blob/master/Library/Formula/trr.rb
Mac OS X デフォルトのフォルダーアイコンの置かれているディレクトリ
$ ls /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources
Accounts.icns Actions.icns AirDrop.icns
....
Mac OS X Yosemite にCommand Line Tools をインストール
問題
Homebrewなどを使う際、Command Line Toolsが必要で、Yosemite Betaをインストールした
直後にbrew doctor
とすると次のようなエラーが出ます。
$ brew doctor Error: No such file or directory - /Library/Developer/CommandLineTools/usr/bin/clang
解決策
次のコマンドでYosemite用のCommand Line Toolsをインストール。
$ xcode-select --install $ # インストール後 $ brew doctor Your system is ready to brew.
vim, MacVimを+luaオプション付きでインストール
テーマ
vimプラグインのneocompleteなどを利用するためには、luaオプション付きのvimを使用する必要がある。問題と解決方法。
問題
neocomplete などを使おうとして.vimrcに
NeoBundle 'Shougo/neocomplete.vim'
と書いた場合、以下の様なエラーが出ることがある。
$ vim neocomplete does not work this version of Vim. It requires Vim 7.3.885 or above and "if_lua" enabled Vim. Press ENTER or type command to continueある。
原因
$ vim --version | grep lua +dialog_con -lua +rightleft +windows
解決方法
brewを用いる。
$ # brewのインストールオプションを調べる $ brew options vim | grep lua --with-lua Build vim with lua support --with-luajit Build with luajit support $ # インストール $ brew install vim --with-lua $ # MacVimも同様 $ brew install macvim --with-lua
もう既に一度インストールしてしまっていた場合には、
brew uninstall vim
で一度アンインストールすればよい。
インストール後の確認
$ vim --version | grep lua +dialog_con +lua +rightleft +windows $ mvim --version | grep lua +dialog_con_gui +lua +rightleft +windows
Mac(+homebrew) 便利なシェルコマンドメモ
nkf: 文字コード変換
インストール
$ brew install nkf
使用例
$ # 文字列コードを調べる $ nkf -g data1.sjis.csv Shift_JIS $ # UTF-8へ変換[オプション-w] $ nkf -w data1.sjis.csv > data1.utf8.csv $ nkf -g data1.utf8.csv UTF-8 $ # Shift_JISへの変換[オプション-S] $ # 同じファイル名で変換[オプション--overwrite] $ nkf -s --overwrite data1.csv $ nkf -g data1.csv Shift_JIS
qpdf: PDFのパスワード操作
インストール
$ brew install qpdf
使用例
$ # パスワード"test"のロックがかかったPDFファイルを開く $ qpdf --decrypt --password=test doc.locked.pdf doc.unlocked.pdf
zip: ファイルの圧縮・解凍
使用例
$ # パスワード保護[オプション-e] $ # 複数のファイルを一つの圧縮ファイルへ[オプション-r] $ zip -e -r compressed.zip *.png Enter password: Verify password: adding: test1.png (stored 10%) adding: test2.png (stored 14%) $ # 解凍 $ unzip compressed.zip
tar: ファイル圧縮・解凍
使用例
$ tar zcvf compress.tar.gz data # 圧縮 $ tar zxvf compress.tar.gz # 解凍
wget: ファイルダウンロード
インストール
$ brew install wget
使用例
$ # ファイル名を指定してダウンロード $ wget http://google.com -O google.html $ # 再帰的にリンクをたどる[オプション-r] $ # 深さを指定する[オプション-l] $ wget -r -l 10 http://qiita.com $ # Basic認証のあるサイトからダウンロード $ wget --user=username --password=pass http://example.com $ # バックグラウンドでダウンロード $ wget -b http://http://qiita.com
python+pandasで大規模データを扱うときのメモ
MySQLからデータを取り出す
"""Get data from MySQL with pandas library.""" import MySQLdb import pandas.io.sql as psql con = MySQLdb.connect(db='work', user='root', passwd='') # DB接続 sql = """SELECT product_id, product_nm, product_features FROM electronics""" df = psql.read_sql(sql, con) # pandasのDataFrameの形でデータを取り出す con.close()
データからベクトルを作る1
大規模データを使ってクラスタリングなどのためのベクトルを作る際、メモリ消費を抑えるためにデータを削除しながら繰り返し処理を行う。
"""Delete rows while creating dataset.""" X = [] for index, row in df.iterrows(): # 行ごとに繰り返し処理 Xi = [row.col1, row.col2, row.col3] X.append(X) df = df.ix[index:] # メモリの消費を抑えるためにデータを削除しながらベクトルを作成
データからベクトルを作る2(速度改良)
1つめのやり方のではコードはきれいだが、繰り返しの速度が遅いという難点がある。 一度リストにするやり方の方が何倍も速い。
"""High speed row iteration in pandas DataFrame""" # データをコピーしてリストへ df_index, df_col1, df_col2, df_col3 = \ list(df.index), list(df.col1), list(df.col2), list(df.col3) del df # データを削除 for _ in df_index: # データを削除しながらイテレート col1, col2, col3 = df_col1.pop(), df_col2.pop(), df_col3.pop() Xi = [col1, col2, col3] X.append(Xi)