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.