Blog Archives


To check a string exists in other string in JavaScript, we can use indexOf function, if exists this function return 》=0 value,otherwise it will return -1.

For example:

if(str.indexOf(substr)>=0){

// exist

} else{

// not exist

}

2 Steps to find and download ebooks


When I find some very interesting books on amazon,  i will find if there exists any ebooks about thme, at this time i will search it at google, but now i use stepor ebooks(http://ebooks.stepor.com).

In stepor ebooks website, we will find some ebooks on pdf, epub, mobi, chm, doc and ppt, all of books download links is collected by search engine.

stepor ebook

If you want to download some ebooks by it, you can do like this:

Step 1: open stepor ebook(http://ebook.stepor.com) and find what you plan to download.

to find ebook you plan to download is very easy, you can brow this website to get, you also can search to find by book title.

Step 2: Click to download this book by download links indexed by this website.

Stepor ebook has indexed some download links of books, you can choose one to download.

Category: Internet

TAG

1 Step to make table center in div by css


When i am designing a website, you may need a table be center in div, It may like this:

table is center in div

To realize this effect is simple, we can do like these steps:

Step 1: Use css to control table to show

Look at code below, to make a table be center in div, we should make table margin-left and margin-right style is auto.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>table is center in div</title>
</head>
<style type="text/css">
#wrap{border:#333333 solid 1px; padding:20px 0px;}
#wrap table{margin-left:auto; margin-right:auto; border:#ff6600 solid 1px;}
</style>
<body>
<div id="wrap">
 <table><tr><td> Table is center in div </td></tr></table>
</div>
</body>
</html>

Then open this page by your browser, you will get result like above.

2 Steps to get more backlinks for your website


Many friends ask me about question: how to get backlinks for our websites, after more backlinks, more website traffic. but as to me this question is simple,meanwhile it is hard,if you do nothing about your website backlinks, you will find this question is very hard to you, but if you do as follows, you will find this question is very easy.

Step 1:Write content for your website

Once you have a website, meanwhile you add several articles to your website then you can add your article url at others’ website and get backlinks from them. So if you want get or add more backlinks, first thing you have to do is add content to your website.

Step 2:Visit some related blog on your article by google

After you have added an article to your website, then you will get a article url, which you can paste it to others’ website and we can find these website by google.

Fox example, if you have written an article “2 steps to get more backlinks for your website“, then you can copy this title to google search input form then search it.

Then you will get some search results on “2 steps to get more backlinks for your website“, these article links in search result is related your article and you can visit them and leave your comments and article url. When you do it for several days, you will find you will get more backlinks for your website.

Tips and Warnings:

(1)When you are making comments at others’ website, you should be responsible and careful so that those webmaster or blogger do not think you are a spammer.

Category: Internet


If you are a blogger like me, you may be very interested in how may blog pages are indexed by google, so if you want to know answer of this question, you can follow me.

Step 1: Search your website by using Site:your website domain name

To know how many pages of your blog or website have been indexed by google, you can search your website by google, for example, if you have a blog website as me, and domain name is http://www.stepor.com,  to know how many pages have been indexed, you can search your website like this: site:www.stepor.com.

Then you will get a search result like below:

stepor indexed by google 1

From picture i know about 131 pages have been indexed by google. then you can do like this to get number of your website.

Step 2:  Get effective number of your pages indexed by google

As to me, when i see eighth page of google search result, i found the indexed number of my blog website indexed by google changed, it change to 128 from 131, look at picture below:

stepor indexed by google 2

You may say why? from my perspective, there are 3 (131-128) pages of my blog website indexed by google just now or a few days, they are not put into google index database, so you can know 131 in first page in google search result, but 128 in other pages.

Tips and Warnings:

(1) To get more accurate number of your pages indexed by google, you can use webmaster tool of google.

Category: Internet

TAG


Sometimes, we need read an image in assets directory to display in android, at this situation, we may need read data of image into a byte array so that we can use it in other place of our program. To read data of an image into a byte data is very simple, we can do like this:

Step 1: Put an image into assets directory in Android project

Before we start to coding, we should place an image into assets directory in android project, it may like this:

image in assets directory

Step 2: Read data of image into a byte array

After we have place an image into assets directory, we can read its data into a byte array, this sample code realize read data of an image  in assets directory into a byte array, then display it on imageview.

show image from assets in android

Smaple code like this:


public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ImageView imageView = (ImageView) this.findViewById(R.id.image_id);
 //read an image in assets
 byte[] data = readImageFromAssets("logo.png");
 Bitmap bitmap = null;
 try {
 bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
 } catch(Exception e) {
 if(null != bitmap) {
 bitmap.recycle();
 bitmap = null;
 }
 }
 if(bitmap != null) {
 Drawable drawable =new BitmapDrawable(bitmap);
 imageView.setBackgroundDrawable(drawable);
 }
 }
 /** read a image into byte array from assets */
 private byte[] readImageFromAssets(String imageName) {
 InputStream is = null;
 ByteArrayOutputStream out = null;
 try {
 is = getBaseContext().getAssets().open(imageName);
 out = new ByteArrayOutputStream(1024);
 byte[] temp = new byte[1024];
 int size = 0;
 while ((size = is.read(temp)) != -1) {
 out.write(temp, 0, size);
 }
 byte[] content = out.toByteArray();

 if(is != null) {
 is.close();
 }
 if(out != null) {
 out.close();
 }
 return content;
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {

 }
 return null;

 }

3 Steps to delete all comments in wordpress


Recent days, my wordpress blog have received many spam comments, i think most of them are sent by some softwares automatically, which brings me a lot of inconvenience, so i plan to delete all comments in my wordpress blog, how to do it ? We can do like this:

Step 1: Use Plugin Delete All Comments

We can use plugin Delete All Comments to help us to delete all comments in wordpress, this plugin is very small and easy to use. you can down it at Delete All Comments In WordPress.

Step 2: Install Delete All Comments plugin and active it

After you have downloaded this plugin, you can install it, to question:How to install it, you can read article: 2 Steps to install wordpress plugin.
After you have installed, you should activate it to make it work.

Step 3: Delete All Comments

After you have activated it you may find it on your Tools:

Delete All Comments

Then click Delete All Comments item, you will see a page like this:

Delete All Comments Action

Then click Delete All, all comments in your wordpress will be deleted.


To know difference between 302 Moved Temporarily and 302 Found is easy, both of them respect “The requested resource resides temporarily under a different URI”, and difference of them are because different of http protocol.

Step 1: 302 response code HTTP 1.0

In http 1.0,302 response code will displayed as 302 Moved Temporarily, you can get more detail information in HTTP 1.0 302 Code.

Step 2: 302 response code HTTP 1.1

In http 1.1, 302 response code will displayed as 302 Found, and you can get more detail information in HTTP 1.1 302 Code.


In article “2 Steps to solve problem:Can’t create handler inside thread that has not called Looper.prepare() in Android“, We know a truth: a toast can not be run in no-ui thread in android, if you should realize it you should use Looper.prepare().

How to use Looper.prepare() you may ask me, you can use it like follow steps:

Step 1: Effect of Loop.prepare() and Looper.loop()

In Anroid Looper you can get some very useful information on Loop.prepare, however, if you think that is too hard to you ,you can understand it like this.

Loop.prepare and Looper.loop() can create a ui thread, then you can run some ui process between them.

Step 2: Example of using Loop.prepare() and Looper.loop()

To understand how to use Loop.prepare() and Looper.loop(), you can read example below.

We know we can not show a toast in a no-ui thread in android, so if you run this code below, you will find a toast will be showed in ui thread.


public class TestActivity extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState){
 super.onCreate(savedInstanceState);
 this.setContentView(R.layout.test);
 Button btn = (Button) this.findViewById(R.id.back_id);
 btn.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 new Thread(new Runnable(){

@Override
 public void run() {
 // TODO Auto-generated method stub
 Looper.prepare();
 showToast("Toast run in sub thread");
 Looper.loop();
 }

 }).start();
 }
 });
 showToast("Toast run in UI thread");
 }
 private void showToast(String msg) {
 Toast.makeText(TestActivity.this, msg, Toast.LENGTH_LONG).show();
 }
}

However, if you plan to show it in a no-ui thread,you must use key code:


Looper.prepare();
showToast("Toast run in sub thread");
Looper.loop();

Then we will create a ui thread, which can show my toast.

taost run in sub thread

Tips and Warnings:

(1) code above if you remove Loop.prepare() and Looper.loop(), this application will break down and stop.


Today when i programming a android project, i met with this problem:

Can’t create handler inside thread that has not called Looper.prepare()

From the error message, we should create a handler after calling Looper.prepare.

However, i know i have not used handler in code snippet when problem occurred.

This code snippet is:

new Thread() {
 @Override
 public void run() {
 super.run();
 String url = HaikangVideoManager.getRTSPURL(cameraID);
 if("".equals(url)) {
 Toast.makeText(context, "url invalid", Toast.LENGTH_LONG).show();
 return;
 }
 mLiveControl.setLiveParams(url, HaikangVideoManager.mName, HaikangVideoManager.mPassword);
 if(mLiveControl.LIVE_PLAY == mLiveControl.getLiveState()){
 mLiveControl.stop();
 }
 if (mLiveControl.LIVE_INIT == mLiveControl.getLiveState()) {
 mLiveControl.startLive(surfaceView);
 }
 }
 }.start();

How to solve this problem? you can do as follow step.

Step 1: Find position of problem occurred

Only when i find position of problem occurred, we can solve this problem easily, by logcat tool in  eclipse, we can find it very easily.

Step 2: Analysis this problem and Solve it

By Logcat tool, i know this problem occurred in Toast.makeText(context, “url invalid”, Toast.LENGTH_LONG).show();

Then i know why this problem occurred, because Tost.make should be run in main thread in android, but no in a sub thread.

To solve this problem is very simple, remove Toast.makeText(context, “url invalid”, Toast.LENGTH_LONG).show();


In Android project, we often have to get the height and width of a device, so that we can change our size of our ui to adjust to different devices, In android, to get these two information is simple, you can do one step.

Step 1: Use DisplayMetrics to get width and height of a device

In android, wen can use class DisplayMetrics to get the with and height of a device, code like this:


private void getScreenSize(){
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels; // width of screen
int screenHeight = dm.heightPixels;// height of screen
}

From code above, the screenWidth and screenHeight are what you want.


In article 2 Steps to know whether vistors use mobile to visit your website in PHP, we introduce a way by check the device type of visitors are using to display different scale page to visitors, however, we can check the width and height of  visitors’ browser to realize too, and this article will give some useful information to you.

Step 1: To get width and height of browser by JavaScript

To get width and height by javascript is not hard, we can use code below to realize it.


<script>
var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;

alert("w="+w+ " h="+h);
</script>

Then we will run this code to know width and height.

Step 2: Analysis the result

Run code above we will get a result like below:

get browser width and height

From this picture, we will know we get the width of height of displaying content, not the width and height of the whole browser.