[Tools] Blog Code Highlight - a tool generating highlighted code with Pretty Print in Blogger

[Tool]
Blog Code Highlight
Version: 1.0.1 Beta

Introduction:
  When highlighting code in Blogger as following:
class MyClass
{
    private:
        int Counter;
        std::vector<int> mCountList;

    public:
        MyClass(void);
        
    public:
        void Show(void);
}

   The HTML code has to be generated manually in the post as follows:
<pre class="prettyprint lang-cpp">
class MyClass
{
    private:
        int Counter;
        std::vector&lt;int&gt; mCountList;

    public:
        MyClass(void);
        
    public:
        void Show(void);
}
</pre>

  It is easy to make a mistake with the wrong typing causes exception occurred and not convenient to modify if the code is in HTML or XML because of some symbols(<, >,  &) are the reserved characters in the markup languages. Those problems confused me while I tried to write the blog with code if I didn't use the highlighting code frequently. In order to solve this problem and improve the efficiency of writing blog, I developed this tool as follows to help me convert the code of languages Google Code-Prettify supported into HTML code. 

   In this post, I would like to introduce how to use this tool to get correct (so far) HTML code for the Blogger.

How to use:
  1. Goes to https://blog-code-highlight.appspot.com

  2. Type or paste the source code in the text area on the left-hand side.

  3. Choose the language type which supported by Google Code-Prettify listed as follows:
    list here.

  4. Choose the version of HTML if you want to generate the code in HTML5.

  5. Tick Show Line Number if you want to show line number in the code. In addition, the first line number can be specified.

  6. Copy the formatted code from the Outcome session and paste it into your blog.

[Click Here] goes to this tool.

[Reference]
  1. Google / code-prettify
  2. HTML Entities

PS. Sorry for the ads. I need to get some funds if the quota is running out.

[Ant]How to build a property file (Build.property)

How to name the property file:
   It is easy and simple to setup a property file for Ant build. Normally, the name of property file is build.properties, but it could be named as build.properties.dev or build.properties.test based on the same deployment environments to be run in different settings. The benefits of using suffix as .xxx are:
  1. The build file can be reused for different execution environment with different property setting, such as developing, testing or release.
  2. Only the name of property file needs to be changed in the build.xml file while the target or source changed. It could reduce the typing error and time cost.


How to setup the properties:
    Each property is illustrated by a name and a value connected by a equals sign (=) in a line.

    For example:

  src=c:\source file
  target.dir=d:\testing

    In this case, dot symbol (.) could be a part of the name. It could be used to classify the properties into a group.

How to comment in the property file:
    Hash character (#) is used as the symbol to make a line as a comment.

    For example:

  ######################
  # This is Header
  #####################

  #Set soruce folder
  src.dir=c:\source file

  #Set destination folder
  target.dir=d:\testing

[Reference]
  1. Ant - Property Files
  2. How do I use a build.properties file

[Apache] Configure Apache for PHP in Mac OS X 10.11.3 El Capitan

[Versions]
OS: Mac OS X 10.11.3
Apache: 2.4.16
PHP: 5.5.30

     In order to develop and test web pages on the local web server, I googled some blogs to figure out what I have to do. It took me a couple of hours to search and test which approach is workable. Finally, I found that Configure Apache for PHP in OS X 10.10 Yosemite / 10.11 El Capitan written by Donat shows me how to set web pages up under home folder of the current user and Configuring Apache Virtual Hosts on Mac OS X posted by McCreary indicates how to set a domain name pointing to localhost. In this post, I am going to demonstrate how to setup both approach in my Mac.

Before Setup:
What have to be done:
Check the version of Apache by the following command:
sudo apachectl -v

Check the version of PHP by the following command:
sudo apachectl -v

Setup:
    For the following demonstration, {username} represents the current username used to login operating system and {servername} represents the target hostname used to access the local website.
  1. Make sure there is a Sites folder in the home directory. If not, create it and ensure the permission is 644(dr-xr--r--). If it is not, use the following command to change it:
    sudo chmod 644 Sites

  2. Make sure /etc/apache2/users/{username}.conf is existed. If not, create it. In addition, update this file as follows:
    <Directory "/Users/{username}/Sites/">
        Options Indexes Multiviews FollowSymLinks
        Require all granted
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

  3. Add virtual host into /etc/apache2/extra/httpd-vhosts.conf as following:
  4. <VirtualHost *:80>
      ServerName {servername}
      DocumentRoot /Users/{username}/Sites
    </VirtualHost>
    

Configuration:
  1. Uncomment the following lines in /etc/apache2/httpd.conf:
    LoadModule deflate_module libexec/apache2/mod_deflate.so
    LoadModule userdir_module libexec/apache2/mod_userdir.so
    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    LoadModule php5_module libexec/apache2/libphp5.so
    Include /private/etc/apache2/extra/httpd-userdir.conf
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    

  2. Then add index.php to the DirectoryIndex
  3. <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>

  4. Uncomment the following line in /etc/apache2/extra/httpd-userdir.conf
  5. Include /private/etc/apache2/users/*.conf
    

  6. Restart Apache:
  7. sudo apachectl restart

  8. If there is any problem happened, run the following command to see the error messages:
  9. sudo apachectl configtest

Test:
     So far, the web server has been established and the pages can be accessed by the following URL:
http://localhost/~{username}

     If there is no web page in this folder, it will show the index of web pages. Put the HTML file or the PHP file to test it.

Mapping to the specific domain name:
       With regard to the URL shown above, it is not convenient for me to access every website with the long typing because I might have plenty of website on my local machine. In order to reduce the expenses of typing, I would rather use a shortened link to do it. The following steps show how to setup a specific domain name for the website.
  1. Open /etc/hosts as follows command:
    sudo vim /etc/hosts

  2. Append the server name and target IP at the end of this file. In this case, 127.0.0.1 can be set for multiple server names.
    
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
    ::1             localhost
    
    127.0.0.1       {servername}
    

  3. Clear the local DNS cache by the following command:
    dscacheutil -flushcache

  4. Restart Apache.
  5. sudo apachectl restart
Test:
Just type:
http://{servername}



[Reference]
  1. Configure Apache for PHP in OS X 10.10 Yosemite / 10.11 Capitan
  2. Configuring Apache Virtual Hosts on Mac OS X
  3. Setting up a local web server on OS X

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...