SyntaxHighlighter

About Me

2012年8月11日 星期六

[note] ubuntu 12.04 apache2 + mysql + php

apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5 libapache2-mod-php5
apt-get install php5-mysql php5-cgi

在ubuntu 12.04上實作mysql 遇到的問題

#: Ubuntu shell
>: Mysql command line

#mysql -u root -p

password:

>show variables like "character%";

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

>quit

#service mysql stop

#vim /etc/mysql/my.cnf

[client]
default_character_set=utf8
[mysqld]
default_character_set=utf8
init_connect='SET NAMES utf8'

:wq!

#service mysql start
start: Job failed to start

修改my.cnf成

[client]
#default_character_set=utf8    //也就是不要這行
[mysqld]
#deault_character_set=utf8     //也不要這行
character-set-server=utf8
init_connect='SET NAMES utf8'

:wq!

#service mysql start

------------------------------------------------------------------------------

參考文章:

2012年8月4日 星期六

lsattr 檔案屬性設定

最近在使用linux的時候發現

檔案的屬性都是唯讀

無法進行修改

root權限下也無法進行修改

chmod也是正常的且也無法修改

感謝CrBoy的幫忙找到了問題

原來是因為chattr的關係

以下是使用指令:

將檔案屬性加上唯讀

sudo chattr +i [path]

將檔案解除唯讀屬性

sudo chattr -i [path]

2012年8月2日 星期四

有關在mac 上安裝wget

想要再mac上面加上wget這個方變得功能(原本以為他會內建xd)

這個是教學文的link:

http://www.mactricksandtips.com/2008/07/installing-wget-on-your-mac-for-terminal.html

首先你的電腦要有c/c++ compiler的功能

達到這個目的的方法有兩個

1.直接安裝gcc

2.安裝mac app store 的Xcode這個app

在下是使用第二個方法

但說真的...好麻煩orz

以前在用linux的時候都是用第一個方法啦xd

安裝完Xcode之後會發現

他還是沒辦法安裝

他會出現一個error message說

configure: error: no acceptable C compiler found in $PATH

發現電腦本身根本就沒有gcc

所以經過一番google後

http://www.myexception.cn/mobile/411231.html

用以上的方法

可以利用Xcode來install gcc

安裝完後就可以照教學文上面的方法繼續將wget完成安裝嚕

2012年7月13日 星期五

mac terminal colorful

Mac 總算來了
最近在架設有關mac的相關環境
看到mac內建的terminal
雖說簡單
但...他只有黑白orz
所以就將它改個顏色吧
Google了蠻多篇的
但終於找到可以用的


#vim ~/.bash_profile    //new a new file

新增以下兩行

export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad

存檔...logout...restart terminal即可生效

2012年7月9日 星期一

有關php code會直接被download與Call to undefined function mysql_connect() 的解決方法


今天在test東西的後發現
我將我的php code丟進我的server後竟然...
把我的網頁下載下來orz
經過google大神得到以下的解決方法

進入/etc/apache2/mods-available/php5.conf
將以下全部註解
< IfModule mod_userdir.c >
< Directory /home/*/public_html >
php_admin_value engine Off
< /Directory >
< /IfModule >


存檔後將apache restart

----------------------------------------------

通常問題不會只有一個
果然又出現另一個問題了
網頁出現了另一個error message
Fatal error: Call to undefined function mysql_connect()...
解決的方法其實很簡單
step1:
檢查你的/etc/apache2/apache2.conf
extension = mysql.so
如果有注解的話將它拿掉
拿掉後restart apache

如果還是不行的話
step2":
檢查是否沒有安裝php5-mysqlphp5-cgi
直接使用
#sudo apt-get install php5-mysql
#sudo apt-get install php5-cgi
安裝結束後restart apache

ps.本人在安裝的時候遇到一串error
Internal Error, ordering was unable to handle the media swap
如果遇到這個問題
我的解決方法是:將apt-get update
#sudo apt-get update
然後再安裝以上兩個套件即可


參考網頁:
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=25172
http://sahabm.blogspot.tw/2009/04/resolving-fatal-error-call-to-undefined.html

2012年7月2日 星期一

Mysql 忘記密碼處理

常常把mysql的密碼忘掉orz
今天google 到一個適用的方法

系統版本:
Ubuntu 11.04

註:
#為linux command
>為mysql command

首先先將mysql stop
#service mysql stop
將mysql 啟動為無人控制mode(下玩指令後當它停止的時候要另開新的頁面[可以使用screen])
#mysql_safe --skip-grant-tables&
登入mysql
#mysql
重設密碼為'1234'(可自己改成你想要的密碼)
>update mysql.user set password=PASSWORD('1234') where user='root';
需手動生效
>flush privileges;
離開mysql
>quit
restart mysql
#service mysql restart

參考網站:http://blog.xuite.net/pippeng/blog/19152470

2012年7月1日 星期日

GPS實作(非使用google map 純使用android library)

最近需要寫有關利用手機去偵測現在的location(經度、緯度)
但不要透過Google map API實現

以下機型測試成功:

HTC Sencation XE(android 4.0.3)
Sony Xperia Arc(android 4.0.4)
HTC One X(android 4.0.3)



android.app.Activity;
android.content.Context;
android.location.Location;  //可以在指定的時間提供location
android.location.LocationListener;  //為自訂億的class android library沒有這個class
android.location.LocationManager;  //提供可以存取系統location的service
android.os.Bundle;  //傳送參數會使用
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.Toast;  //快顯訊息

public class GPS extends Activity {
 
    private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1;
    //設定超過一個距離(尺)他就會做更新location的動作
    private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000;
    //設定超過一個時間(毫秒)他就會做更新location的動作
 
    protected LocationManager locationManager;
 
    protected Button retrieveLocationButton;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        retrieveLocationButton = (Button)findViewById(R.id.retrieve_location_button);
        
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //get location service
        
        //requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent)
        //Criteria: 訂定尋找location provider的標準
        //PendingIntent: 處理即將發生的事件
        //PendingIntent與Intent的差異:Intent會隨著Activiy的消失而消失,PendingIntent不會
        locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,  //Name of the GPS provider
            MINIMUM_TIME_BETWEEN_UPDATES, 
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            new MyLocationListener()
        );
        
 retrieveLocationButton.setOnClickListener(new OnClickListener() {
     public void onClick(View v) {
         showCurrentLocation();
     }
 });        
        
    }    

 protected void showCurrentLocation() {

     Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
     //取得最後得知道provider資訊
     if (location != null) {
         String message = String.format(
                    "Current Location \n Longitude: %1$s \n Latitude: %2$s",
      location.getLongitude(), location.getLatitude());
  Toast.makeText(GPS.this, message,Toast.LENGTH_LONG).show();
     }

 }   

 private class MyLocationListener implements LocationListener {

     public void onLocationChanged(Location location) {
         String message = String.format(
             "New Location \n Longitude: %1$s \n Latitude: %2$s",
      location.getLongitude(), location.getLatitude());
      //將想要印出的資料用string.format的方法存入string
      Toast.makeText(GPS.this, message, Toast.LENGTH_LONG).show();
      //Toast.LENGTH_LONG:以最長的時間週期呈現文字
     }

     public void onStatusChanged(String s, int i, Bundle b) {
         Toast.makeText(GPS.this, "Provider status changed",
      Toast.LENGTH_LONG).show();
         //當provider cheange的時候會顯示
     }

     public void onProviderDisabled(String s) {
  Toast.makeText(GPS.this,
                    "Provider disabled by the user. GPS turned off",
      Toast.LENGTH_LONG).show();
  //當device的GPS沒有開啟的時候他會顯示
     }

     public void onProviderEnabled(String s) {
  Toast.makeText(GPS.this,
      "Provider enabled by the user. GPS turned on",
      Toast.LENGTH_LONG).show();
  //當device將GPS打開的時候他會顯示
     }

 }
    
}

最後別忘了需要一些permission:
在AndroidManifest.xml的檔案裡面的< /application >後面加上


< uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
//允許一個程式存取精確位置
< uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
//允許程式建立模組使用
< uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
//允許程式存取CellID或WiFi熱點來取得粗略的位置
參考網址:
http://hejp.co.uk/android/android-gps-example/
http://www.javacodegeeks.com/2010/09/android-location-based-services.html
http://www.moke.tw/wordpress/computer/advanced/279

2012年4月25日 星期三

系統指令

查詢CPU's information:
    cat /proc/cpuinfo

查詢memory's informaion:
    cat /proc/meminfo

查詢記憶體的使用狀況:
    free -m(以MB來呈現)

查詢本機PCI裝置:
    lspci(可以搭配pipe來使用)

查詢CPU與整個硬體的狀況:
    iostat(前提是要先安裝sysstat)

查詢系統硬體溫度:
    sensors(前提是要先安裝lm-sensors)

查詢系統版本:
    lsb_release -a

2012年4月24日 星期二

Vim 筆記

最近朋友有發一篇有關vim的使用文章
這篇文章有非常詳細的介紹
以下就在對較為常用的做一些筆記
normal mode:
使用h(左)j(右)k(上)l(右)做移動
在這邊還有個小遊戲可以練習有關hjkl的使用 遊戲
^:可以到自首
$:可以到字尾
[[:可以到整個文章的最前面
H:可以到此頁的最上面
M:可以到此頁的中間
L:可以到次頁的最下面
C:可以將此字到最後面全部刪除
%:可以重這個括弧跑到對應的括弧EX:{ }