Pinyin4j Helper类

package com.mtjst.im.util;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class HanyuPinyinHelper {

	public static boolean isChineseCharacter(char c) {
		int i = (int) c;
		return (i >= 0x4e00 && i <= 0x9fa5);
	}

	public static String getPinyin(String str) {

		StringBuffer sb = new StringBuffer();

		char[] ca = str.toCharArray();

		HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();

		format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
		format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
		format.setVCharType(HanyuPinyinVCharType.WITH_V);

		for (int i = 0; i < ca.length; i++) {
			if (isChineseCharacter(ca[i])) {
				try {
					sb.append(PinyinHelper.toHanyuPinyinStringArray(ca[i],
							format)[0]);
				} catch (BadHanyuPinyinOutputFormatCombination e) {
					e.printStackTrace();
				}
			} else {
				sb.append(ca[i]);
			}
		}

		return sb.toString();
	}
}

 

发表在 android | 留下评论

android AutoCompleteTextView 自定义Adapter

package com.mtjst.im.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import com.mtjst.im.R;
import com.mtjst.im.model.District;

public class DistrictAdapter extends BaseAdapter implements Filterable {

	private LayoutInflater inflater;
	private List<District> mOriginalValues;
	private List<District> districts;

	public DistrictAdapter(Context context, List<District> districts) {
		this.inflater = LayoutInflater.from(context);
		this.districts = districts;
	}

	public void refreshData(List<District> districts) {
		this.districts = districts;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_district, parent,
					false);
			viewHolder.district = (TextView) convertView
					.findViewById(R.id.district);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		District district = this.districts.get(position);

		viewHolder.district.setText(district.getName());
		return convertView;
	}

	class ViewHolder {
		TextView district;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return districts.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return districts.get(position).getName();
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public Filter getFilter() {
		Filter filter = new Filter() {

			@SuppressWarnings("unchecked")
			@Override
			protected void publishResults(CharSequence constraint,
					FilterResults results) {

				districts = (List<District>) results.values;
				notifyDataSetChanged();
			}

			@Override
			protected FilterResults performFiltering(CharSequence constraint) {

				FilterResults results = new FilterResults();
				List<District> FilteredArrList = new ArrayList<District>();

				if (mOriginalValues == null) {
					mOriginalValues = new ArrayList<District>(districts);
				}

				if (constraint == null || constraint.length() == 0) {
					results.count = mOriginalValues.size();
					results.values = mOriginalValues;
				} else {
					constraint = constraint.toString().toLowerCase();
					for (int i = 0; i < mOriginalValues.size(); i++) {
						District data = mOriginalValues.get(i);
						// if (data.getPinyin().startsWith(
						// HanyuPinyinHelper.getPinyin(constraint
						// .toString()))) {
						// FilteredArrList.add(data);
						// }
						FilteredArrList.add(data);
					}
					// set the Filtered result to return
					results.count = FilteredArrList.size();
					results.values = FilteredArrList;
				}
				return results;
			}
		};

		return filter;
	}
}

 

发表在 android | 留下评论

android 编译 volley

设置环境变量

export PATH=$PATH:/Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools:/usr/local/ant/bin:/Applications/adt-bundle-mac-x86_64-20140702/sdk/tools

ant去官网下载二进制包, android命令在adt-bundle-mac-x86_64-20140702/sdk/tools下

下载volley源码

https://github.com/mcxiaoke/android-volley/archive/master.zip

进入volley目录

执行

android update project -p . -t android-20 -s

android-20可以执行 android list targets 命令得到

id: 1 or "android-20"
     Name: Android 4.4W
     Type: Platform
     API level: 20
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.

最后执行 ant jar

就会在bin目录生成volley.jar

发表在 android | 留下评论

搜索文件夹内的所有文件里包含某字符串的linux命令

从文件内容查找匹配指定字符串的行:
$ grep “被查找的字符串” 文件名
从文件内容查找与正则表达式匹配的行:
$ grep –e “正则表达式” 文件名
查找时不区分大小写:
$ grep –i “被查找的字符串” 文件名
查找匹配的行数:
$ grep -c “被查找的字符串” 文件名
从文件内容查找不匹配指定字符串的行:
$ grep –v “被查找的字符串” 文件名
从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR”的行
find / -type f -name “*.log” | xargs grep “ERROR”

发表在 Linux | 留下评论

CentOS升级openssl为最新版

wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
tar zxvf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j.tar.gz
make && make install

mv /usr/bin/openssl /usr/bin/openssl.OFF

mv /usr/include/openssl /usr/include/openssl.OFF

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

ln -s /usr/local/ssl/include/openssl /usr/include/openssl

echo “/usr/local/ssl/lib”>>/etc/ld.so.conf

ldconfig -v

openssl version -a

发表在 Linux | 留下评论

mosquitto — an MQTT broker

Name

mosquitto — an MQTT broker

Synopsis

mosquitto [-c config file] [ -d | –daemon ] [-p port number] [-v]

Description

mosquitto is a broker for the MQTT protocol version 3.1.

Options

-c, --config-file
Load configuration from a file. If not given, the default values as described in mosquitto.conf(5) are used.

-d, --daemon
Run mosquitto in the background as a daemon. All other behaviour remains the same.

-p, --port
Listen on the port specified instead of the default 1883. This acts in addition to the port setting in the config file. May be specified multiple times to open multiple sockets listening on different ports. This socket will be bound to all network interfaces.

-v, --verbose
Use verbose logging. This is equivalent to setting log_type to all in the configuration file. This overrides and logging options given in the configuration file.

Configuration

The broker can be configured using a configuration file as described in mosquitto.conf(5) and this is the main point of information for mosquitto. The files required for SSL/TLS support are described in mosquitto-tls(7).

Broker Status

Clients can find information about the broker by subscribing to topics in the $SYS hierarchy as follows. Topics marked as static are only sent once per client on subscription. All other topics are updated every sys_interval seconds. If sys_interval is 0, then updates are not sent.

$SYS/broker/bytes/received
The total number of bytes received since the broker started.

$SYS/broker/bytes/sent
The total number of bytes sent since the broker started.

$SYS/broker/changeset
The repository changeset (revision) associated with this build. Static.

$SYS/broker/clients/active
The number of currently connected clients

$SYS/broker/clients/expired
The number of disconnected persistent clients that have been expired and removed through the persistent_client_expiration option.

$SYS/broker/clients/inactive
The total number of persistent clients (with clean session disabled) that are registered at the broker but are currently disconnected.

$SYS/broker/clients/maximum
The maximum number of active clients that have been connected to the broker. This is only calculated when the $SYS topic tree is updated, so short lived client connections may not be counted.

$SYS/broker/clients/total
The total number of active and inactive clients currently connected and registered on the broker.

$SYS/broker/connection/#
When bridges are configured to/from the broker, common practice is to provide a status topic that indicates the state of the connection. This is provided within $SYS/broker/connection/ by default. If the value of the topic is 1 the connection is active, if 0 then it is not active. See the Bridges section below for more information on bridges.

$SYS/broker/heap/current size
The current size of the heap memory in use by mosquitto. Note that this topic may be unavailable depending on compile time options.

$SYS/broker/heap/maximum size
The largest amount of heap memory used by mosquitto. Note that this topic may be unavailable depending on compile time options.

$SYS/broker/load/connections/+
The moving average of the number of CONNECT packets received by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of connections received in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/bytes/received/+
The moving average of the number of bytes received by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of bytes received in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/bytes/sent/+
The moving average of the number of bytes sent by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of bytes sent in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/messages/received/+
The moving average of the number of all types of MQTT messages received by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of messages received in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/messages/sent/+
The moving average of the number of all types of MQTT messages sent by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of messages send in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/publish/dropped/+
The moving average of the number of publish messages dropped by the broker over different time intervals. This shows the rate at which durable clients that are disconnected are losing messages. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of messages dropped in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/publish/received/+
The moving average of the number of publish messages received by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of publish messages received in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/publish/sent/+
The moving average of the number of publish messages sent by the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of publish messages sent in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/load/sockets/+
The moving average of the number of socket connections opened to the broker over different time intervals. The final “+” of the hierarchy can be 1min, 5min or 15min. The value returned represents the number of socket connections in 1 minute, averaged over 1, 5 or 15 minutes.

$SYS/broker/messages/inflight
The number of messages with QoS>0 that are awaiting acknowledgments.

$SYS/broker/messages/received
The total number of messages of any type received since the broker started.

$SYS/broker/messages/sent
The total number of messages of any type sent since the broker started.

$SYS/broker/messages/stored
The number of messages currently held in the message store. This includes retained messages and messages queued for durable clients.

$SYS/broker/publish/messages/dropped
The total number of publish messages that have been dropped due to inflight/queuing limits. See the max_inflight_messages and max_queued_messages options in mosquitto.conf(5) for more information.

$SYS/broker/publish/messages/received
The total number of PUBLISH messages received since the broker started.

$SYS/broker/publish/messages/sent
The total number of PUBLISH messages sent since the broker started.

$SYS/broker/retained messages/count
The total number of retained messages active on the broker.

$SYS/broker/subscriptions/count
The total number of subscriptions active on the broker.

$SYS/broker/timestamp
The timestamp at which this particular build of the broker was made. Static.

$SYS/broker/uptime
The amount of time in seconds the broker has been online.

$SYS/broker/version
The version of the broker. Static.

Wildcard Topic Subscriptions

In addition to allowing clients to subscribe to specific topics, mosquitto also allows the use of two wildcards in subscriptions. + is the wildcard used to match a single level of hierarchy. For example, for a topic of “a/b/c/d”, the following example subscriptions will match:

  • a/b/c/d
  • +/b/c/d
  • a/+/c/d
  • a/+/+/d
  • +/+/+/+

The following subscriptions will not match:

  • a/b/c
  • b/+/c/d
  • +/+/+

The second wildcard is # and is used to match all subsequent levels of hierarchy. With a topic of “a/b/c/d”, the following example subscriptions will match:

  • a/b/c/d
  • #
  • a/#
  • a/b/#
  • a/b/c/#
  • +/b/c/#

The $SYS hierarchy does not match a subscription of “#”. If you want to observe the entire $SYS hierarchy, subscribe to $SYS/#.

Note that the wildcards must be only ever used on their own, so a subscription of “a/b+/c” is not valid use of a wildcard. The # wildcard must only ever be used as the final character of a subscription.

Bridges

Multiple brokers can be connected together with the bridging functionality. This is useful where it is desirable to share information between locations, but where not all of the information needs to be shared. An example could be where a number of users are running a broker to help record power usage and for a number of other reasons. The power usage could be shared through bridging all of the user brokers to a common broker, allowing the power usage of all users to be collected and compared. The other information would remain local to each broker.

For information on configuring bridges, see mosquitto.conf(5).

Signals

SIGHUP
Upon receiving the SIGHUP signal, mosquitto will attempt to reload configuration file data, assuming that the -c argument was provided when mosquitto was started. Not all configuration parameters can be reloaded without restarting. See mosquitto.conf(5) for details.

SIGUSR1
Upon receiving the SIGUSR1 signal, mosquitto will write the persistence database to disk. This signal is only acted upon if persistence is enabled.

SIGUSR2
The SIGUSR2 signal causes mosquitto to print out the current subscription tree, along with information about where retained messages exist. This is intended as a testing feature only and may be removed at any time.

Files

/etc/mosquitto/mosquitto.conf
Configuration file. See mosquitto.conf(5).

/var/lib/mosquitto/mosquitto.db
Persistent message data storage location if persist enabled.

/etc/hosts.allow, /etc/hosts.deny
Host access control via tcp-wrappers as described in hosts_access(5).

发表在 Linux | 留下评论

Linux查看连接数,并发数

Linux查看连接数,并发数
1、查看apache当前并发访问数:  www.2cto.com
  netstat -an | grep ESTABLISHED | wc -l
  对比httpd.conf中MaxClients的数字差距多少。
  2、查看有多少个进程数:
  ps aux|grep httpd|wc -l
  3、可以使用如下参数查看数据
  server-status?auto
  #ps -ef|grep httpd|wc -l
  1388
  统计httpd进程数,连个请求会启动一个进程,使用于Apache服务器。
  表示Apache能够处理1388个并发请求,这个值Apache可根据负载情况自动调整。
  #netstat -nat|grep -i “80”|wc -l
  4341
  netstat -an会打印系统当前网络链接状态,而grep -i “80”是用来提取与80端口有关的连接的,wc -l进行连接数统计。  www.2cto.com
  最终返回的数字就是当前所有80端口的请求总数。
  #netstat -na|grep ESTABLISHED|wc -l
  376
  netstat -an会打印系统当前网络链接状态,而grep ESTABLISHED 提取出已建立连接的信息。 然后wc -l统计。
  最终返回的数字就是当前所有80端口的已建立连接的总数。
  netstat -nat||grep ESTABLISHED|wc – 可查看所有建立连接的详细记录
  查看Apache的并发请求数及其TCP连接状态:
  Linux命令:
  netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
  返回结果示例:
  LAST_ACK 5
  SYN_RECV 30
  ESTABLISHED 1597
  FIN_WAIT1 51
  FIN_WAIT2 504
  TIME_WAIT 1057
  其中的
  SYN_RECV表示正在等待处理的请求数;
  ESTABLISHED表示正常数据传输状态;
  TIME_WAIT表示处理完毕,等待超时结束的请求数。(这个参数还不太懂,为啥是等待超时结束,请大神指教)
发表在 Linux | 留下评论

android volley 获取网络图片

package com.w3hacker.demo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;

public class MainActivity extends Activity {
	private ImageView image;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		image = (ImageView) findViewById(R.id.image);

		RequestQueue requestQueue = Volley.newRequestQueue(this);

		String url = "http://www.w3hacker.com/wp-content/uploads/2013/10/180.jpg";

		ImageRequest imageRequest = new ImageRequest(url,
				new Listener<Bitmap>() {

					@Override
					public void onResponse(Bitmap response) {
						image.setImageBitmap(response);
					}
				}, 0, 0, Config.RGB_565, new ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {

					}
				});
		
		requestQueue.add(imageRequest);
	}
}

 

发表在 android | 留下评论

android volley获取json array

package com.w3hacker.demo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		String url = "http://www.w3hacker.com/getall.php";

		RequestQueue requestQueue = Volley.newRequestQueue(this);

		JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url,
				new Listener<JSONArray>() {

					@Override
					public void onResponse(JSONArray response) {
						for (int i = 0; i < response.length(); i++) {
							try {
								JSONObject jsonObject = response
										.getJSONObject(i);
								String name = (String) jsonObject.get("name");
								Log.e("MQTT", name);
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
					}
				}, new ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						Log.e("MQTT", error.getMessage());
					}
				});

		requestQueue.add(jsonArrayRequest);
	}
}

 

发表在 android | 留下评论

android volley请求json数据

package com.w3hacker.demo;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		String url = "http://www.w3hacker.com/get.php?name=Musikar";

		RequestQueue requestQueue = Volley.newRequestQueue(this);

		JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, null,
				new Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {

						try {
							String name = (String) response.get("name");
							Log.e("MQTT", name);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}, new ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {

					}
				});
		requestQueue.add(jsonObjectRequest);
	}
}

 

发表在 android | 留下评论