2014年6月12日木曜日
Constraints of multiple layouts listview for android
http://edisonthk.wordpress.com/2014/06/12/constraints-of-multiple-layouts-listview-for-android/
2014年4月21日月曜日
Setup egit for eclipse ADT by install new software
http://edisonthk.wordpress.com/2014/04/21/setup-egit-for-eclipse-adt-by-install-new-software/
2014年4月16日水曜日
Login ssh to server without including username
ssh myserver
How to do it?
nano ~/.ssh/config
host myserver hostname myserverdomain.com user myuser
And save it. No restart is required, just try ssh myserver, and you are login as myuser@myserverdomain.com
2014年1月28日火曜日
LED Blinky with BGScript Programming
http://edisontus.blogspot.jp/2014/01/getting-started-with-development.html
I am going to guide you how to make LED blink (turn on and turn off) in every 1 seconds with BGScript.
Create 3 config files (gatt.xml, hardware.xml, project.xml)
Every file have it's own function and contains the information needed when compile to binary file. These 3 files are config files that is needed and you must always remember to import these in every project. What you needs to do is copy following source code and paste it.hardware.xml is configuration file that related to ble112 hardware configuration.
<?xml version="1.0" encoding="UTF-8" ?>
<hardware>
<sleeposc enable="true" ppm="30" />
<usb enable="false" endpoint="none" />
<txpower power="15" bias="5" />
<usart channel="1" alternate="1" baud="57600" endpoint="api" />
<wakeup_pin enable="true" port="0" pin="0" />
<port index="0" tristatemask="0" pull="down" />
<pmux regulator_pin="7" />
</hardware>
gatt.xml exposes the Bluetooth services and profiles.
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<service uuid="1800">
<description>Generic Access Profile</description>
<characteristic uuid="2a00">
<properties read="true" const="true" />
<value>BG Demo</value>
</characteristic>
<characteristic uuid="2a01">
<properties read="true" const="true" />
<value type="hex">4142</value>
</characteristic>
</service>
<service type="primary" uuid="9000" id="manufacturer">
<characteristic uuid="9100">
<properties read="true" const="true" />
<value type="hex">000780c0ffeef00d</value>
</characteristic>
<characteristic uuid="9101">
<properties read="true" const="true" />
<value>modelnumber</value>
</characteristic>
<characteristic uuid="9106">
<properties read="true" const="true" />
<value>Bluegiga</value>
</characteristic>
</service>
<service uuid="e001">
<description>Battery status</description>
<include id="manufacturer" />
<characteristic uuid="e101" id="xgatt_battery">
<properties read="true" notify="true" />
<value type="hex">ABCD</value>
</characteristic>
</service>
<service uuid="00431c4a-a7a4-428b-a96d-d92d43c8c7cf">
<description>Bluegiga demo service</description>
<characteristic uuid="f1b41cde-dbf5-4acf-8679-ecb8b4dca6fe">
<properties read="true" write="true"/>
<value type="hex">coffee</value>
</characteristic>
</service>
</configuration>
project.xml tell bgbuild what roles played by every xml file.
<project>
<gatt in="gatt.xml" />
<hardware in="hardware.xml" />
<script in="blink.bgs" />
<image out="out.hex" />
</project>
Create blink.bgs
dim flag dim interval # Boot event listener event system_boot(major ,minor ,patch ,build ,ll_version ,protocol_version ,hw) flag = 0 interval = $8000 # Configure the P0_0 as output call hardware_io_port_config_direction(0, 1) # Enable P0_0 pin call hardware_io_port_write(0, 1, 1) # Start a 5 second, one stop timer call hardware_set_soft_timer(interval, 0 ,1) end # Timer event listener event hardware_soft_timer(handle) #declare hardware_set_soft_timer to allow it work as forever loop as recursive if flag = 0 then # When timer expires disable P0_0 pin call hardware_io_port_write(0, 1, 0) call hardware_set_soft_timer(interval, 0 ,1) flag = 1 else # When timer expires enable P0_0 pin call hardware_io_port_write(0, 1, 1) call hardware_set_soft_timer(interval, 0 ,1) flag = 0 end if end
Debug with bgbuild.exe
C:\Bluegiga\ble-1.2.1-91\bin\bgbuild.exe project.xml
Then, binary file out.hex is generated. It is the file we needed to flash into ble112.
BLE SW update tool
Last job
Explaination on blink.bgs
End
2014年1月22日水曜日
Simple guide to ExecutorService Android
What can ExecutorService do? Do you know that powerful AsyncTask method is only allows to be executed one time in single activity. If you execute AsyncTask more then one time in single activity, you will get the errors.
So it is where ExecutorService comes, it help you handle multiple background task which AsyncTask cannot be done.
Try it out!!
<?php echo "hello! I am server."; ?>
package com.example.apps1;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button mButton;
private ExecutorService pool;
public static final String URL = "http://path_to_server/";
private static final String TAG = MainActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mButton = new Button(this);
mButton.setText("Press");
addContentView(mButton, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
pool = Executors.newSingleThreadExecutor();
mButton.setOnClickListener(mClickListener);
}
private View.OnClickListener mClickListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
pool.execute(new NetworkService());
}
};
private class NetworkService implements Runnable {
private Handler mHandler;
public NetworkService(){
mHandler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message inputMessage){
String msg = (String) inputMessage.obj;
Toast.makeText(getApplicationContext(), ""+msg, Toast.LENGTH_SHORT).show();
}
};
}
@Override
public void run() {
String recv = HttpRequest(URL);
sendMessage(1, recv);
}
public void sendMessage(int what, String msg){
Message message = mHandler.obtainMessage(what , msg);
message.sendToTarget();
}
}
// Doing all Networking task, if failed to get message from server, it will return null
//
public String HttpRequest(String url) {
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = null;
try{
HttpGet httpGet = new HttpGet(url);
response = client.execute(httpGet);
return EntityUtils.toString(response.getEntity());
}catch(ClientProtocolException e){
Log.e(TAG,"ClientProtocolException : "+e);
}catch(IOException e){
Log.e(TAG,"IOException : "+e);
}
return null;
}
}
Explanation
- Executors.newSingleThreadExecutor();
- Executors.newFixedThreadPool(10);
- Executors.newScheduledThreadPool(10);
Based on how ExecutorService is instanced, ExecutorService will be working in different way. For more detail please checking Executors API. In this guide, I am using newSingleThreadExecutor, it only allows one task in the same time.
NetworkService is implemented with Runnable. NetworkService is almost same as AsyncTask, contains UI thread callback method, doInBackground method.
In this case, same method of AsnycTask and NetworkService
- doInBackground == run
- onPostExecute == handleMessage
private class NetworkService implements Runnable {
private Handler mHandler;
public NetworkService(){
// Handler looper constructor to declare this handler
// is going to link to UI Thread
mHandler = new Handler(Looper.getMainLooper()){
// handleMessage method is callback of background work.
// All the tasks in handleMessage will be pass to UI thread
//
// This method is same as AsyncTask.onPostExecute
@Override
public void handleMessage(Message inputMessage){
String msg = (String) inputMessage.obj;
Toast.makeText(getApplicationContext(), ""+msg, Toast.LENGTH_SHORT).show();
}
};
}
// Runnable.run method doing all tasks in background
// It is same as AsyncTask.doInBackground
@Override
public void run() {
String recv = HttpRequest(URL);
// Get the result from HttpRequest and past it to handler.
sendMessage(1, recv);
}
public void sendMessage(int what, String msg){
Message message = mHandler.obtainMessage(what , msg);
message.sendToTarget();
}
}
pool.execute(new NetworkService());
End
2014年1月21日火曜日
Quick Guide to Android Networking by Request Message from Server
On Server side
<?php
echo "hello! I am server";
?>
Script it as simple as you can.
On Android side
Android is quiet complicated with Internet. You needs to enable android to access to internet and work your internet thread on background. Before we get start with our tutorial, copy the code below and debug it. It is always simple to understand if you get the things work first.package com.example.apps1;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView mTextView;
private static final String TAG = MainActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextView = new TextView(this);
addContentView(mTextView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
new ConnectToServer().execute();
}
public class ConnectToServer extends AsyncTask<Void,Void,String>{
@Override
protected String doInBackground(Void... params) {
// replace the url to your own
return HttpRequest("http://path_to_server/");
}
@Override
protected void onPostExecute(String result){
if(result == null){
mTextView.setText("Failed to connecting to server");
}else{
mTextView.setText(result);
}
}
public String HttpRequest(String url)
{
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = null;
try{
HttpGet httpGet = new HttpGet(url);
response = client.execute(httpGet);
return EntityUtils.toString(response.getEntity());
}catch(ClientProtocolException e){
Log.e(TAG,"ClientProtocolException : "+e);
}catch(IOException e){
Log.e(TAG,"IOException : "+e);
}
return null;
}
}
}
Replace the url "http://path_to_server" to your own in HttpRequest.
Don't debug it, we haven't done yet. As I mentioned above, you need to configure android to able to access internet. What you needs to do is simple, go to your_project_directory and open AndroidManifest.xml
Add following uses-permission to in front of <uses-sdk> tag
<uses-permission android:name="android.permission.INTERNET" />
Then, debug it and you will see the requested message from server.
Explanation
There are 2 things you need to be careful when programming across internet.- Networking thread must be on background
- Configure internet permission in AndroidManifest.xml
Android is doing a good job for developer, there are built-in background thread method prepared by Android called AsyncTask.
AsyncTask easy us to doing background task coding by put all the background code in doInBackground method. On the code above, HttpRequest method is the internet task and you will find it I put it on doInBackground method. It means the all the task in HttpRequest will be carried out in background thread.
onPostExecute method is a callback method for background thread. After HttpRequest getting the messages, it needs to show it on UI. Here's where onPostExecute comes, the message returned by HttpRequest method is assign to onPostExecute 1st parameter "result". TextView set text of 1st parameter result.
@Override
protected String doInBackground(Void... params) {
// doing all networking thread here
//
// 1st parameter of HttpRequest is the url to server. Replace the url to your own
return HttpRequest("http://path_to_server/");
}
@Override
protected void onPostExecute(String result){
// 1st parameter result is the result returned by HttpRequest which doInBackground
if(result == null){
mTextView.setText("Failed to connecting to server");
}else{
mTextView.setText(result);
}
}
// Doing all Networking task, if failed to get message from server, it will return null
//
public String HttpRequest(String url){
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = null;
try{
HttpGet httpGet = new HttpGet(url);
response = client.execute(httpGet);
return EntityUtils.toString(response.getEntity());
}catch(ClientProtocolException e){
Log.e(TAG,"ClientProtocolException : "+e);
}catch(IOException e){
Log.e(TAG,"IOException : "+e);
}
return null;
}
After coding AsyncTask method, you needs to execute it by
new ConnectToServer().execute();
Be caution here, AsyncTask is easy but it can only be executed one time in single Activity.
It means if you execute AsnycTask for twice, exception will be thrown and you will get errors.
Luckily, Android have prepared another method called ExecutorService. It allows multiple network task can be executed in single activity.
Check it out with my next post, if you are interesting with it.
End
2014年1月19日日曜日
Getting started with Developing Bluetooth 4.0 LE and Android with BLE112 Bluetooth module
http://edisonthk.wordpress.com/2014/01/18/getting-started-with-developing-bluetooth-4-0-le-and-android-with-ble112-bluetooth-module/
2013年11月10日日曜日
Daemon Thread ["http-bio-8080"-exec-2] (Suspended (exception RuntimeException)) on Eclipse for Tomcat 7
Solution
Uncheck suspend execution on uncaught exceptions options in Preferences. Go to Window > Preferences > Java > Debug and uncheck Suspend execution on uncaught exceptions.2013年9月29日日曜日
How to inject javascript in android webview like chrome javascript console
http://edisonthk.wordpress.com/2013/09/29/how-to-inject-javascript-in-android-webview-like-chrome-javascript-console/
2013年9月23日月曜日
Simple introduction about what is Ruby on Rails
I begin to learn ruby on rails since begin of this August. I found out that ruby on rails is awesome, it speed up all my works and make it simple to maintain. So, I wrote this article to introduce about how awesome rails is.
Back to our topic, what is ruby on rails? Web application development framework with ruby language. For more details, you can do some searching on what is ruby on rails, there are many sources you can found on internet.
Installation
It is always easier to be understood by running up the things.To install rails on your windows or mac PC. There is a quick way to install it by download rails installer and install it.
To install rails on linux os such as ubuntu, debian might needs a little bit more works then windows and mac. There are sources on internet, check it out.
To begin a new project
Before getting start to develop a new web application. You need to setup database, directory of your new project, .htaccess to control the traffic. Maybe you will spent almost half an hours to one hours to setup all those things. But …Rails, will do it automatically for you.
By typing a few commands for it, rails will do it for you. Here’s the commands.
rails new MyProject cd MyProject rails generate model Item name:string price:integer description:text rails generate controller items index new create show edit update destroy rake db:migrate rails server
On first command, create new project and name it "NewProject". Second command create table name item and columns of name, price and description. Third command create directory for html file, ruby file and routes. Fourth command to startup database and last command to startup the server.
Everything will be setup within 1 minutes. It means, you can begin your programming after 1 minutes. Cool right!
Go to http://localhost:3000 and you will see the welcome message of rails.
To check with the project generated, go to http://localhost:3000/items
The page is blank. This is because all you have generated is database, system and routes. There will nothing to show unless html code is written.
Scaffold
A powerful tool that prepared by rails called Scaffold. Scaffold will generate everything including database, simple system code, traffic, html layout code. It means, you can begin to coding from half way instead of blank file.How to use it? By a few simple command
First create a new project. In this case, named NewProject
rails new NewProject
Then, generate scaffold with following command and startup server.
rails generate scaffold item name:string price:integer description:text rake db:migrate rails server
Here’s the result generated by scaffold. Check it out
Instead of blank project, scaffold will generate a template for us to make a quick way to start.
End
It is the end of the article, do you think that ruby on rails is awesome?2013年9月14日土曜日
Event prevent default is not working
If you are working on key action with jquery and having problems on event.preventDefault is not working. Let’s me explain something simple to you.
event.preventDefault
As given example on docs, it shows us how it works on click action. For instances, prevent default action of anchor request the given url when clicked, action of submit button clicked to submit the form.So far so good.
bind.( “keydown” , function( event ){ return false; } );
preventDefault is good but when it comes to key action such as enter key on submit form and tab key on switching the focus of input element. It lose it effects. You will found out that enter key are still performing default action and others key as well.So… what is the solution? Adding return false on handler. Snippets below shows an simple example on this solution.
$(document).bind('keydown', function(e){
return false;
});
It’s works right!
What happens if you want only ‘enter’ key to be prevent default action. Here’s the solution.
$(document).bind('keydown', function(e){
var keyPressed = ('which' in e) ? e.which : e.keyCode;
if( keyPressed == 13){
return false;
}else{
return true;
}
});
Enter keycode is 13. Return true on event handler will allow the key to continue with default action and return false will stop event handler from continue to default action.
It’s still not working
There are a few quite common mistake make by people, especially for me. Either you too?
- Errors inside the handler function
If there is errors (exp. syntax errors) occured inside the handler function, default action will be carry out even though there is return false in handler function. Don’t tried to ignore the errors that shows on your browser, it might be the core of your problems.
- Mess up with JQuery instances and native Javascript instances
What does it means? Check it out with the differences at following codes.
$("ul").children("li")[0].html("");
$("ul").children("li")[0].innerHTML = "";
It is quite tricky problems, html() is jquery properties and innerHTML is javascript properties. But on this case, children(“li”) returns native javascript element array, so there is no method for html(“”) in returned element array. So, second code is the correct answer.
If you have do some checking by Object.keys( $(“ul”).children(“li”)[0] ); you will found out that the properties is different from jquery properties.
Conclusions
High level language doesn’t means you don’t have to understand the basic of it. Understanding basic sometimes will be the helper on solving problems.
Good luck
2013年9月6日金曜日
How to open select input method option menu programmatically on Android
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (mgr != null) {
mgr.showInputMethodPicker();
}
2013年8月29日木曜日
Install ruby on rails for Aptana Studio 3 on Windows
I spent almost half of my day to install ruby on rails on my Windows PC. After a long fighting on installing, I found an EASY way for windows. Could be said as DAMN EASY.
What you need to do is download the latest version from Rails installer site and run it. Don’t need to download Ruby Installer, as it is included inside Rails installer. What you need to do is waiting until it’s done.
After installed, you can test it by open command prompt and go to whatever testing directory and type
rails new TestApps cd TestApps rails server
Then, open browser and go to http://localhost:3000 .If you are able to see the page. Congratulation, you are done with ruby on rails install.
Last things is to download Aptana Studio 3.
Caution here, make sure you install rails first instead of Aptana studio. Otherwise, you have to configure the path for rails on Aptana studio.
If you received error "Unable to find 'rdebug-ide' binary script. May need to install 'ruby-debug-ide' gem, or may need to add your gem executable directory to your PATH", when debug ruby in Aptana studio.
Install ruby-debug-ide by following command
gem install ruby-debug-ide
Then, restart your Aptana studio. You should be able to debug ruby file.
Okay! Hope you are already in coding. Thank you for reading.
2013年8月21日水曜日
Crop Images into pieces for java applet
CropImageFilter(int x, int y, int w, int h)
First, load the image from folder. Here's is the method I prepared.
private Image loadImage(String img){
return getImage(app.getDocumentBase(),"img/"+img);
}
For eclipse IDE, I put my images file inside the src/img package.
After load the image, let's say "image_want_chop.png" is loaded and chop it with following code.
Image originalImage = loadImage("image_want_chop.png");
ImageFilter imageFilter = new CropImageFilter(x,y,width,height);
Image choppedImage = createImage(new FilteredImageSource(originalImage.getSource(),
imageFilter ));
Thank you for reading.
2013年8月20日火曜日
Split MySQL select data into multiple pages by using LIMIT
Our goal is to split the selected MySQL data into multiple pages and display current page and the data show on specify page.
Introduce to LIMIT clause
Let’s say the limit of data on single page is 10 rows, and current page is page 2. It means I need to show the data begin from 20th to 30th. So what I need to do is to set the offset value and length of data selected. $offset = 0;
$length_of_data = 10;
$query = "SELECT * FROM mytable LIMIT {$offset} ,{$length_of_data}";
The parameter of LIMIT clause is LIMIT offset, length
Optimize the query
To prevent sql injection, we need to modify the code above into bottom.
$length_of_data = 10;
$query = "SELECT * FROM mytable LIMIT :offset ,{$length_of_data}";
$page = intval(trim($_GET["page"]));
$offset = $page * $length_of_data;
try{
$stmt = $db->prepare($query);
$stmt->bindParam(':offset',$offset,PDO::PARAM_INT);
$stmt->execute();
}catch(PDOException $ex){
die ($ex);
}
Caution : According to stackoverflow, seem like there is a bug when using execute(array(“:offset”=>0)) or bindParam(“:offset”,trim($offset),PDO::PARAM_INT) without intval function. So it is better using what I given on above. I hope it works for your guys.
You can test it by add ?page=0 to your end of the url. It will show you the first 10 rows data without offset.
Display current page and all available pages
It is the last things we need to do. First get the total rows number from table. Then show the current page with special view and other pages with normal view.
$query = "SELECT * FROM mytable";
try{
$stmt = $db->prepare($query);
$stmt->execute();
}catch(PDOException $ex){
die ($ex);
}
$rows = $stmt->fetchAll();
$count = count($rows);
for($num = 0;$num < $count / $limit_row;$num++){
if($page == $num){
echo '<a href="forum_main.php?page'.$num.'"><span class="page_number current">'. ($num+1).'</span></a>';
}else{
echo '<a href="forum_main.php?page='.$num.'"><span class="page_number">'.($num+1).'</span></a>';
}
}
Here’s we done! Thank you for reading.
2013年7月6日土曜日
Simple Custom Dialog for Android
Android developers have provided us based on how to create a custom dialog by using alertdialog.builder method. If you are interesting with it, here’s the link. http://developer.android.com/guide/topics/ui/dialogs.html
I am going to shows another way instead of using alertdialog.builder. What is the benefit of this method is you can update the content of dialog view dynamically and directly.
If you are thinking changing the content of dialog when the button is pressed without closing dialog. You might give a try on this method.
First, create the layout for custom dialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/dialog_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is custom dialog"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/dialog_positive_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="positive"/>
<Button
android:id="@+id/dialog_negative_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="negative"/>
</LinearLayout>
</LinearLayout>
Then, create the custom dialog class
class SimpleCustomDialog extends AlertDialog{
TextView text;
SimpleCustomDialog(Context ctx){
super(ctx);
setTitle("Custom Dialog");
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.alertdialog_layout, null);
text = (TextView)view.findViewById(R.id.dialog_text);
text.setText("this is custom dialog");
Button positiveButton = (Button)view.findViewById(R.id.dialog_positive_button);
Button negativeButton = (Button)view.findViewById(R.id.dialog_negative_button);
positiveButton.setOnClickListener(new PositiveButtonListener());
negativeButton.setOnClickListener(new NegativeButtonListener());
setView(view);
}
class PositiveButtonListener implements View.OnClickListener{
@Override
public void onClick(View view) {
text.setText("Button clicked");
}
}
class NegativeButtonListener implements View.OnClickListener{
@Override
public void onClick(View view) {
// dialog wouldn't dismiss itself, you have to call dismiss method
//dismiss dialog
SimpleCustomDialog.this.dismiss();
}
}
}
finally call show method to show dialog
SimpleCustomDialog mDialog = new SimpleCustomDialog(this);
mDialog.show();
If you want to dismiss the dialog, just call dismiss method.
Hope this article helps you. Thank your for reading.
2013年6月16日日曜日
Installation Ubuntu into MK808B
http://edisonthk.wordpress.com/2013/06/16/installation-ubuntu-into-mk808b/
2013年6月10日月曜日
How to customize your code on blogger ( SyntaxHighlighter )
Introduction
I want to show everyone how to make your source code looks neat and tidy like the sample code below. /**
* SyntaxHighlighter
*/
function foo()
{
if (counter <= 10)
return;
// it works!
}
What your have to do is pretty simple. There are only 3 steps.
- Configure your blog by copy and paste the links I given into your template header
- Copy your source code you want to show on your blog and paste it on HTML
- Wrap your source code with <pre> tag
Well, if you are still don’t understand what we are going to do. Just follow my instruction.
1st step
As what I have said on above, copy the following links .
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeEclipse.css' rel='stylesheet' type='text/css'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/> <script language='javascript' type='text/javascript'> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); </script>
Where to paste? Template header ! First login into your blogger dashboard.
Then, click “template” on left-hand-side.
Then, click “Edit HTML”
Find the header close tag </head> and paste the code above the header.
Here’s we are done with configuration. Let’s do some simple test on it.
Second Step
Open new post. And switch your edit mode from compose to HTML.
Let’s say you have following source code.
/**
* SyntaxHighlighter
*/
function foo()
{
if (counter <= 10)
return;
// it works!
}
Paste the source code into your content. Remember, you must paste it in HTML mode but not Compose mode.
If there is any symbol like <> in your code, you must change them to < and > respectively.
It should looks like above.
Final Step
After you have paste your source code into content, we have to wrap your source code with <pre> tag.
Here’s we done! Save it and view it.
Link
The source code and library above is provided by SyntaxHighlighter. Check it out for more details.Thank you.
2013年5月1日水曜日
Networking and Socket programming Tutorial on C
I have migrate my blog to new site. Click link below to redirect.
http://edisonthk.wordpress.com/2013/04/30/networking-and-socket-programming-tutorial-on-c/







