caca-utilsで勉強会のデモにネタを仕込む
勉強会とかでターミナル作業のデモをやるときに仕込むと効果的です。
導入方法
sudo yum -y install caca-utils |
使い方
使い方としては、cacaviewかimg2txtコマンドを使って
img2txt -W `tput cols` path/to/image.jpg cacaview path/to/image.jpg img2txt -W 100 path/to/image.png |
てな感じ。一番上はtput colsで画面サイズを引数に渡してる感じです
~/.ssh/rc に
img2txt -W 60cols path/to/image.jpg" |
とか書いておくと、sshアタッチしたときに画像が出ます。ちょっとした小ネタにどうぞ。
GithubとOctopressでモダンな技術系ブログを作ってみる
mizzyさんが、http://mizzy.org/をOctopressで運用していていいなーと思ったので、Octopressをちょっと使ってみたのでメモ。
作業環境はCentOS 5.7です。
Octopressの利用にはRuby 1.9.2以上が必要なので、あらかじめ導入しておきましょう。
私は作業用サーバにもともとRuby 1.9.3が入れていたので、すぐに利用が出来ました。
Octopress Setup – Octopressに書いてあるように、rvmとかを利用すると楽かもしれません。
Octopressの導入
gitでサクッと導入。
cd ~ git clone git://github.com/imathis/octopress.git octopress cd octopress sudo gem install bundler sudo bundle install rake install |
Github Pagesの準備
Githubで静的ページを運営出来るようにGithub Pagesを作成。
Github Pagesを利用するために、ここでusername.github.com というような形でリポジトリを作成。

今回のOctopressの導入とは関係ないですが、この状態でindex.htmlファイルを用意して、pushすれば下記のようなお知らせがきてそのうち閲覧出来るようになります。

Octopressのデプロイ設定
続いてOctopressのデプロイ用の初期設定を行います。
rake setup_github_pages Enter the read/write url for your repository: |
と出るので、上で作成したGithub PagesのリポジトリURLを指定。
私の場合だと
git@github.com:glidenote/glidenote.github.com.git |
みたいな感じです。
そして
rake generate rake deploy |
しばらくすると
http://glidenote.github.com/
にアクセス出来るようになり、出来上がり。
ソースのcommitも忘れないようにしておきましょう。
Octopressの初期設定
設定はConfiguring Octopress – Octopressに書いてあるので、その通り進めます。
ブログの設定は_config.yml に書いてあり、下記項目を修正。titleとsubtitle、authorくらいは修正しておきましょう。
url: # For rewriting urls for RSS, etc title: # Used in the header and title tags subtitle: # A description used in the header author: # Your name, for RSS, Copyright, Metadata simple_search: # Search engine for simple site search subscribe_rss: # Url for your blog's feed, defauts to /atom.xml subscribe_email: # Url to subscribe by email (service required) email: # Email address for the RSS feed if you want it. |
設定を修正したら
rake gen_deploy |
でデプロイ。
新規記事の投稿
新規記事の投稿は下記のような感じ
rake new_post["title"] |
zshを利用していると、[が展開されて上手く利用出来ないので下記のようにエスケープ。
rake new_post\["title"\] |
ここで指定するtitleはURLに利用されるので、日本語は利用不可のようです。(記事自体のタイトルには日本語可)
たとえば下記のような感じで実行すると
rake new_post\["test post"\] mkdir -p source/_posts Creating new post: source/_posts/2011-11-07-test-post.markdown |
すると source/_posts/2011-11-07-test-post.markdown
というファイルが生成されるので、それをエディタで編集。記法はMarkdownで書きます。
--- layout: post title: "test post" date: 2011-11-07 15:02 comments: true categories: --- ここにテキストを書く。 |
記事を書いたら、
rake gen_deploy |
でデプロイ。
実際にページにアクセスしてみて、表示されるか確認。
これで最低限動くようになりました。
記事のプレビューを見る
記事をデプロイすると即公開なので、公開前のプレビューを見たい場合は下記コマンド。
rake generate rake preview |
するとhttp://localhost:4000 など4000番ポートでプレビューが確認できます。
とりあえず利用出来るようになったので、独自ドメインを当てたり、デザインの変更はそのうちやりたいと思います。
試しに同じ内容をOctopressで書いてみました。
http://glidenote.github.com/blog/2011/11/07/install-octopress-on-github/
参考ページ
Big Sky :: githubとjekyllとoctopressで作る簡単でモダンなブログ
github:pagesはもう使っているか? – Meltdown Countdown
mizzy.org
lsyncdで特定のファイルだけ同期する
lsyncd – Lsyncd (Live Syncing Daemon) synchronizes local directories with a remote targets – Google Project Hosting
lsyncdで特定のファイルだけ同期する方法があったのでメモ。
lsyncdはexcludeFromで同期除外(exclude)のファイル指定は可能なんですが、指定ファイルだけ同期(include)の設定が出来なかったので何とかならないものかと調べていたら、rsyncOps部分で実現出来ました。まあrsyncのオプションで無理矢理実現してるだけですが。導入完了はCentOS 5.7です。
yumでlsyncdの導入。
yum -y install lsyncd |
rpm -ql lsyncd /usr/bin/lsyncd /usr/share/doc/lsyncd-2.0.4 /usr/share/doc/lsyncd-2.0.4/COPYING /usr/share/doc/lsyncd-2.0.4/ChangeLog /usr/share/doc/lsyncd-2.0.4/examples /usr/share/doc/lsyncd-2.0.4/examples/lbash.lua /usr/share/doc/lsyncd-2.0.4/examples/lecho.lua /usr/share/doc/lsyncd-2.0.4/examples/lgforce.lua /usr/share/doc/lsyncd-2.0.4/examples/limagemagic.lua /usr/share/doc/lsyncd-2.0.4/examples/lpostcmd.lua /usr/share/doc/lsyncd-2.0.4/examples/lrsync.lua /usr/share/doc/lsyncd-2.0.4/examples/lrsyncssh.lua /usr/share/man/man1/lsyncd.1.gz |
yumで入れても設定ファイルも起動スクリプトも生成されないので自分で用意。
mkdir -p /etc/lsyncd/ /bin/cat<< EOF> /etc/lsyncd/lsyncd.conf ---- -- User configuration file for lsyncd. -- -- Simple example for default rsync. -- settings = { statusFile = "/tmp/lsyncd.stat", statusInterval = 1, } sync{ default.rsync, source="/etc/", target="/root/tmp/etc/", rsyncOps={"-az", "--exclude-from=\/etc\/lsyncd\/rsync_exclude\.lst"}, } EOF /bin/cat<< EOF> /etc/lsyncd/rsync_exclude.lst + passwd + shadow - * EOF |
上記設定は/etc/passwd,/etc/shadowだけ同期して、それ以外は同期しない設定になってます。
起動用スクリプト /etc/init.d/lsyncd を用意。ファイルの中身は下記のような感じ
#!/bin/bash
#
# chkconfig: - 85 15
# description: Lightweight inotify based sync daemon
#
# processname: lsyncd
# config: /etc/lsyncd/lsyncd.conf
# config: /etc/sysconfig/lsyncd
# pidfile: /var/run/lsyncd.pid
# Source function library
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
OPTIONS="-pidfile /var/run/lsyncd.pid /etc/lsyncd/lsyncd.conf"
if [ -e /etc/sysconfig/lsyncd.options ]; then
. /etc/sysconfig/lsyncd.options
fi
RETVAL=0
prog="lsyncd"
thelock=/var/lock/subsys/lsyncd
start() {
echo -n $"Starting $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
daemon /usr/bin/lsyncd $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $thelock
fi;
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc /usr/bin/lsyncd
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $thelock
fi;
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc /usr/bin/lsyncd -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
condrestart(){
[ -e $thelock ] && restart
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status lsyncd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=1
esac
exit $RETVAL |
同期先のディレクトリを作成
mkdir -p /root/tmp/etc/ |
起動スクリプトの登録と自動起動の設定
chmod u+x /etc/init.d/lsyncd chkconfig --add lsyncd chkconfig lsyncd on /etc/init.d/lsyncd start |
passwdとshadowを更新して、反映されているか確認。
useradd hoge passwd hoge more /root/tmp/etc/* |
lsyncd.confで同期先をリモートサーバにすれば、リモートサーバと同期できて (゚Д゚)ウマー
ack.vimで編集効率を10倍向上させる
Vimテクニックバイブル ~作業効率をカイゼンする150の技
ここ1週間、Vimテクニックバイブルに載ってる使ったことのないプラグインを試しているんですが、個人的にvimgrepよりも使いやすいと思っているack.vimが見当たらなかったのでご紹介。
ackとは
ack 1.96 — better than grep, a source code search tool for programmers
findで再帰的に全ファイルを列挙して、各ファイルに対してgrepというような事を一つのコマンドでやってくれます。.svnとかCVSとかを検索対象として自動で除外してくれるので、ソースコードの検索に非常に役に立ちます。findとgrepでソース検索してたら、「それack使うと楽だよ」と会社の親切な人が教えてくれましたよ。基本的な利用方法は下記のような感じで
ack パターンマッチ [ファイル名(省略可)] |
CentOSとかならyumで入ります(要epel)
yum -y install ack |
Macでhomebrew使ってるなら
brew install ack |
ack.vimとは
ack.vimは、vim上からackを呼び出して、検索結果をquickfixに一覧表示してくれる、素晴らしいプラグインです。ack.vimを使ってるか、使ってないかで編集効率が数倍違います。
ack.vimの導入
ackを呼び出しているので、ackが利用出来る必要がありますのであらかじめサーバにいれておきましょう。
ack.vimはVundleを使ってれば、.vimrcに
Bundle 'ack.vim' |
とかいて、:BundleInstallするだけです。
またmileszs/ack.vim – GitHubに書いてあるように、GitHubからもってきて、rake installでも導入可能です。
git clone https://github.com/mileszs/ack.vim cd ack.vim rake install |
今風(モダン)なやり方では無いですが、直接ダウンロードしてきても利用出来ると思います。
curl -o ack.tar.gz "http://www.vim.org/scripts/download_script.php?src_id=10433" mv ack.tar.gz ~/.vim cd ~/.vim tar xvzf ack.tar.gz |
ack.vimの使い方
実際の使い方は、非常にシンプルで下記のような感じです。
# 基本的な使い方 :Ack [options] {pattern} [{directory}] # hogeという文字を検索するときは :Ack hoge |
コマンドのackと使い方は同じですし、オプションがそのまま利用出来るので、vimgrepのように直感的でない引数を覚える必要がありません。
ack.vim便利す。
*ack.txt* Plugin that integrates ack with Vim
==============================================================================
Author: Antoine Imbert <antoine.imbert+ackvim@gmail.com> *ack-author*
License: Same terms as Vim itself (see |license|)
==============================================================================
INTRODUCTION *ack*
This plugin is a front for the Perl module App::Ack. Ack can be used as a
replacement for grep. This plugin will allow you to run ack from vim, and
shows the results in a split window.
:Ack[!] [options] {pattern} [{directory}] *:Ack*
Search recursively in {directory} (which defaults to the current
directory) for the {pattern}. Behaves just like the |:grep| command, but
will open the |Quickfix| window for you. If [!] is not given the first
error is jumped to.
:AckAdd [options] {pattern} [{directory}] *:AckAdd*
Just like |:Ack|, but instead of making a new list, the matches are
appended to the current |quickfix| list.
:AckFromSearch [{directory}] *:AckFromSearch*
Just like |:Ack| but the pattern is from previous search.
:LAck [options] {pattern} [{directory}] *:LAck*
Just like |:Ack| but instead of the |quickfix| list, matches are placed in
the current |location-list|.
:LAckAdd [options] {pattern} [{directory}] *:LAckAdd*
Just like |:AckAdd| but instead of the |quickfix| list, matches are added
to the current |location-list|
:AckFile [options] {pattern} [{directory}] *:AckFile*
Search recursively in {directory} (which defaults to the current
directory) for filenames matching the {pattern}. Behaves just like the
|:grep| command, but will open the |Quickfix| window for you.
Files containing the search term will be listed in the split window, along
with the line number of the occurrence, once for each occurrence. <Enter> on
a line in this window will open the file, and place the cursor on the matching
line.
See http://betterthangrep.com/ for more information. |
Vimテクニックバイブル ~作業効率をカイゼンする150の技
著者/訳者:Vimサポーターズ
出版社:技術評論社( 2011-09-23 )
定価:¥ 3,129
Amazon価格:¥ 3,129
単行本(ソフトカバー) ( 384 ページ )
ISBN-10 : 4774147958
ISBN-13 : 9784774147956






