2012年12月6日 星期四

Synchronized, Map.containsKey()

資料來源:
http://www.jackforfun.com/2007/07/java-synchronized.html



Map.containsKey() 




圖片來源http://www.isstudy.com/java/1762.html

 

http://blog.sina.com.cn/s/blog_6168ee920100jqu4.html

我们常常使用 Map 对象来缓存数据, 比较常见的处理流程是:
1. 调用 Map 的 get() 方法获取数据;
2. 如果返回不为 null, 直接返回该数据;
3. 如果返回为 null, 则生成数据, 或者从其他地方获取数据, 然后存放入 Map 中, 最后返回该数据.
这里, 我们可以通过使用 Map 的containsKey() 方法来检测是否数据是否存在, 如果key存在, 则表明已经获取过一次数据, 那么直接返回该 key 在 Map 中的值. 不管是否为 null 都直接返回; 如果 key 不存在, 则去生成或者获取数据, 并放入到 Map 中, 并返回该数据.
这里使用 containsKey() 来检测可以应用于: 1. 从其他对方获取的数据可能为空, 并且不会有变化; 2. 获取数据比较耗时. 这个场景下, 使用该方法可以大大降低消耗, 特别是在同步情况下.

MessageDigest

java.security
Class MessageDigest

java.lang.Object
  extended byjava.security.MessageDigestSpi
      extended byjava.security.MessageDigest 
 
 This MessageDigest class provides applications the functionality of a
 message digest algorithm, such as MD5 or SHA. 
 
 MessageDigest md = MessageDigest.getInstance("MD5");
 byte[] hashConde;
 md.update(number.getBytes());
 hashConde = md.digest(); 
 


 byte[] digest()
          Completes the hash computation by performing final operations such as padding. 取的值須儲存為byte[] 型態
 
 
參考 http://caterpillar.onlyfun.net/Gossip/Encoding/String.html
 byte[] getBytes()
          Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. 使用平台預設的編碼, 儲存為byte陣列
 




參考 http://www.dotblogs.com.tw/chhuang/archive/2011/01/19/20883.aspx
 void update(byte[] input)
          Updates the digest using the specified array of bytes. 計算byte[] 的演算法的值(MessageDigest)

2012年9月17日 星期一

在webmin設定DNS

http://antoinecafe.blogspot.tw/2004/09/webmindns.html

啟用 chroot 功能後, 所有與該程式運作相關的檔案必須全部移至更改後的根目錄下。以此版 BIND 為例, 所有設定檔及記錄檔都必須以 /var/named/chroot 為根目錄, 搬到該目錄下 (檔案的內容則不需更改)。相關檔案要擺位的位置, 請參考下表: 相關檔案名稱 啟用 chroot 前檔案 (絕對) 位置 啟用 chroot 後檔案 (絕對) 位置 
工作環境設定檔 
/etc/named.conf 
/var/named/chroot/etc/named.conf 

根網域記錄檔 
/var/named/named.ca 
/var/named/chroot/var/named/named.ca 

本機正解記錄檔 
/var/named/localhost.zone 
/var/named/chroot/var/named/localhost.zone 

本機反解記錄檔 
/var/named/named.local 
/var/named/chroot/var/named/named.local 

網域正解記錄檔 
/var/named/named.flag.com.tw 
/var/named/chroot/var/named/named.flag.com.tw 

網域反解記錄檔 
/var/named/named.203.74.205 
/var/named/chroot/var/named/named.203.74.205 

2012年9月10日 星期一

intent中的俩方法区别


http://zhouxun1026.iteye.com/blog/1618618

public Intent putExtra (String name, double[] value)
设置方法 intent.putExtra("aaa", "bbbb");
获取方法 this.getIntent().getCharSequenceExtra("aaa")

public Intent putExtras (Bundle extras)

设置方法
Bundle bd = new Bundle();
bd.putString("aaa",“bbbb”);
intent.putExtras(bd);
获取方法
Bundle bd=this.getIntent().getExtras();
bd.getString("aaa"));


总结:带s的得通过个Bundle来绑定数据

2012年8月27日 星期一


Lifecycle Flow

Here are the primary processes involved in cloud-to-device messaging:
  • Enabling GCM. An Android application running on a mobile device registers to receive messages.
  • Sending a message. A 3rd-party application server sends messages to the device.
  • Receiving a message. An Android application receives a message from a GCM server.
These processes are described in more detail below.

Enabling GCM

This is the sequence of events that occurs when an Android application running on a mobile device registers to receive messages:

  1. The first time the Android application needs to use the messaging service, it fires off a registration Intent to a GCM server.
    This registration Intent (com.google.android.c2dm.intent.REGISTER) includes the sender ID(註冊後網址列上的ProjectID), and the Android application ID.(APP名稱)
    Note: Because there is no lifecycle method that is called when the application is run for the first time, the registration intent should be sent on onCreate(), but only if the application is not registered yet.
  2. If the registration is successful, the GCM server broadcasts a com.google.android.c2dm.intent.REGISTRATION intent which gives the Android application a registration ID.
    The Android application should store this ID for later use (for instance, to check on onCreate() if it is already registered). Note that Google may periodically(定期) refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.
  3. To complete the registration, the Android application sends the registration ID to the application server. The application server typically通常 stores the registration ID in a database.
The registration ID lasts持續 until the Android application explicitly明確地
 unregisters itself, or until Google refreshes the registration ID for your Android application.
Note: When users uninstall an application, it is not automatically unregistered on GCM. It is only unregistered when the GCM server tries to send a message to the device and the device answers that the application is uninstalled. At that point, you server should mark the device as unregistered (the server will receive a NotRegistered error).
Note that it might take a few minutes for the registration ID to be completed removed from the GCM server. So if the 3rd party server sends a message during this time, it will get a valid message ID, even though the message will not be delivered to the device.

Architectural Overview

Architectural Overview


This section gives an overview of how GCM works.
This table summarizes the key terms and concepts involved in GCM. It is divided into these categories:
  • Components — The physical entities that play a role in GCM.
  • Credentials — The IDs and tokens that are used in different stages of GCM to ensure that all parties have been authenticated, and that the message is going to the correct place.
Components
Mobile Device The device that is running an Android application that uses GCM. This must be a 2.2 Android device that has Google Play Store installed, and it must have at least one logged in Google account if the device is running a version lower than Android 4.0.4. Alternatively, for testing you can use an emulator running Android 2.2 with Google APIs.
3rd-party Application Server An application server that developers set up as part of implementing GCM in their applications. The 3rd-party application server sends data to an Android application on the device via the GCM server.
GCM Servers The Google servers involved in taking messages from the 3rd-party application server and sending them to the device.
Credentials
Sender ID A project ID you acquire from the API console, as described in Getting Started. The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device.
Application ID The Android application that is registering to receive messages. The Android application is identified by the package name from the manifest. This ensures that the messages are targeted to the correct Android application.
Registration ID An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
Google User Account For GCM to work, the mobile device must include at least one Google account if the device is running a version lower than Android 4.0.4.
Sender Auth Token An API key that is saved on the 3rd-party application server that gives the application server authorized access to Google services. The API key is included in the header of POST requests that send messages.

GCM Architectural Overview

GCM Architectural Overview

Google Cloud Messaging for Android (GCM) is a free service that helps developers send data from servers to their Android applications on Android devices. This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly). The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device.
To jump right into using GCM with your Android applications, see the instructions in Getting Started.

Introduction


Here are the primary characteristics of Google Cloud Messaging (GCM):
  • It allows 3rd-party application servers to send messages to their Android applications.
  • GCM makes no guarantees about delivery or the order of messages.
  • An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
  • It does not provide any built-in user interface or other handling for message data. GCM simply passes raw message data received straight to the Android application, which has full control of how to handle it. For example, the application might post a notification, display a custom user interface, or silently sync data.
  • It requires devices running Android 2.2 or higher that also have the Google Play Store application installed, or or an emulator running Android 2.2 with Google APIs. However, you are not limited to deploying your Android applications through Google Play Store.
  • It uses an existing connection for Google services. For pre-3.0 devices, this requires users to set up their Google account on their mobile devices. A Google account is not a requirement on devices running Android 4.0.4 or higher.

2012年8月25日 星期六

using plain text

If you are using plain text instead of JSON, the message fields must be set as HTTP parameters sent in the body, and their syntax is slightly different, as described below:


Field Description
registration_id Must contain the registration ID of the single device receiving the message. Required.
collapse_key Same as JSON (see previous table). Optional.
data.<key> Payload data, expressed as parameters prefixed with data. and suffixed as the key. For instance, a parameter of data.score=3x1 would result in an intent extra named score whose value is the string 3x1. There is no limit on the number of key/value parameters, though there is a limit on the total size of the message. Note that the key cannot be a reserved word (from or any word starting with google.). Optional.
delay_while_idle Should be represented as 1 or true for true, anything else for false. Optional. The default value is false.
time_to_live Same as JSON (see previous table). Optional.


If you want to test your request (either JSON or plain text) without delivering the message to the devices, you can set an optional HTTP parameter called dry_run with the value true. The result will be almost identical to running the request without this parameter, except that the message will not be delivered to the devices. Consequently, the response will contain fake IDs for the message and multicast fields (see Response format).

For JSON, it must contain a string representing a JSON object with the following fields:

string representing a JSON object with the following fields:
Field Description
registration_ids A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.
collapse_key An arbitrary string (such as "Updates Available") that is used to collapse a group of like messages when the device is offline, so that only the last message gets sent to the client. This is intended to avoid sending too many messages to the phone when it comes back online. Note that since there is no guarantee of the order in which messages get sent, the "last" message may not actually be the last message sent by the application server. See Advanced Topics for more discussion of this topic. Optional, unless you are using the time_to_live parameter—in that case, you must also specify a collapse_key.
data A JSON object whose fields represents the key-value pairs of the message's payload data. If present, the payload data it will be included in the Intent as application data, with the key being the extra's name. For instance, "data":{"score":"3x1"} would result in an intent extra named score whose value is the string 3x1. There is no limit on the number of key/value pairs, though there is a limit on the total size of the message (4kb). Note that the values must be enclosed by strings. If you want to include objects or other non-string data types (such as integers or booleans), you have to do the conversion to string yourself. Also note that the key cannot be a reserved word (from or any word starting with google.). Optional.
delay_while_idle If included, indicates that the message should not be sent immediately if the device is idle. The server will wait for the device to become active, and then only the last message for each collapse_key value will be sent. Optional. The default value is false, and must be a JSON boolean.
time_to_live How long (in seconds) the message should be kept on GCM storage if the device is offline. Optional (default time-to-live is 4 weeks, and must be set as a JSON number). If you use this parameter, you must also specify a collapse_key.

The following table specifies the API Level supported by each version of the Android platform.


Platform VersionAPI LevelVERSION_CODENotes
Android 4.1, 4.1.1 16 JELLY_BEAN Platform Highlights
Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1 Platform Highlights
Android 4.0, 4.0.1, 4.0.2 14 ICE_CREAM_SANDWICH
Android 3.2 13 HONEYCOMB_MR2
Android 3.1.x 12 HONEYCOMB_MR1 Platform Highlights
Android 3.0.x 11 HONEYCOMB Platform Highlights
Android 2.3.4
Android 2.3.3
10 GINGERBREAD_MR1 Platform Highlights
Android 2.3.2
Android 2.3.1
Android 2.3
9 GINGERBREAD
Android 2.2.x 8 FROYO Platform Highlights
Android 2.1.x 7 ECLAIR_MR1 Platform Highlights
Android 2.0.1 6 ECLAIR_0_1
Android 2.0 5 ECLAIR
Android 1.6 4 DONUT Platform Highlights
Android 1.5 3 CUPCAKE Platform Highlights
Android 1.1 2 BASE_1_1
Android 1.0 1 BASE

Migrating Your Apps

Migrating Your Apps


This section describes how to move existing C2DM apps to GCM.

Client changes

Migration is simple! The only change required in the application is replacing the email account passed in the sender parameter of the registration intent with the project ID generated when signing up for the new service. For example:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderID);
startService(registrationIntent);
After receiving a response from GCM, the registration ID obtained must be sent to the application server. When doing this, the application should indicate that it is sending a GCM registration ID so that the server can distinguish it from existing C2DM registrations.
從GCM接收到響應獲得註冊ID必須被發送到應用程序服務器在這樣做時,應用程序應該表明它已被發送一個GCM註冊ID,這樣服務器可以區分從現有的C2DM註冊

Server changes

When the application server receives a GCM registration ID, it should store it and mark it as such.
Sending messages to GCM devices requires a few changes:
  • The request should be sent to a new endpoint: https://android.googleapis.com/gcm/send.
  • The Authorization header of the request should contain the API key generated during sign up. This key replaces the deprecated ClientLogin Auth token.
For example:
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA

{
  "registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
  "data" : {
    "Team" : "Portugal",
    "Score" : "3",
    "Player" : "Varela",
  },
}
For a detailed discussion of this topic and more examples, see the Architectural Overview.
Eventually, once enough users of your application have migrated to the new service, you might want to take advantage of the new JSON-formatted requests that give access to the full set of features provided by GCM.

2012年8月24日 星期五

append()

append()

http://blog.xuite.net/x_3kkk/java/11386460-%E5%AD%97%E4%B8%B2%E7%9A%84%E6%96%B0%E5%A2%9E%E8%88%87%E6%8F%92%E5%85%A5+%28+append+%2F+insert+%29

2012年8月15日 星期三

compile kernel error

out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1

1. Install gcc4.4
apt-get gcc-4.4 and gcc-4.4-multilib and do
2. Use this command to build
make CC=gcc-4.4 CXX=g++-4.4

https://groups.google.com/forum/#!msg/android-building/GhtCJSBDwUw/WkKtUiNB_moJ[1-25]


out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt

2012年8月8日 星期三

Java note

@link:
/** 
  *亂說一同
  * @link package.class #getValue 
  * @param   
  * @see #getValue 
  */ @link是一個連接標記,在doc裡會多增加一個See Also(默認的類是自己) #member label就是把@see獲取到。你可以試一下就明白了
http://topic.csdn.net/t/20031222/14/2589902.html


@SuppressWarnings

hiding to suppress warnings relative to locals that hide variable

http://www.thebuzzmedia.com/supported-values-for-suppresswarnings/ 




java.lang.Object
  extended by IntentService
      extended by com.google.android.gcm.GCMBaseIntentService
Field Summary
static java.lang.StringTAG 
public class GCMIntentService extends GCMBaseIntentService { // @SuppressWarnings("hiding") private static final String TAG = "GCMIntentService"; public GCMIntentService() { super("SENDER_ID"); }


 protected GCMBaseIntentService(String senderId) {
        // name is used as base name for threads, etc.
        super("GCMIntentService-" + senderId + "-" + (++sCounter));
        mSenderId = senderId;
    }
Constructor Summary
protectedGCMBaseIntentService()            Constructor that does not set a sender id, useful when the sender id is context-specific.
protectedGCMBaseIntentService(java.lang.String... senderIds)            Constructor used when the sender id(s) is fixed.




2012年7月13日 星期五

Study English

set up 設定
receive 接收
proper 正確
simply 簡單地


It does not provide any built-in user interface or other handling for message data.
GCM simply passes raw message data received straight to the Android application,
GCM簡單地傳送原始訊息


2012年6月27日 星期三

[Win7 64]Eclipse 抓不到 Android 設備解決

  1. 安裝JDK (設定PATH)
  2. 安裝ADT
  3. 安裝Android SDK (不能安裝請參考 http://www.wretch.cc/blog/DavidHo/907412 )
  4. 找不到Android 實體設備,確認Eclipse ADT中此檔案是否有裝
  5. 安裝過程中,裝置管理員即會找設備並安裝 Driver 
  6. 裝置管理員已經找到:


2012年6月8日 星期五

解決 VSFTP 無法上傳的問題



修改
 vi /etc/vsftpd/vsftpd.conf
把 anon_upload_enable=YES  前面註解的# 移除即可(不需要重新開FTP Server)




2012年6月5日 星期二

原來Ubuntu 內建沒有Gparted分割軟體@@

原來Ubuntu 內建沒有Gparted分割軟體@@
只有Live CD開機會有
只要手動從 Ubuntu Software Center 搜尋 "gparted" 安裝完成囉

Java \r \n

原先以為 \n 即可換行
但是寫個JAva程式輸出文字到windows 記事本後
發現\n 無效
必須也要加入\r
於是開始找網路資料才知道
而且一定要先 \r 再 \n
不能 \n \r

例如
char asus[] = {'A','S','U','S','\r','\n'};
String str = "End of file";
->正確換行


char asus[] = {'A','S','U','S','\n','\r'};
String str = "End of file";
->不能換行


这个跟操作系统有关
\r Mac
\n Unix/Linux
\r\n Windows
http://zhidao.baidu.com/question/234228652.html

find, grep

 find . -name "*.c" -exec grep "capacity" {} =nH \;
search .c file with "capacity"

2012年6月4日 星期一

[HTC One X]Howto: Compile Your Own Kernel


sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev g++-multilib lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev git

get One X source code from  http://htcdev.com/devcenter/downloads
I use Carrier is hTC Asia




download tool chain from:
https://sourcery.mentor.com/sgpp/lite/arm/portal/release1802


IA32 GNU/Linux TAR c6930d14801b4fab6705d72df013e58b

cd [Your kernel source]

make  endeavoru_android_defconfig (be found from kernel/arch/arm/configs/

make  endeavoru_android_defconfig ARCH=arm CROSS_COMPILE=/home/howy/android/arm-2010q1/bin/arm-none-linux-gnueabi-

make -j5 ARCH=arm CROSS_COMPILE=/home/howy/android/arm-2010q1/bin/arm-none-linux-gnueabi-

Result: Kernel: arch/arm/boot/zImage is ready




refer
http://rootzwiki.com/topic/8824-howto-compile-your-own-kernel-v-01/



boot.img tool
http://forum.xda-developers.com/showthread.php?t=562318
download:
http://forum.xda-developers.com/attachment.php?attachmentid=229872&d=1253485580


./mkbootimg --kernel /home/howy/kernel/arch/arm/boot/zImage --ramdisk /home/howy/ramdisk.img --output boot.img







relpace the boot.img on HTC One X

 root@howy-U53Jc:/root/android-sdks/platform-tools# ./fastboot flash boot /home/howy/boot.img


2012年5月31日 星期四

yum install xinetd


[root@howy public_html]# yum install xinetd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.stuhome.net
 * extras: mirrors.stuhome.net
 * updates: mirrors.stuhome.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package xinetd.x86_64 2:2.3.14-33.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch            Version                    Repository     Size
================================================================================
Installing:
 xinetd          x86_64          2:2.3.14-33.el6            base          120 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 120 k
Installed size: 259 k

Is this ok [y/N]: y
Downloading Packages:
xinetd-2.3.14-33.el6.x86_64.rpm                                                                                                                  | 120 kB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 2:xinetd-2.3.14-33.el6.x86_64                                                                                                                        1/1

Installed:
  xinetd.x86_64 2:2.3.14-33.el6

Complete!


21.2.6 針對實體帳號的設定
http://linux.vbird.org/linux_server/0410vsftpd.php#server_real



[root@howy public_html]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> on
ftpd_connect_db --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off

2012年5月26日 星期六

5/29 還是發生一樣問題:
[root@howy ~]# service mysqld status
mysqld 已停止執行但 subsys 被鎖定
決定先關閉自動備份功能
有空再試試看這個方式
http://bbs.nsysu.edu.tw/txtVersion/boards/linux/M.1189311466.AI.html

___________________________
早起床發現網站
Can't connect to local MySQL server through socket


檢查log:
vi /var/log/mysqld.log
tail -n 20 /var/log/mysqld.log

InnoDB: using the same InnoDB data or log files.


120521  4:47:54  InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1
120521  4:47:54  InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/operating-system-error-codes.html
InnoDB: Could not open or create data files.
InnoDB: If you tried to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
120521  4:47:54 [ERROR] Plugin 'InnoDB' init function returned error.
120521  4:47:54 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120521  4:47:54 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
120521  4:47:54 [ERROR] Do you already have another mysqld server running on port: 3306 ?
120521  4:47:54 [ERROR] Aborting
120521  4:47:54 [Note] /usr/libexec/mysqld: Shutdown complete
120521 04:47:54 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120521 04:47:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120521  4:47:57  InnoDB: Initializing buffer pool, size = 8.0M
120521  4:47:57  InnoDB: Completed initialization of buffer pool
InnoDB: Unable to lock ./ibdata1, error: 11



先用這方法 (暫時恢復運作)
http://www.neo.com.tw/archives/92

發生找不到 mysql.sock 的處理方法!Posted by Neo on 三月 - 16 - 2004
9 Comments出現以下的訊息:
Got an error: Connection error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
mysql.sock 突然消失算是常見的問題,如果是第一次安裝MySQL才出現,那只要找出 mysql.sock 在哪裡就可以了。
以上述的錯誤訊息,mysql.sock 應該是在 /var/lib/mysql/ 裡面 ,如果沒有的話,就下:
#find / -name mysql.sock
來找看看放在哪裡,找到之後再下:
#mysqladmin -S /找到路徑/mysql.sock -u root {參數}
那...如果是突然不見的,或是都找不到怎麼辦?
那只好重新啟動 mysql 了,tarball 安裝可以透過 mysqld 或 mysqladmin 重新啟動,rpm 安裝可以透過 service mysql restart 。但是在 mysql.sock 不見的情況下,可能是無法重新啟動 mysql 的,如果真的不行,只好先下:
#ps -aux|grep mysql
再把看到的 pid 先砍了
#kill 看到的pid
確定全部都殺完了,再看一次還有沒有
#ps -aux|grep mysql
確定裡面的 mysql 都沒有了,然後再執行 mysqld 或是 service mysql start 就可以了。

做了兩個設定,過幾天再看看有無再出現問題:

1.嘗試這個指令
I had the same problem with Mysql 4.1.12 after recieving a SELinux update throught the RedHat Network. Editing /etc/selinux/config so the it says:
SELINUX=permissiveFixed my problem.http://www.linuxforums.org/forum/servers/17376-mysql-server-wont-start-port-conflick.html
 改 /etc/selinux/config


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=permissive
#by Howy 2012/5/27

# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted



2.參考IBM網站
http://www-900.ibm.com/cn/support/viewdoc/detail?DocId=2011073000000執行:
mysql_install_db相关介绍http://hi.baidu.com/ostech/blog/item/6f838f7c1b3d00330dd7da38.html
[root@howy ~]# mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h howy.tw password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!

再看看log
[root@howy howy]# tail -n 20 /var/log/mysqld.log
120527  9:56:48  InnoDB: Completed initialization of buffer pool
120527  9:56:49  InnoDB: Started; log sequence number 0 44233
120527  9:56:49 [Note] Event Scheduler: Loaded 0 events
120527  9:56:49 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
120527 11:08:19 [Note] /usr/libexec/mysqld: Normal shutdown
120527 11:08:19 [Note] Event Scheduler: Purging the queue. 0 events
120527 11:08:19  InnoDB: Starting shutdown...
120527 11:08:23  InnoDB: Shutdown completed; log sequence number 0 44233
120527 11:08:23 [Note] /usr/libexec/mysqld: Shutdown complete
120527 11:08:23 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120527 11:09:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120527 11:09:08  InnoDB: Initializing buffer pool, size = 8.0M
120527 11:09:08  InnoDB: Completed initialization of buffer pool
120527 11:09:09  InnoDB: Started; log sequence number 0 44233
120527 11:09:09 [Note] Event Scheduler: Loaded 0 events
120527 11:09:09 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution



























2012年5月13日 星期日

Abocom WA-160CUN (RT5370) on CentOS6.2 x64


感謝這篇文章讓我把USB無線網卡裝到CentOShttp://hi.baidu.com/yunsuanfu/blog/item/8375ee039e5a7e114afb51ff.html 



請先裝gcc compile相關套件(我是在安裝CentOS 時就選入)
下載 ralink rt5370 driver檔名如下:
(2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2)

我的步驟

#cd 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO/
#vi os/linux/config.mk
HAS_WPA_SUPPLICANT
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT把n都改成y

# vi /etc/modprobe.d/blacklist.conf,最後面加入兩行:
   blacklist rt5370lib
   blacklist rt5370usb
#make clean
#make;make install
#modprobe rt5370sta
#reboot
重新開機完成, 網路設定就有介面可以設定上網了

補充:我有多這步驟

# vi/etc/modprobe.d/modprobe.conf

(新文件)加入以下內容

alias ra0 rt5370



參考: https://wiki.archlinux.org/index.php/Rt2870
http://linux.vbird.org/linux_server/0130internet_connect.php#wireless_connect
http://yishin-li.blogspot.com/2011/11/setting-up-zyxel-nwd2105-for-centos-5.html


引用

CentOS 安装USB无线网卡驱动
2012-01-18 22:54
为了避免布线,所以买了一个USB的无线网卡,tp-link的,是TL-WN727N,花了70大洋买的,没想到芯片跟水星的29元的一样,悲催,真不知道有啥区别,上一篇文章说装GCC,主要就是为了安装这个网卡的驱动,网上搜了一下资料,发现还不错,官方提供了linux的驱动源码,当然是芯片的驱动
这个网卡的芯片是RT5370的,所以首先得去官方下载驱动http://www.ralinktech.com/cn/04_support/support.php?sn=501
最好还是用root账户登录
1、将下载的驱动源码解压,然后最好命名一个简短的文件夹名,方便命令行里的操作
2、在os/linux/config.mk中找到HAS_WPA_SUPPLICANT以及HAS_NATIVE_WPA_SUPPLICANT_SUPPORT,将他们的值都设为”y”(不含引号)
3、屏蔽系统自带的驱动:编辑 /etc/modprobe.d/blacklist.conf,加入下面两行:
   blacklist rt2800lib
   blacklist rt2800usb
这一步到底有没有用,真不知道,网上是这样写,就照做吧,咱是菜鸟

下面这几步都是在字符界面,即控制台中用命令来操作的
4、进入到源码的根目录,在源码根目录下:make && make install
5、完成上面这些工作,就可以加载模块了:
   modprobe rt5370sta
6、加载完模块,就可以回到图形界面,像配置windows无线上网一样配置CentOS了,呵呵


參考文件
http://hi.baidu.com/yunsuanfu/blog/item/8375ee039e5a7e114afb51ff.html

2012年5月10日 星期四

[原創翻譯]Activity

Creating an Activity
To create an activity, you must create a subclass of Activity (or an existing subclass of it). In your subclass, you need to implement callback methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed. The two most important callback methods are:
建立一個activity,必須創建activity的子類別(或是已存在一個子類別)在子類別中,需要執行叫回的方法,此方法是系統呼叫activity在生命周期的不同狀態轉換時,如activity被創建,停止,恢復或毀壞的時候。兩個重要的叫回方法是:
onCreate()
You must implement this method. The system calls this when creating your activity. Within your implementation, you should initialize the essential components of your activity. Most importantly, this is where you must call setContentView() to define the layout for the activity's user interface.
必須執行此方法。當創建activity時系統會呼叫 onCreate() ,當執行時,應該要初始化activity的必要元件。最重要的是,必須呼叫setContentView()以定義版面activity的使用者介面
onPause()
The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).
使用者離開activity的第一個指示時(儘管不總是說activity毀壞系統呼叫這個方法onPause()通常應該做改變,應該保持跳出使用者的會話(因為使用者可能回不來)
There are several other lifecycle callback methods that you should use in order to provide a fluid user experience between activities and handle unexpected interuptions that cause your activity to be stopped and even destroyed. All of the lifecycle callback methods are discussed later, in the section aboutManaging the Activity Lifecycle.
有很多其他生命週期叫回方法,應該使用他們以提供 activity 和處理意外中斷之間有流暢的用戶體驗,這些意外會導致 activity 停止甚至毀壞。



Implementing a user interface

The user interface for an activity is provided by a hierarchy of views—objects derived from the View class. Each view controls a particular rectangular space within the activity's window and can respond to user interaction. For example, a view might be a button that initiates an action when the user touches it.
activity使用者介面由以下提供: views—objects 的層級,從 View class 的物件取得
Android provides a number of ready-made views that you can use to design and organize your layout. "Widgets" are views that provide a visual (and interactive) elements for the screen, such as a button, text field, checkbox, or just an image. "Layouts" are views derived from ViewGroup that provide a unique layout model for its child views, such as a linear layout, a grid layout, or relative layout. You can also subclass the View and ViewGroup classes (or existing subclasses) to create your own widgets and layouts and apply them to your activity layout.
The most common way to define a layout using views is with an XML layout file saved in your application resources. This way, you can maintain the design of your user interface separately from the source code that defines the activity's behavior. You can set the layout as the UI for your activity withsetContentView(), passing the resource ID for the layout. However, you can also create new Views in your activity code and build a view hierarchy by inserting new Views into a ViewGroup, then use that layout by passing the root ViewGroup to setContentView().
For information about creating a user interface, see the User Interface documentation.
以上來源: http://developer.android.com/guide/topics/fundamentals/activities.html
原創翻譯,若有更好的描述歡迎指正批評,謝謝