Long time ago, when i design the database, i never think of the character set for my database. But recently, i have to work on some non-english language like Chinese and Korean. I found that my database does not store the info correctly. So here is my suggestion: No matter if you decide to support multiple language or not, when you design your database, you should use UTF-8 as the character set. If you are using mysql and your database is not not with UTF8 – you should use this query to convert it to UTF8. ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATERead More →

Here is the code to utilize Google Translate to translate any text to English for free. /* this function translates chinese to english if you want to use this function, please write your own curl_post_content – it’s just a curl request using post method – i have my own curl_post_content which i can’t publish here. the data that google returns doesn’t work well with json_decode function, we have to fix it a little bit, see the str_replace function here */ function translate_to_english($text) { $url=”https://translate.google.com/translate_a/single?client=t&sl=auto&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&srcrom=0&ssel=0&tsel=0&source=btn&kc=2&tk=523995|731640″; $data=array(); $text=strip_tags($text); $data[“q”]=$text; $response=curl_post_content($url,$data); $response=str_replace(“,,”,”,0,”,$response); $response=str_replace(“,,”,”,0,”,$response); $response=str_replace(“[,”,”[0,”,$response); $obj =json_decode($response,true ); //true converts stdClass to associative array. $result=””; foreach($obj[0] as $v) {Read More →

I have a Chinese text file that’s not encoded in UTF8 , it’s encoded with gb2312 . I have been struggling to insert it into mysql. When i copy the text file & import it to mysql via phpmyadmin, it display chinese character very well, but if i use php to insert it, it display some weird characters. It turned out that i need to re-encode gb2312 to ut8 in php before inserting to database. The reason when it’s working fine via phpmyadmin, it’s because when we copy & paste, the browser already re-encode from gb2312 to utf8. here is the function i use: $text=Read More →

Mounting a Windows (SMB) share on Ubuntu gives us a “cannot allocate memory” error. Executing a command like this: mount -t cifs //toad/Backup /media/backup -o user=username,password=password,iocharset=utf8,file_mode=0777,dir_mode=0777 We get an error like this: mount error(12): Cannot allocate memory Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) Solution: First, check the permissions on your shared folder. Right-click the folder and selectProperties. Your Windows user must be allocated permissions on both the Securityand the Sharing tabs. Open regedit, and set the following registry key to ‘1’. This key tells Windows to set aside enough system cache for sharing large files. Commenter Raoul Duke (thanks!) adds that this change is unnecessary on Windows 7 and later.Read More →

Debugging Autofs problem If you are having trouble automounting your file systems, want to check where the log that autofs being saved, it may be useful to run automount in the foreground. Stop the autofs daemon sudo service autofs stop Run automount in the foreground with verbose information sudo automount -f -v From another terminal, try to mount your file-systems by changing directories into the mountpoint. Check the output from the first terminal for clues as to why the mount failed or was not attempted.   Hope it help.Read More →

The automatic troubleshooter says “Audio device is disabled”, even though it’s not http://www.pcgamer.com/the-most-frustrating-windows-7-audio-problem-solved/   http://superuser.com/questions/815832/how-to-deal-with-windows-7-when-it-reports-audio-device-is-disabled-but-is-noRead More →

If your apt-get repositories don’t contains any precompiled 1.0.1g OpenSSL version, so just download sources from official website and compile it. Below the single command line to compiling and install the last openssl version. curl https://www.openssl.org/source/openssl-1.0.1g.tar.gz | tar xz && cd openssl-1.0.1g && sudo ./config && sudo make && sudo make install Replace old openssl binary file by the new one via a symlink. sudo ln -sf /usr/local/ssl/bin/openssl `which openssl` You are all good ! # openssl version should return openssl version OpenSSL 1.0.1g 7 Apr 2014Read More →

Are you trying to setup on replication on mysql5.5+ ? After upgrading, your mysql can’t start,and  the log show “unknown variabled ‘master-host=’ The following options are removed in MySQL 5.5. If you attempt to start mysqld with any of these options in MySQL 5.5, the server aborts with an unknown variable error. –master-host –master-user –master-password –master-port Solution, comment the master- related variables. Do following, On Master: mysql>GRANT REPLICATION SLAVE ON *.* TO ‘slave_user’@’%’ IDENTIFIED BY ‘‘; (Replace with a real password!) mysql>FLUSH PRIVILEGES; mysql>FLUSH TABLES WITH READ LOCK; mysql>SHOW MASTER STATUS; # get the DB dump. mysql>UNLOCK TABLES; On Slave: # import the DB dump mysql>stopRead More →