Implementation of "Post count" of HashTag with Mysql stored proc

Recently, I am making a feature similar to Instagram HashTag search in my app, which is searching the hashtag with post count with the given keyword.

To do this, I try to keep the post count in the Tag record and get it when do the search. However, to complete this, I need to handle the way to increase the count when a new post is created.

To do so, I had chosen using stored proc to do this task.

What’s and Why stored procedure ? 

Combine several SQL in a named procedure. It can make the application code more simple.

Before using procedure:
We need to use two SQLs to handle
UPDATE table SET count = count + 1 WHERE tag = ‘myTag’
SELECT count FROM table WHERE tag = ‘myTag’

After using procedure:
Just simply use the following SQL
CALL increase_post_count(‘myTag’)

Stored procedure of “Increase Post count” 

Define the procedure 

CREATE PROCEDURE inc_post_count
   IN inputTag VARCHAR(100)
    UPDATE tbl_hashtag SET postCount = postCount + 1 WHERE tag = inputTag ;
    SELECT postCount FROM tbl_hashtag WHERE tag = inputTag ;
END //

Note: The above statement is working mysql client but not in phpMyAdmin

Using the procedure
CALL inc_post_count(‘MyTag’) 


TDDLib for cocos2d-x-3.0 go public

I am going to put my Unit Test Framework for cocos2d-x 3.0 to open source (github). If you are a lover of TDD or Unit Test, you may love it. 

Github: https://github.com/tklee1975/tddlib_cocos2dx3

Currently, I am writing some documents about how to setup the library in your project and how to add a new test. If you are interested and like this project, please let me know.  

Testing "testSprite"

Testing "testLabel"


Map API - Looking for Places around a location

If we are talking about location based application, first of all, we think of GPS or LBS! However LBS only can tell us the coordinate (latitude and longitude) of your current location. It cannot tell you the place that you are standing at.

Thus, we need to work with Map API to get things done.

Features of the Map API

  • Given a location (latitude, longitude) , and then tell you the places near that location;
  • Given a name or name prefix with the location, and then tell you the places that match;
In short, with the help of the Map API + LBS, we are able to tell the possible places to users where they are currently at. 

What's Place?

The most basic and natural form about an location is just the coordinate (latitude, longitude); Imagine that you are at an unknown sea, the only possible information is just the coordinate.
However, the most of the cases, users aren't the sailors, coordinate mean nothing to them. So need the detail about that location, such as the street name, building name, country, etc. 

Geocoding vs Place Search

In the Map APIs, there are kind of information can be retrieved by the coordinate. 
First is the geocoding information, which it is the formal addresses near that coordinates. The method of this process is called "Geocoding". 

coordinate: 38.889772, -77.042771addresses:
  • 1964 Independence Avenue Southwest, Washington, DC 20227, USA
  • Washington, DC 20245, USA

Second is that place information, which are the places such as  shops, route, hospital, etc. This kind of information include the name of the entity and the address of that.  

coordinate: 38.889772, -77.042771places:
  • Constitution Gardens (Constitution Gardens, Washington, DC 20024, USA)
  • West Potomac Park (Southwest Washington, Washington, DC, USA)

For my own application, I use Place Search instead of Geocode because it is more understood by the end users.

Available Map API

For my selection, the best are Google Map API or FourSquare API; And there are still many selections available;


Cocos2d-x 3.0 Setup (Include Git & Github support)

Recently, I am going to try the latest cocos2d-x 3.0 final version. Here is the note to use cocos2d-x 3.0 with the source control of Git & Github;

Steps to setup

1. Download and zip cocos2d-x 

Simply following the instruction at cocos2d-x official site ( http://www.cocos2d-x.org/download) to download.

2. Setup the directory structure 

The following is my structure related to the cocos2dx
  • /w/cocos2dx/engine - Place the cocos2d core at here. (The pack of the cocos2d-x project will be placed here)
  • /w/cocos2dx/project - The project directory, where is my code placed at.
  • /w/cocos2dx/script/ -  The script files simplify some task. (will discuss later)

3. Run the setup 

Just run the following commands

cd /w/cocos2dx/engine/./setup.py

It will change your .bash_profile to add some environment variable

Prepare the following information:  


4. Create a new project using script

Use the following command to make a new project :
cd /w/cocos2dx/engine/tools/bin/cocos_console/./cocos.py new -p ken.game -l cpp Example1 -d /w/cocos2dx/project/

5. (optional) Trim down the project size

Since every project made by the cocos.py will make a copy of the cocos2d engine inside the project. If you want to share the engine code among different projects, we can do steps below; However, if you are going to hack the engine code and don't affect other project, you shouldn't do that. One more point, this action will place the cocos2d engine source code outside the source control scope. (Pro: save space;  Con: change won't be logged)

Just do the following to keep the project smaller
mv ./cocos2d ../ln -s ../cocos2d ./cocos2d

6. Setup GIT 

Do the following step to setup GIT. 
  • Install Git. (suppose Xcode will help to install the git, but it doesn't happened. just go to http://git-scm.com/ to download it) 
  • Add the .gitignore to the project directorycd /w/cocos2dx/cp ./script/.gitignore project/Example1
  • Git initialisation
    run "git init" in your project directory
  • Add to SourceTree (SourceTree is a GUI version of Git. available at http://www.sourcetreeapp.com/)Select "Add Working copy" and the select the project directory (w/cocos2dx/project/Example1)
  • Commit the work at SourceTree

7. Sync with Github 

In the previous step, we just put the source code to the local repository; It will be more safe if we put the source on the remote location. Here, I select github. Besides github, there are many alternatives such as you setup your own git remote server or using bitbucket. 

There are the steps to setup repository in github.

  • Create a repository in www.github.com. (Assume that you are already registered) and copy-and-paste the git url.
  • Open SourceTree and select your project to add a remote location- Select the project.
    - Choose "Repository -> Repository Setting" in the menu.
    - Select the "Remotes" Tab.
    - Click the "Add" button; It will show the "Add Remote" Popup.
    -  Enter "origin" in "Remote Name" and the given github url in "Remote Path"
  • Pull the master branch to github (origin location)

8. Start coding and Enjoy it

Open the project in Xcode, build and Run it.