2014年3月28日金曜日

Jekyll で Table Of Contents を表示する方法

■環境
CentOS 5.10 64bit
Ruby 2.1.1
Gem 2.2.2
Jekyll 1.5.0
※Jekyllのインストールおよび設定はこちらから

■nokogiri のインストール
gem install nokogiri --no-rdoc --no-ri

■jekyll-toc-generator のインストール
cd /var/tmp
git clone https://github.com/dafi/jekyll-toc-generator.git
cd jekyll-toc-generator/
cp -ipr _plugins /jekyll/to/path
    「/jekyll/to/path」はjekyll buildしているmarkdownファイル等があるディレクトリを指定します
cp -ipr _plugins /jekyll/to/path
cp -ipr css/toc.css /jekyll/to/path/_layouts
    「_layouts」フォルダがまだ作成されていない場合はこちらを元に初期設定を済ませてください

■layout.htmlの修正
1. headタグ内にcssの宣言を追加
<link href="toc.css" media="screen" rel="stylesheet" type="text/css"></link>
2. tocを表示するための宣言を追加
bodyタグ内に存在する{{ content }}を以下に置き換えてください
{{ content | toc_generate }}

■動作確認
cd /jekyll/to/path
jekyll build
jekyll server --watch

http://localhost:4000/
    markdownのファイル名がindex.mdではない場合はmarkdownファイル名.htmlを後ろに付けてアクセスしてください

2014年3月26日水曜日

Emacsにmarkdown-modeをインストール

■環境
CentOS 5.10 64bit
Emacs 23.4.1

■インストール
cd /var/tmp
git clone git://jblevins.org/git/markdown-mode.git
cd markdown-mode
cp markdown-mode.el ~/.emacs.d/site-lisp/
emacs ~/.emacs
以下を追記
(load-file "~/.emacs.d/site-lisp/markdown-mode.el")
(autoload 'markdown-mode "markdown-mode"
   "Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

※cookbooksにも適用しました
https://github.com/kakakikikeke/cookbooks-emacs

■参考サイト

2014年3月25日火曜日

CentOSにPostgres9.3.1をインストールする方法

■環境
CentOS 5.10 64bit
PostgreSQL 9.3.1

■事前確認
rpm -qa | grep postgres
    他のPostgreSQLサーバがインストールされていないことを確認する
    「postgresql-server.x86_64」というパッケージがなければサーバはインストールされていません
    ちなみに自分の環境では以下がインストールされていました
  • postgresql-libs-8.1.23-6.el5_8
  • postgresql-libs-8.1.23-6.el5_8
  • postgresql-8.1.23-6.el5_8

■インストール手順
cd /var/tmp
wget http://yum.postgresql.org/9.3/redhat/rhel-5-x86_64/pgdg-centos93-9.3-1.noarch.rpm
rpm -ivh pgdg-centos93-9.3-1.noarch.rpm
yum clean all
yum repolist | grep pgdg93
    PostgreSQLのリポジトリが追加されていることを確認します

yum -y install postgresql93.x86_64 postgresql93-server.x86_64
    yum installします
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.kddilabs.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Excluding Packages in global exclude list
Finished
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql93.x86_64 0:9.3.4-1PGDG.rhel5 set to be updated
--> Processing Dependency: postgresql93-libs = 9.3.4-1PGDG.rhel5 for package: postgresql93
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql93
---> Package postgresql93-server.x86_64 0:9.3.4-1PGDG.rhel5 set to be updated
--> Running transaction check
---> Package postgresql93-libs.x86_64 0:9.3.4-1PGDG.rhel5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
 Package                           Arch                 Version                          Repository            Size
====================================================================================================================
Installing:
 postgresql93                      x86_64               9.3.4-1PGDG.rhel5                pgdg93               1.7 M
 postgresql93-server               x86_64               9.3.4-1PGDG.rhel5                pgdg93               5.6 M
Installing for dependencies:
 postgresql93-libs                 x86_64               9.3.4-1PGDG.rhel5                pgdg93               220 k

Transaction Summary
====================================================================================================================
Install       3 Package(s)
Upgrade       0 Package(s)

Total download size: 7.5 M
Downloading Packages:
(1/3): postgresql93-libs-9.3.4-1PGDG.rhel5.x86_64.rpm                                        | 220 kB     00:00
(2/3): postgresql93-9.3.4-1PGDG.rhel5.x86_64.rpm                                             | 1.7 MB     00:00
(3/3): postgresql93-server-9.3.4-1PGDG.rhel5.x86_64.rpm                                      | 5.6 MB     00:00
--------------------------------------------------------------------------------------------------------------------
Total                                                                               2.6 MB/s | 7.5 MB     00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : postgresql93-libs                                                                            1/3
  Installing     : postgresql93                                                                                 2/3
  Installing     : postgresql93-server                                                                          3/3

Installed:
  postgresql93.x86_64 0:9.3.4-1PGDG.rhel5               postgresql93-server.x86_64 0:9.3.4-1PGDG.rhel5

Dependency Installed:
  postgresql93-libs.x86_64 0:9.3.4-1PGDG.rhel5

Complete!

■動作確認
service postgresql-9.3 initdb
データベースを初期化中:                                    [  OK  ]

service postgresql-9.3 start
postgresql-9.3 サービスを開始中:                           [  OK  ]

su - postgres
-bash-3.2$ psql -l
List of databases
   Name    |  Owner   | Encoding
-----------+----------+----------
 postgres  | postgres | UTF8
 template0 | postgres | UTF8
 template1 | postgres | UTF8
(3 rows)

-bash-3.2$ createdb test
CREATE DATABASE

-bash-3.2$ psql -U postgres test
Welcome to psql 8.1.23 (server 9.3.4), the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

WARNING:  You are connected to a server with major version 9.3,
but your psql client is major version 8.1.  Some backslash commands,
such as \d, might not work properly.
クライアントが8.1のままだったのでDB接続時に警告が表示されました

■参考サイト

■Tips
設定ファイルの場所
/var/lib/pgsql/9.3/data/postgresql.conf
/var/lib/pgsql/9.3/data/pg_hba.conf

「-h localhost」を指定した場合はパスワードなしでpsqlを実行できるようにする
vim /var/lib/pgsql/9.3/data/pg_hba.conf
host    all             all             127.0.0.1/32            trust

「-h localhost」を指定した場合にパスワード認証でpsqlを実行できるようにする
psql
postgres=# ALTER USER postgres with password 'yoshinaka';

vim /var/lib/pgsql/9.3/data/pg_hba.conf
host    all             all             127.0.0.1/32            md5

LISTENポートを変更する方法
通常は /var/lib/pgsql/9.3/data/postgresql.conf の「#port = 5432」の部分を書き換えてrestartすればOKなのですが
今回インストールしたyumインストールの場合は起動スクリプト内でポートの指定を行っているようなので起動スクリプトを修正してやる必要がありました
vim /etc/init.d/postgresql-9.3
PGPORT=5432

PGPORT=5431

service postgresql-9.3 restart

2014年3月24日月曜日

【Windows Server 2008R2】winsxsのデータを削除する方法

以下を実行するとServicePackがアンインストールできなくなるので事後責任にて実行してください

Windows Server 2008R2でWindowsUpdateを何回か実施し
ServicePack2あたりまで適用されると「C:\Windows\winsxs」が20GBを超えてブートパーティションを食いつぶします

Microsoftの公式でも案内してました
http://support.microsoft.com/kb/973016/ja

基本的にwinsxs領域は削除しちゃいけないらしいんですが、付属のツールを使うことで不要ファイルだけを削除することができるようです

1. コマンドプロンプトを立ち上げます
2. 以下のコマンドを実行します
C:\Windows\System32\DISM.exe /online /Cleanup-Image /spsuperseded
3. 10分くらい待っていれば終了です、以下デバッグログのスクリーンショットのサンプルです


約2GBほど空き領域が増えました
ただ大幅に増えるわけではないのでブートパーティションの領域を拡張するのが一番いいかもしれないです

2014年3月20日木曜日

のどかでキーボードレイアウトをショートカットキーで切り替える方法

Shift + F2

いつも忘れるのでメモ
タスクバーから
のどかを右クリック -> 設定
として切り替えるのが非常に面倒なときにどうぞ

のどかは付属のドキュメントが非常に充実しているので何かあればそれを見るといいかもしれません
のどかを右クリック -> ヘルプ
で開くことができます

2014年3月19日水曜日

Mavenプロジェクトにコンバートしたがプロジェクトエクスプローラで src/main/java配下にパッケージが作成されずにsrc配下にパッケージが作成されてしまう場合の対処方法

タイトルが長くてすいません

原因はプロジェクトのフォルダ直下にある.classpathの記述がおかしいからです

.classpathファイルを以下に変更してeclipseを再起動してください
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="target/test-classes" path="src/test/java">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" path="src/main/resources"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="output" path="target/classes"/>
</classpath>

Mavenプロジェクト用と通常のJava用のプロジェクトでは.classpathのファイルのフォーマットが異なるので書き換えてあげる必要があります
通常のJavaプロジェクトからMavenプロジェクトにコンバートする際には気をつけてください

また上記のファイル内容の場合はsrc/main/resourcesも必要になりますのでない場合は作成するか.classpathファイルから定義を削除してください