Wednesday, 18 May 2016

CentOS 7 で Waifu2x を動作させるには

自分のポストの翻訳版です。
http://k2-rnd.blogspot.jp/2016/05/how-to-setup-waifu2x-on-centos7.html

!! こちらの Python+OpenCL 版の動作はかなり遅い !!
!! 他に C++, OpenCV+OpenCL 版を試して、良い結果を得た !!
!! 従って、直近にそれ対応の導入ガイドを投稿する予定 !! 
参考したガイド:
https://wiki.tiker.net/OpenCLHowTo

動作させるのにいろんな難関を直面したので、備忘録的にガイドを作成しました。
特に OpenCL あたりのリンク関連がかなり面倒でした・・・
( Intel 版は問題はありません。問題児は AMD 版のみです。)

Waifu2x とは?
簡単に言うと、アニメや二次元向けの画像拡大するものです。

本家 Waifu2x:
https://github.com/nagadomi/waifu2x (@ultraistter)

使用する派生 Waifu2x: cl-waifu2x (Waifu2x OpenCL)
https://github.com/marcan/cl-waifu2x (@marcan42)

cl-waifu2x を使用する理由:
本家の方では CUDA 対応の NVIDIA のグラフィックボードが必須でして、
OpenCL さえ有れば動ける Python-OpenCL の派生版を使用しました。
OpenCL も必要無いのであれば、以下のものを使っても大丈夫、らしいです。
https://marcan.st/transf/waifu2x.py
( cl-waifu2x と同じ作者)

依存物:
- Python >= 2.7
- numpy
- scipy
- PIL (or Pillow) < 3.0.0 ( 3.x 以降は fromstring() 関連のエラーがあります)
- OpenCL ヘッダ
- OpenCL ライブラリ (AMD or Intel)
- Boost(推奨)
- OpenCL Test Tool(推奨)
- PyOpenCL

導入手順:
- Python, numpy, scipy, OpenCL headers, Boost などを入れる
# yum install python numpy scipy opencl-headers boost boost-devel ctags

- Pillow ( 2.9.0 ) を入れる
# easy_install pillow==2.9.0 

- OpenCL を入れる( Intel 版、簡単)
* Intel 版は SSE4.2 以降を対応する CPU が必要です。
** 執筆した時点では v16.1 が最新版でした。 url など変わるかもしれません。
*** v16.1 では redhat-lsb-core が必要です。
**** ダウンロードサイト: https://software.intel.com/en-us/articles/opencl-drivers
# yum install redhat-lsb-core
# wget http://registrationcenter-download.intel.com/akdlm/irc_nas/9019/opencl_runtime_16.1_x64_rh_5.2.0.10002.tgz
# tar xzvf opencl_runtime_16.1_x64_rh_5.2.0.10002.tgz
# ./install.sh

特に問題が発生しないはずです。セットアップを終わらせましょう。

- OpenCL を入れる( AMD 版、問題児)
* AMD 版は SSE3 以降を対応する CPU が必要です。
** セットアップ自体は楽ですが、設定が・・・
*** 最大の難関は OpenCL へのリンクあたり・・・
**** ダウンロードサイト: http://developer.amd.com/tools-and-sdks/opencl-zone/amd-accelerated-parallel-processing-app-sdk/
# tar xjvf AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2
# ./AMD-APP-SDK-v3.0.130.136-GA-linux64.sh
# vi /etc/ld.so.conf (add /opt/AMDAPPSDK-3.0/lib/x86_64/sdk )
# ln -s /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so.1 /usr/lib/libOpenCL.so.1
# ln -s /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so.1 /usr/lib64/libOpenCL.so.1

おめでとう〜これで OpenCL の導入が終わりました!
OpenCL を試すには、以下のツールをセットアップしてくださいませ。
(必須ではありません)
# curl https://codeload.github.com/hpc12/tools/tar.gz/master | tar xvfz -
# cd tools-master

難関その1
Intel 版の場合:
# make

AMD 版の場合:
# make OPENCL_INC=/opt/AMDAPPSDK-3.0/include OPENCL_LIB=/opt/AMDAPPSDK-3.0/lib/x86_64/sdk

OpenCL デバイスの一覧コマンド:
# ./print-devices
OpenCL を実験するには:
# ./cl-demo 1000000 10
セットアップが成功すれば、エラーが出ないでしょう。
Intel 版を導入して、実行時に "Device Not Available" エラーが発生したら、つまり使用している CPU は SSE4.2 対応してません。 AMD 版を使いましょう><

インストールを続行します。
- PyOpenCLを入れる。
* easy_install や pip 経由で入れないように、失敗するオチです。
** 執筆時では 2016.1が最新です。
# wget https://pypi.python.org/packages/cb/4e/fcb45db7d3005f5646f28a3de2a2f8e60a6e4b629f02bbb331320778f3a1/pyopencl-2016.1.tar.gz
# tar xzvf pyopencl-2016.1.tar.gz
# cd pyopencl-2016.1

難関その2
Intel 版の場合:
# python configure.py

AMD 版の場合:
# python configure.py --cl-inc-dir=/opt/AMDAPPSDK-3.0/include --cl-lib-dir=/opt/AMDAPPSDK-3.0/lib/x86_64/sdkintel/opencl/lib64 --cl-libname=OpenCL

ビルドを実行:
# make

難関その3( AMD 版のみ)
ビルド途中、 OpenCL が見つからないエラーで失敗する可能性があります。
理由はパラメーターが正しく渡されてないだけです。
以下のコードを実行して再ビルドすればいいです。
# g++ -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/pyopencl._cffi.o build/temp.linux-x86_64-2.7/src/c_wrapper/wrap_cl.o build/temp.linux-x86_64-2.7/src/c_wrapper/wrap_constants.o build/temp.linux-x86_64-2.7/src/c_wrapper/bitlog.o build/temp.linux-x86_64-2.7/src/c_wrapper/pyhelper.o build/temp.linux-x86_64-2.7/src/c_wrapper/platform.o build/temp.linux-x86_64-2.7/src/c_wrapper/device.o build/temp.linux-x86_64-2.7/src/c_wrapper/context.o build/temp.linux-x86_64-2.7/src/c_wrapper/command_queue.o build/temp.linux-x86_64-2.7/src/c_wrapper/event.o build/temp.linux-x86_64-2.7/src/c_wrapper/memory_object.o build/temp.linux-x86_64-2.7/src/c_wrapper/image.o build/temp.linux-x86_64-2.7/src/c_wrapper/gl_obj.o build/temp.linux-x86_64-2.7/src/c_wrapper/memory_map.o build/temp.linux-x86_64-2.7/src/c_wrapper/buffer.o build/temp.linux-x86_64-2.7/src/c_wrapper/sampler.o build/temp.linux-x86_64-2.7/src/c_wrapper/program.o build/temp.linux-x86_64-2.7/src/c_wrapper/kernel.o build/temp.linux-x86_64-2.7/src/c_wrapper/debug.o -L/opt/AMDAPPSDK-3.0/lib/x86_64/sdk -L. -lOpenCL -lpython2.7 -o build/lib.linux-x86_64-2.7/pyopencl/_cffi.so

インストールを完了します。
# make install

cl-waifu2x を clone する
# git clone https://github.com/marcan/cl-waifu2x.git
# cd cl-waifu2x

Waifu2x を動作する
# python cl-waifu2x.py image-source.png image-waifu2x.png models/scale2.0x_model.json

以上です!
Waifu2x を楽しんでくださいませ〜

How to setup Waifu2x on CentOS7

!! The Python+OpenCL variant used is very slow !!
!! I tested C++, OpenCV+OpenCL variant and it's pretty fast !!
!! Will write the installation guide soon on another post !!

Based on this guide:
https://wiki.tiker.net/OpenCLHowTo

I was having a struggle to get it to work. Especially linking OpenCL.
(No problem with Intel counterpart, but the AMD ones...)

What is Waifu2x?
To sum it simple, it's basically an up-scaller for anime-style image.

Original Waifu2x:
https://github.com/nagadomi/waifu2x (@ultraistter)

Waifu2x I'm using: cl-waifu2x (Waifu2x OpenCL)
https://github.com/marcan/cl-waifu2x (@marcan42)

Reason of using cl-waifu2x:
The original counterpart dependencies requires NVIDIA GPU with CUDA support,
therefore I chose the Python-OpenCL version as it can be done as long as OpenCL is available.

If you do not need OpenCL, you can use this:
https://marcan.st/transf/waifu2x.py
(Same author as cl-waifu2x)

Required:
- Python >= 2.7
- numpy
- scipy
- PIL (or Pillow) < 3.0.0 (3.x above will trigger fromstring() exception)
- OpenCL headers
- OpenCL library (AMD or Intel)
- Boost (Optional)
- OpenCL Test Tool (Optional)
- PyOpenCL

Installation steps:
- Install Python, numpy, scipy, OpenCL headers, Boost
# yum install python numpy scipy opencl-headers boost boost-devel ctags

- Install Pillow (Uses 2.9.0)
# easy_install pillow==2.9.0 

- Install OpenCL Library (Intel OpenCL. the simple way)
* Intel OpenCL requires CPU that supports SSE4.2 and onwards
** Using v16.1 when writing this guide, url might changes.
*** You need redhat-lsb-core for v16.1
**** You can download it here: https://software.intel.com/en-us/articles/opencl-drivers
# yum install redhat-lsb-core
# wget http://registrationcenter-download.intel.com/akdlm/irc_nas/9019/opencl_runtime_16.1_x64_rh_5.2.0.10002.tgz
# tar xzvf opencl_runtime_16.1_x64_rh_5.2.0.10002.tgz
# ./install.sh

Just proceed the installation, nothing much to setting.

- Install OpenCL Library (AMD OpenCL, the hard way)
* AMD OpenCL requires CPU that supports SSE3 and onwards
** The installation is not that hard, but faulty...
*** The real pain lies on linking to AMD OpenCL
**** You can download it here: http://developer.amd.com/tools-and-sdks/opencl-zone/amd-accelerated-parallel-processing-app-sdk/
# tar xjvf AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2
# ./AMD-APP-SDK-v3.0.130.136-GA-linux64.sh
# vi /etc/ld.so.conf (add /opt/AMDAPPSDK-3.0/lib/x86_64/sdk )
# ln -s /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so.1 /usr/lib/libOpenCL.so.1
# ln -s /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so.1 /usr/lib64/libOpenCL.so.1

Congrats! You have complete installing OpenCL!
You can test OpenCL by installing the Test Tool.
(You can skip this)
# curl https://codeload.github.com/hpc12/tools/tar.gz/master | tar xvfz -
# cd tools-master

Treaky part-1
Using Intel OpenCL:
# make
Using AMD OpenCL:
# make OPENCL_INC=/opt/AMDAPPSDK-3.0/include OPENCL_LIB=/opt/AMDAPPSDK-3.0/lib/x86_64/sdk

List of Possible OpenCL Device:
# ./print-devices
OpenCL Demo:
# ./cl-demo 1000000 10
If your installation is successful, you should not get no error.
If you installed Intel OpenCL but you get Device Not Available error, it means that your CPU do not support SSE4.2. Use AMD OpenCL instead.

Continue installation.
- Install PyOpenCL.
* Do not install using easy_install or pip, it won't build properly
** 2016.1 was the latest version when writing this guide.
# wget https://pypi.python.org/packages/cb/4e/fcb45db7d3005f5646f28a3de2a2f8e60a6e4b629f02bbb331320778f3a1/pyopencl-2016.1.tar.gz
# tar xzvf pyopencl-2016.1.tar.gz
# cd pyopencl-2016.1

Treaky part-2
Using Intel OpenCL:
# python configure.py

Using AMD OpenCL:
# python configure.py --cl-inc-dir=/opt/AMDAPPSDK-3.0/include --cl-lib-dir=/opt/AMDAPPSDK-3.0/lib/x86_64/sdkintel/opencl/lib64 --cl-libname=OpenCL

Proceed to build:
# make

Treaky part-3 (AMD OpenCL Only)
You might break the make for the last sentence as you get the OpenCL not found error.
It just that the parameter was passed wrongly, you just need to run this once and rerun # make
# g++ -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/pyopencl._cffi.o build/temp.linux-x86_64-2.7/src/c_wrapper/wrap_cl.o build/temp.linux-x86_64-2.7/src/c_wrapper/wrap_constants.o build/temp.linux-x86_64-2.7/src/c_wrapper/bitlog.o build/temp.linux-x86_64-2.7/src/c_wrapper/pyhelper.o build/temp.linux-x86_64-2.7/src/c_wrapper/platform.o build/temp.linux-x86_64-2.7/src/c_wrapper/device.o build/temp.linux-x86_64-2.7/src/c_wrapper/context.o build/temp.linux-x86_64-2.7/src/c_wrapper/command_queue.o build/temp.linux-x86_64-2.7/src/c_wrapper/event.o build/temp.linux-x86_64-2.7/src/c_wrapper/memory_object.o build/temp.linux-x86_64-2.7/src/c_wrapper/image.o build/temp.linux-x86_64-2.7/src/c_wrapper/gl_obj.o build/temp.linux-x86_64-2.7/src/c_wrapper/memory_map.o build/temp.linux-x86_64-2.7/src/c_wrapper/buffer.o build/temp.linux-x86_64-2.7/src/c_wrapper/sampler.o build/temp.linux-x86_64-2.7/src/c_wrapper/program.o build/temp.linux-x86_64-2.7/src/c_wrapper/kernel.o build/temp.linux-x86_64-2.7/src/c_wrapper/debug.o -L/opt/AMDAPPSDK-3.0/lib/x86_64/sdk -L. -lOpenCL -lpython2.7 -o build/lib.linux-x86_64-2.7/pyopencl/_cffi.so

Complete the installation.
# make install

Getting cl-waifu2x
# git clone https://github.com/marcan/cl-waifu2x.git
# cd cl-waifu2x

Test Waifu2x.
# python cl-waifu2x.py image-source.png image-waifu2x.png models/scale2.0x_model.json

That's all!
Have fun with Waifu2x!

Wednesday, 2 December 2015

My APEX cheatbook (For Newbies?)

Data Convertion.
- To String: String.valueOf(data);
- To Integer: Integer.valueOf(data);

Stringified(Serialized) JSON to Apex Data.
private static void doSomething(String JSONString) {
  Map<String, Object> myJSON = (Map<String, Object>) JSON.deserializeUntyped(JSONString);
  Integer something = myJSON.get('key');
}

Execute Apex Class from Browser Client.
Apex Class:
Global with sharing class SomeClass {
  // Dummy constructer
  public SomeClass() {}

  // Important, without RemoteAction, it wont work
  @RemoteAction
  public static String someFunction() {
    return 'success';
  }
}

Browser Client Side(JavaScript):
<apex:page controller="SomeClass">
<script>
SomeClass.someFunction(function(result, event) {
  console.log(result); // outputs 'success';
});
</script>
</apex:page>


To be continue...?

Monday, 16 November 2015

PHP-FPM on Apache HTTPD (CentOS 7)

This basically guides you on implementing PHP-FPM on Apache HTTPD.
The following installation steps are all done on CentOS 7.
Previous version of CentOS might not work as previous Apache HTTPD's fast cgi mod are a bit, "challenging".

Specification:
CentOS 7+
Apache HTTPD 2.4+
PHP 5.6+ (Remi Repository)

(After fresh installation of CentOS)
Step 1, Update system, install Remi repository, install PHP and HTTPD
# yum update
# cd /tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
# yum install httpd httpd-devel
# yum install --enablerepo=remi, remi-php56 php php-devel php-fpm <any-extra-php-modules-you-need-example-php-mbstring>

Step 2, setup new directory
# cd /var/www/html
# mkdir php-fpm
# printf '<?php\n   phpinfo();' > php-fpm/index.php

Step 3, Add a new HTTPD configuration points to the new directory
(A configuration that assign all calls to the directory passes it to php-fpm, on a virtual host)
# vi /etc/httpd/conf.d/php-fpm.conf

# Config Content
<VirtualHost *:80>
    ServerName your-servername.com

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/php-fpm/$1

    DocumentRoot /var/www/html/php-fpm
    <Directory /var/www/html/php-fpm>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/fpm_error.log

    CustomLog /var/log/httpd/fpm_access.log combined
</VirtualHost>


Before proceeding, make sure you added rules to firewalld to allow access.
Step 4, Bring up PHP-FPM and HTTPD
(The steps below disables firewalld and selinux, remember it is important not to disable them on the production server)
# service firewalld stop
# setenforce 0
# service php-fpm start
# service httpd start

Now, access to your server, you will see the php-info, with php-fpm being active in the cgi-fcgi section.

If you want to begin your development on the directory, go on =)
But you might want to concern on the systemd-private-temp configuration if your site allow file uploads.
(CentOS 7 new feature, the "PrivateTemp" option that store in /usr/lib/systemd/system/php-fpm.service)

// Thoughts
It is so much easy on setting up PHP-FPM on CentOS 7 compare to previous CentOS. You need to install mod_fcgi, load it, pass it, very troublesome on virtual host, etc...
Totally a mess.

But it is easy on NGINX. Just around 4 lines and you are done.
I'm basically used to HTTPD, so I will try to stick with it.

NGINX was not that bad either.
It depends on what your site serves.

Thursday, 21 August 2014

How to broadcast Linux hostname to Windows Network (Based on CentOS 6 / 7)

Do you have an experience, that Ubuntu able to broadcast its hostname to Windows network where other Linux OS have issues on it?

You googled for remedy.
You edited ifcfg-xxx, dhclient-xxx.conf, /etc/hostname.
You tried nsupdate.

But, nothing worked and frustrates you.
Changing hostname in Ubuntu alone affects immediately.
You start to think that you should have used Ubuntu...

Well, here is my solving method based on both CentOS 6 / 7.
(Do it with your own responsibility)

After the OS installation with "Web Server" package.

You install SAMBA.
# yum install samba

Next, you rename your hostname.
# hostname my-centos

Start the SAMBA NMB Daemon.
# service nmb start

There, you should be able to ping "my-centos" from Windows.
If you still unable to get them, it might be SELinux / iptables issue.
It's not recommended but you can disable it.

# setenforce 0
# iptables -F

There. it should be working nicely right now.
Have a nice day =)

Tuesday, 22 January 2013

Recent update 2013/01/23

It's late but, Happy New Year :D
Recently have really busy on my job.

Because of it, I was unable to do my personal stuff.
So, it end up AliceSoft released a Browser type ADV before I released my B-ADV. orz
Well that ADV is now closed though, it turned me up to revise my B-ADV.

So, my current status is on developing reB-ADV(revised B-ADV). Bit by bit though...
I just really hope that I able to release before any similiar stuff released.

Well in developing reB-ADV, I replaced Audio Data API with Web Audio API.
Have been playing with the new toy, but still unclear how to pan / balance the channel.
The Google's Pan/Reverb demo works good and when I try to mimic it, it just doesn't come out right. Sigh.

Well, hope to share you guys with anything new or anything inspires me.

Have a nice day :)
(It looks like my postfix + dovecot setup is the most popular post in my blog, hmm)

Thursday, 4 October 2012

CodeIgniter + Memcached on CentOS 6.x

*This setup uses PHP 5.4.x from remi repository, on CentOS 6.3*

Do you have trouble to get Memcached working on CodeIgniter?
Well, I do.

Recently, I have been researching and playing around with CodeIgniter.
After having some fun with experimenting page building and DB access,
Data Caching was my next "toy".

But things doesn't goes well.
So I'm writing this down as a memo for myself too.

1. You need to have memcached.php under the application/config/ directory.
* NOTE: CodeIgniter v2.x does not contain the file.
* Refer: http://codeigniter.com/forums/viewthread/180005/#926666
* The config's sample also provided in the thread.

2. You need to get libmemcached and libmemcached-devel from the correct repository.
* I get my PHP 5.4 from remi repository, so I need to get it from remi repository too.
* If you do not get the correct library, you won't be able to continue the next step.

3. Install php memcached module, and add it into php.ini
* Just run #pecl install memcached, after installation just edit php.ini
* In order to build/install, you will need gcc and gcc-c++.

4. Most importantly, install memcached.
* In CentOS 6.x, memcached is normally provided in the default repository.
* If you are referring this setup and installing it on CentOS 5.x, you will need RPMForge repository to get the job done.

5. After everything from above are finished, you are ready to go.
* get the memcached daemon run and restart your apache/httpd server.

6. In CodeIgniter, Use the code below to test if your memcached works
// $this->load->driver('cache', array('adapter' => 'memcached'));
// var_dump($this->cache->memcached->is_supported());
* This should return you boolean(true) and you can use memcached as your data caching.

Have a nice day. :D

Wednesday, 19 September 2012

iPhone emoji issues on MySQL + PHP

Today I had some troubles while storing text from iPhone device to MySQL.
I did some digging and found that the iPhone's emoji is suspicious.

PHP threw some error with byte characters in it.
After some time googling around,
found that the iphone emojis are mostly 4 bytes character,
and MySQL will only able to store the data if its in UTF84mb format.

What a tragedy.
There are 2 cures for this issue.

1. Upgrade your MySQL server and set the character to UTF84mb.
2. Remove the 4 byte character.

$cleanStrings = preg_replace('/[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]/', '', $fourByteString);

Referred: http://kohkimakimoto.hatenablog.com/entry/2012/02/04/103457

Sigh, I hate emojis.

Thursday, 2 August 2012

Scrollable fixed contents with HTML and CSS, with some jQuery

Do you have a task to make a scrollable fixed element where the main content is behind it?
Plus, it must contain native application-like animation?
AND IT MUST BE IN HTML + CSS?

Well, I just figured it out a way for it.
I made this when my colleague asked me whether HTML + CSS able to scroll fixed element while I thinking about the "log part" of my BADV-project template.

What came out is this.
(Notet that it's just a rought sample. Android / iOS may react different)


content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content

Well, it's a dirty work and all work-in-progress code / comments are inside.
(Note that some css values were modified to suit into this blog. Example, position: fixed to absolute)

Original code:
http://dev.k2-rnd.com/samples/slide.zip

Sunday, 29 July 2012

SquirrelMail issue and fix (Message Filtering and Multibyte Character display, for CentOS)

I'm happy with SquirrelMail even since I installed it.
(Check my previous post on postfix and dovecot)

Everything is working fine and no big deal really occured.
Until...
01 Start to manage Log-type Messages.
02 Start to compose / receiving multibyte messages...

Issue 01
It was not quite a problem when you think that you can just filter the message,
and move them into a specified folder.
But the problem is "Message Filter" is DISABLED in default.
Search through the web found the solution.
(Only available for the latest version of SquirrelMail?)

If you installed your SquirrelMail through EPEL-repo, you just need to execute:
# /usr/share/squirrelmail/config/conf.pl
Select "Plugin", Select "filter", Save your configuration and quit.
Now you will have "Message Filtering" on the Option Menu.
End of Issue 01.

Issue 02
Well, if you only compose your message using ONLY Alphabets.
Plus, if you do not have any contact that sents you multibyte character included messages.
This might not be an issue for you.

You are unable to view the message properly due to decoding issue. (everything is garbled)
Note that, if you switched your Display Option to that specified language,
you able to view the decoded message properly.
But in my case, I want my SquirrelMail default language as English.
As well I receives Japanese and Chinese messages.

Google's search result lead me to a solution,
where you need to modify the current source. (Japanese site, which says i8n.php is buggy, etc...)
Which i think is not a good idea to do so.
I continue to search for the clue until I fed up and decided to browse through the official site.
Well, what did you know. There is a miracle cure in the download section.
What you need to do is:
- Download "Extra Decoding Library" from the official site's download section.
- Extract the package.
- Copy and Replace the SquirrelMail's function/decode/ directory.

** You will need php-recode for "Extra Decoding Library". Skip this step if you already have it.
# yum install php-recode

Linux command:
01. Download.
# wget http://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fprdownloads.sourceforge.net%2Fsquirrelmail%2Fsquirrelmail-decode-1.2.tar.gz

02. Extract and access directory.
# tar xzvf squirrelmail-decode-1.2.tar.gz
# cd squirrelmail-decode-1.2

03. Copy file (execute install, you will be prompted for SquirrelMail's directory: /usr/share/squirrelmail/)
# ./install

04. Check whether files are copied successfully.
# ll /usr/share/squirrelmail/functions/decode/

05. Restart httpd.(Might not needed?)
# service httpd graceful

And there you go.
You can now compose / receive multibyte message with no problem.
... Unless some new encoding method added ...

End of Issue 02.

Tuesday, 24 July 2012

How to locate yourself using HTML5 Geolocation (obtain current location's latitue/longtitude)

To locate your current position.

What you need is just the following JavaScript code.


var coordinates;
function updatePosition(position) {
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    coordinates = [lat, lon];
}

function handleError(positionError) {
    alert('Attempt to get location failed: ' + positionError.message);
}

var gps = navigator.geolocation;
gps.getCurrentPosition(updatePosition, handleError);
alert(coordinates);

Yeap, thats all what you need to get your current location's latitude and longtitude.
And it's works on ALMOST all browsers. (Argh,  android device before v2.1 not supported.)
Mind that, the latitude and longtitude obtained it's not 100% accurate.
It depends on ISP and carrier for the accuracy.

Example, PC browser that access through wired line ISP would obtain the nearest relay station's location. Where the wi-fi user gets a closer match.

Tuesday, 26 June 2012

Personal thoughts on #OpJapan

This is my personal thoughts on #OpJapan.

Japanese Gov. changed ever since the last election.
Is a from bad to worst.
Who ever thought of that?
They made empty promises and suffers the life of its citizen.
Well, it will be off topic if I talk about the politics here,
so I'm not gonna express my feelings on that right here.

To the topic.

In here, Japan, a new copyright law passed at June 22th, 2012.
The new law will be implemented on October.
The law is about punishing illegal downloads, ripping, etcs...

Sounds good for a country to combat piracy.
But, not until JASRAC orders ISP to install surveilance that scans on user activity(download).
There goes our privacy...

Anounymous finds that this will be a start of non-free internet and had commenced attack on Japan.
They are risking themself just to fighting for the freedom of the internet.

On my thought, this act is a justice.
I'm not saying being pirate is good, but ridiculous-ness of what JASRAC is trying to do is awful.
I'm not gonna talk about advantage and disadvantage of illegal downloading here.
Just that this law gonna make citizen suffers more...

But, the most important part is,
(By now, during i wrote this post) most of the citizens are not taking action to protest or anything to protect their privacy.
They are just sitting back and let just hope that Anounymous help them to defeat the evil.
Some even says, "We should fight on ourself, get out outsiders"from bulletin boards.

Sigh, what I want to say is just,
Japanese citizens should realize by now that the Gov. is taking advantage of theirs.
If they do not stands up and fight for it, they will always be the puppet of the blood sucking Gov.


Tuesday, 19 June 2012

How to install PHP 5.4.x on CentOS 6.x

Here are a few commands to execute for installing PHP 5.4.x on CentOS 6.x.

1. Install REMI Repository
# rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

2. Execute yum install with remi-test enabled
# yum install php --enablerepo=remi-test

Check whether you're ok with the dependencies and proceed the installation.
Done. Just that simple 3 steps.

Note. You might want to disable remi-test after installation
# yum update --disablerepo=remi-test

Monday, 11 June 2012

How to play HTML5 audio through JavaScript

A simple memo of how to play HTML5 audio using JavaScript

var audioElement = new Audio();
audioElement.src = 'http://www.somesite.com/audioresource.ogg';
audioElement.load();
audioElement.play();
That's all. Is that simple :D

Note that some browser do not supports ogg formats.
You might want to encode that specified format to support playback for that particular browser.
Well, I don't care about those browsers though.

As for mobile browsers... (MobileSafari, Android Browser)
Unfortunately they do not work as planned.

Reference :
http://www.phoboslab.org/log/2011/03/the-state-of-html5-audio
http://remysharp.com/2010/12/23/audio-sprites/
http://24ways.org/2010/the-state-of-html5-audio

It's year 2012 and Apple haven't solve that problem yet...
I do not owned an Android Device, I do not know is it fixed or not...

Monday, 28 May 2012

How to setup FFMPEG with major codecs in

Video transcoding is 1 of my many hobbies.
When it comes to video encoder, FFMPEG is absolutely the best solution.

Follow the steps below to install it today!

Based ON Fresh Installed CentOS 5.x

[Update Current Software and Libraries]
# yum update

[Install RPMForge Repository][Replace * with i386 or x86_64]
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.*.rpm
# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
# rpm -i rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

[Install Tools and Libraries for Compiling]
# yum install gcc gcc-c++ glib glib-devel libtool automake autoconf git subversion

[Add Library Path to ld.so.conf]
# vi /etc/ld.so.conf
** add /usr/local/lib

[LAME MP3]
# wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
# tar xzvf lame-3.99.5.tar.gz
# cd lame-3.99.5
# ./configure
# make
# make install

$ cd ..

[LIBA52]
# wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
# tar xzvf a52dec-0.7.4.tar.gz
# cd a52dec-0.7.4

-- 32 Bit --
# ./configure
-- 64 Bit --
# ./configure CFLAGS="-fPIC"

# make
# make install

$ cd ..

[FAAC]
# wget http://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
# tar xzvf faac-1.28.tar.gz
# cd faac-1.28
# sh bootstrap
# ./configure
# make
# make install

[NASM & YASM]
# wget http://www.nasm.us/pub/nasm/releasebuilds/2.12.01/nasm-2.12.01.tar.gz
# tar xzvf nasm-2.12.01.tar.gz
# cd nasm-2.12.01
# ./configure
# make
# make install

$ cd ..

# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# tar xzvf yasm-1.3.0.tar.gz
# cd yasm-1.3.0
# ./configure
# make
# make install

$ cd ..

[X264]
# git clone git://git.videolan.org/x264.git x264-git
# cd x264-git
-- 32 Bit --
# ./configure --enable-shared --extra-cflags=-fPIC
-- 64 Bit --
# ./configure --enable-shared
# make
# make install

$ cd ..

[XVID]
# wget http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz
# tar xzvf xvidcore-1.3.4.tar.gz
# cd xvidcore/build/generic
# ./configure
# make
# make install

$ cd ../../..

[WIN32 CODECS]
# wget http://www.mplayerhq.hu/MPlayer/releases/codecs/all-20110131.tar.bz2
# tar xjvf all-20110131.tar.bz2
# mv all-20110131 /usr/local/lib/all-20110131
# mv /usr/local/lib/all-20110131 /usr/local/lib/win32

[Ogg Theora & Ogg Vorbis]
# wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
# tar xzvf libogg-1.3.2.tar.gz
# cd libogg-1.3.2
# ./configure
# make
# make install

$ cd ..

# wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
# tar xzvf libvorbis-1.3.5.tar.gz
# cd libvorbis-1.3.5
# ./configure
# make
# make install

$ cd ..

# wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
# tar xjvf libtheora-1.1.1.tar.bz2
# cd libtheora-1.1.1
# ./configure
# make
# make install

$ cd ..

[FLAC]
# wget http://downloads.xiph.org/releases/flac/flac-1.3.1.tar.xz
# tar xJvf flac-1.3.1.tar.xz
# cd flac-1.3.1
# ./configure
# make
# make install

$ cd ..

[OPUS]
# wget http://downloads.xiph.org/releases/opus/opus-1.1.2.tar.gz
# tar xzvf opus-1.1.2.tar.gz
# cd opus-1.1.2
# ./configure
# make
# make install

$ cd ..

[VP8/VP9/VPX]
# git clone http://git.chromium.org/webm/libvpx.git vpx-git
# git clone https://chromium.googlesource.com/webm/libvpx vpx-git
# cd vpx-git
-- 32 Bit --
# ./configure --enable-vp8 --enable-vp9 --enable-vp10 --enable-shared --extra-cflags=-fPIC
-- 64 Bit --
# ./configure --enable-vp8 --enable-vp9 --enable-vp10 --enable-shared
# make
# make install

$ cd ..

[HEVC / X265]
# yum install hg cmake
# hg clone https://bitbucket.org/multicoreware/x265 x265-hg
# cd x265-hg/build/linux
# ./make-Makefiles.bash
# make
# make install

$ cd ..

[FFMPEG]
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig        <-- for HEVC
# git clone git://git.videolan.org/ffmpeg.git ffmpeg-git
# cd ffmpeg-git

-- 32 Bit --
# ./configure --enable-shared --enable-gpl --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libx264 --enable-libx265 --enable-memalign-hack --enable-static --enable-nonfree --enable-libtheora --enable-libvorbis --enable-libopus --enable-libvpx --enable-version3
-- 64 Bit --
# ./configure --enable-shared --enable-gpl --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libx264 --enable-libx265 --enable-memalign-hack --enable-static --enable-nonfree --enable-libtheora --enable-libvorbis --enable-libopus --enable-libvpx --enable-version3 --extra-cflags=-fPIC

# make
# make install

And you're done.
Have a nice day :)


!REMEMBER!
FFMPEG are not for commercial use.

Thursday, 5 April 2012

How to setup postfix + dovecot mail server based on CentOS 6.2

This have been taking me hours to configure it.

1. Stop the sendmail service and remove it
> service sendmail stop
> yum remove sendmail

2. Install Postfix and Dovecot
> yum install postfix dovecot

3. Edit you hosts file and Add 'mail.yourdomain.com' and 'mail' to 127.0.0.1
> vi /etc/hosts

4. Edit the programs configuration. Mostly about user, servername, etc...
(Will edit later for details)
> vi /etc/postfix/main.cf
> vi /etc/dovecot/dovecot.conf
> vi /etc/aliases

4A. postfix/main.cf sample, configs that added.
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all 
inet_protocols = ipv4 # required for CentOS 7 ~ 
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydestination = $myhostname, $mydomain
mynetworks = 192.168.0.0/24, 127.0.0.0/8
#relay_domains =
home_mailbox = Maildir/
smtpd_recipient_restrictions=permit_mynetworks,reject_unauth_destination
#relayhost = your-hosting-site-mail-relay.yourhostingsite.com
FIGURE 4B. dovecot.conf sample, configs that added.
protocols = imap pop3
mail_location = maildir:~/Maildir
pop3_uidl_format = %08Xu%08Xv 
FIGURE 4C. /etc/aliases sample
# Person who should get root's mail
root:           kiddokenshin

5. Switch your MTA configuration and make sure is SMTP
> alternatives --config mta

6. Add mail user account (without SSH login)
> useradd -s /sbin/nologin youruser
> passwd youruser
> echo "youruserpasswd" | saslpasswd2 -p -u yourdomain.com -c youruser
> sasldblistusers2
> chgrp postfix /etc/sasldb2

7. Start your mail server
> service dovecot start
> service postfix start

8. Check your smtp port availability
> telnet localhost 25

Remember to add MX record and CNAME record on your domain manager. Most probably your mail server is working right now.

!! CAUTION !!
- If you cant send your mail out, most probably its the firewall's fault.
- Some rental server(or hosting site) required you to relay to their mail server to send mail.

If you like to use web browser to view and reply mail,
follow the optional instruction below to install the web based mailer, squirrelmail.

Installing squirrelmail (Optional)
A. Install EPEL Repository
> wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
> rpm -i epel-release-6-5.noarch.rpm

B. Install and Config SquirrelMail
(configure your squirrelmail, such as server name, smtp domain etc...)
> yum install squirrelmail
> /usr/share/squirrelmail/config/conf.pl

C. Edit httpd.conf and Restart httpd (assuming you have httpd)
> vi /etc/httpd/conf/httpd.conf
> service httpd restart

SAMPLE of httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Log into http://yourdomain.com/squirrelmail to access it.

Monday, 2 April 2012

How to setup SVN server with httpd based on centos 6.2

Installing SVN server is quite a headache.
This is my installation steps based on centos 6.2

1. Install Httpd and Subversion
> yum install httpd mod_dav_svn subversion

2. Edit your httpd.conf (at least change your server name)
> vi /etc/httpd/conf/httpd.conf

3. Edit http's subversion.conf (path to svn repos, set auth type and password path)
> vi /etc/httpd/conf.d/subversion.conf

It should be something like this.
<Location /repos>
   DAV svn
   SVNParentPath /var/www/svn/repos
#
#   # Limit write permission to list of valid users.
#   <LimitExcept GET PROPFIND OPTIONS REPORT>
#      # Require SSL connection for password protection.
#      # SSLRequireSSL
#
### You can comment the lines here if you do not need auth
      AuthType Basic
      AuthName "Authorization Realm"
      AuthUserFile /etc/svn-auth-conf
#      AuthUserFile /path/to/passwdfile
      Require valid-user
#   </LimitExcept>
</Location>

4. Create user for svn (if you are using auth to commit / check out)
> htpasswd -cm /etc/svn-auth-conf yoursvnuser

5. Create svn a repo
> mkdir -p /var/www/svn
> svnadmin create /var/www/svn/repos
> chown -R apache.apache /var/www/svn/repos

6. Local commit to repo
> svn import /tmp/somefolder file:////var/www/svn/repos -m "Initial commit"

7. Start your httpd
> service httpd start

8. Try checking out from the newly created repo
> svn co http://yourdomain/repos

There, a workable new svn server.

Sunday, 1 April 2012

KiddoKenshin Personal Research and Development

JA
東京に上京してから最早6年目です。

今までは、
仕事上では他人のブログやソースなどのおかげで、
大変助かりました。

そんでもって、転職したあとに考えたのは、
自分も今まで吸収した知識を共有したいと思って、
ブログを開きました。

近いうちになんかブラウザベースなオープンソースの何かを作る予定です。
つまり HTML + CSS + JavaScript /w jQuery です。
よろしくお願いいたします。

EN
It's been 6 years ever since I landed on Tokyo.

During my previous carrier,
I was able to solve lots of problem thanks to someone's blog/source/forum replies.

So what am I thinking lately after I switched my job, was.
I would like to contribute it back with my knowledge.
As a result, I made this blog.

Well, I will make an browser based open-source something in a near future.
Which means HTML + CSS + JavaScript /w jQuery in involve.