2012年9月27日 星期四
[RPi] Raspberry Pi ARM based bare metal examples
control low-level peripherals of Raspberry Pi directly without operating
system, see this repo
2012年9月25日 星期二
[PHP] PHP UTF-8 cheatsheet
要確認PHP的輸出是否為UTF-8,有許多步驟要檢查,不過已經有人整理好了,順便筆記一下吧:
1. Update your database tables to use UTF-8
2. Install the mbstring extension for PHP
3. Configure mbstring
4. Deal with non-multibyte-safe functions in PHP
5. Sort out HTML entities
add wrapper
6. Check content-type headers
modify output
7. Update email scripts
use UTF-8 encoding in text file, and mb_encode_mimeheader() with content
8. Check binary files and strings
reference:
* PHP UTF-8 cheatsheet
1. Update your database tables to use UTF-8
CREATE DATABASE db_name CHARACTER SET utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci ; ALTER DATABASE db_name CHARACTER SET utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci ; ALTER TABLE tbl_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
2. Install the mbstring extension for PHP
3. Configure mbstring
$ vim /path/to/php.ini
mbstring.language = Neutral ; Set default language to Neutral(UTF-8) (default) mbstring.internal_encoding = UTF-8 ; Set default internal encoding to UTF-8 mbstring.encoding_translation = On ; HTTP input encoding translation is enabled mbstring.http_input = auto ; Set HTTP input character set dectection to auto mbstring.http_output = UTF-8 ; Set HTTP output encoding to UTF-8 mbstring.detect_order = auto ; Set default character encoding detection order to auto mbstring.substitute_character = none ; Do not print invalid characters default_charset = UTF-8 ; Default character set for auto content type header
4. Deal with non-multibyte-safe functions in PHP
$ vim /path/to/php.ini
mbstring.func_overload = 7 ; All non-multibyte-safe functions are overloaded with the mbstring alternativeschange functions
mail() -> mb_send_mail() strlen() -> mb_strlen() strpos() -> mb_strpos() strrpos() -> mb_strrpos() substr() -> mb_substr() strtolower() -> mb_strtolower() strtoupper() -> mb_strtoupper() substr_count() -> mb_substr_count() ereg() -> mb_ereg() eregi() -> mb_eregi() ereg_replace() -> mb_ereg_replace() eregi_replace() -> mb_eregi_replace() split() -> mb_split()
5. Sort out HTML entities
add wrapper
/** * Encodes HTML safely for UTF-8. Use instead of htmlentities. * * @param string $var * @return string */ function html_encode($var) { return htmlentities($var, ENT_QUOTES, 'UTF-8') ; }
6. Check content-type headers
modify output
header('Content-type: text/html; charset=UTF-8') ;and
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
7. Update email scripts
use UTF-8 encoding in text file, and mb_encode_mimeheader() with content
8. Check binary files and strings
reference:
* PHP UTF-8 cheatsheet
2012年9月22日 星期六
[Tips] dpkg指令快速參考
Debian/Ubuntu系列相關都使用dpkg(Debian package management system)做為軟體管理系統,常用到的指令筆記一下
dpkg -i package.deb # install dpkg -r package # remove dpkg -P package # purge, including configuration dpkg -L package # listfiles dpkg -l package # list package concisely dpkg -S keyword # find package(s) owning file(s) dpkg -l # list installed package dpkg -c package.deb # listfiles
2012年9月16日 星期日
[Tips] Switch to External Monitor in LXDE
之前換了國人自製的LXDE,發現有些設定不太一樣,比如說想要將螢幕投到外接螢幕,function按鍵就沒作用,非要重開機才能正常,爬了一下文才發現原來LXDE還有做這樣的螢幕管理工具,說明如下:
執行方式就是直接呼叫
預設執行起來應該是這樣
如果有外接螢幕就會變成這樣
選擇正確的輸出就可以快樂的投影了
Description: simple monitor config tool for LXDE This is a very basic monitor config tool utilizing the X extension called RandR. It can let you change the screen resolution on the fly. Besides, when you run lxrandr with external monitor connected, its GUI will change, and show you some quick options to get your projector or external monitor working correctly.
執行方式就是直接呼叫
$ sudo lxrandr
預設執行起來應該是這樣
如果有外接螢幕就會變成這樣
選擇正確的輸出就可以快樂的投影了
訂閱:
文章 (Atom)