tag:blogger.com,1999:blog-32030670843967142202024-02-06T22:35:43.121-08:00Kencoder TavernKeep your heart with all diligence, For out of it spring the issues of life. (HolyBible Proverb 4:23)
<br>
因為一 生的果效是由心發出 (聖經箴言 4:23)testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.comBlogger49125tag:blogger.com,1999:blog-3203067084396714220.post-59936103456905195112015-02-25T08:57:00.001-08:002015-02-25T08:57:30.057-08:00cocos2d-x: Adding Unit Test Framework "SimpleTDD"<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Introduction: </b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">SimpleTDD is a simple unit test framework that help you to develop tests to examine the behaviour of your codes;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Storyboard about SimpleTDD</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6-FE3X0lWmfr8omGnJPM64JmXgXMHZEpcbAzGj77rNs6PA974MKLGvThgLhNmNYJmlHaY7nzrlp5LERBmW-866Ngmm-vnx40qDHNLZVZ7BFMcYnclNMdN-2bA3FKMPpVlEfQXMR6UPkk/s1600/SimpleTDD+demo+flow.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6-FE3X0lWmfr8omGnJPM64JmXgXMHZEpcbAzGj77rNs6PA974MKLGvThgLhNmNYJmlHaY7nzrlp5LERBmW-866Ngmm-vnx40qDHNLZVZ7BFMcYnclNMdN-2bA3FKMPpVlEfQXMR6UPkk/s1600/SimpleTDD+demo+flow.png" height="225" width="400" /></a><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Setup Overview</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><b></b></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">This is the steps to install SimpleTDD in your project:</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">1. Download SimpleTDD </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">2. Run the setup script </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">3. Set Macro for Debug version</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">4. Add Test Button</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">5. Create Unit Tests</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">Required software for SimpleTDD is just python, which should be installed when Xcode is installing;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Download SimpleTDD</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">Simplify clone the SimpleTDD project from the Github</span><br />
<span style="-webkit-text-stroke-color: rgb(4, 46, 238); color: #042eee; font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><a href="https://github.com/tklee1975/SimpleTDD-cocos2dx"><u>https://github.com/tklee1975/SimpleTDD-cocos2dx</u><span style="font-kerning: none;"><u></u></span></a></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br /><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Run the setup script</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">Setup script is python script that help you to copy Library classes and script to your project;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">After setup script is run, add the files to your project build; </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">For XCode (iOS): </span><br />
<br />
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">File -> Add Files to "your project"</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Select "UnitTest" and "SimpleTDD" folders</span></li>
</ul>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">For Android: Add them in the Android.mk </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><b>Set Macro for Debug version</b></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">SimpleTDD need you to set Macro "ENABLE_TDD" to open the route to the Test Main Menu so that It won't affect the release build;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">For XCode(iOS):</span><br />
<br />
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Open "Build Setting"</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Search for "Macro"</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Modify "Preprocessor Macros" values </span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Add "ENABLE_TDD" </span></li>
</ul>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">For Android: Define "-DENABLE_TDD" at "LOCAL_CPPFLAGS" in Android.mk</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><b>Add Test Button</b></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">To enter the Test Main, you need add a button at your main scene;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">This are the codes:</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">// At the header </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">#include "TDDHelper.h" </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">// Inside the Scene or Layer setup method</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">TDDHelper::addTestButton(this, Vec2(100, 80));</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><b>Create Unit Tests</b></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">These are the steps to create unit tests that help you to test individual code; You are going to do these steps many many times; It will be fine because it is not hard to do;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Create the TestSuite Class</b></u></span><br />
<br />
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Run the createTest.sh to create the TestSuite Class</span></li>
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">run "./script/createTest.sh Example1" </span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">It will generate source code "Example1Test.h" & "Example1Test.cpp" in Classes/UnitTest Folder</span></li>
</ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Add Test Class to project </span></li>
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">For Xcode, use Add files to project</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">For Android, include these files in Android.mk</span></li>
</ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Edit "MyTDDCase.h"</span></li>
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">MyTDDCase.h is the header file to control which Unit Test will be shown in the Test Menu</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">First, include the new Test Class using "#include Example1Test.h"</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Second, add "TEST(Example1Test)" in the TDD_CASES block</span></li>
</ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">When it is done, the test suite "Example1" will be shown</span></li>
</ul>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>Create a test in the TestSuite Class</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><b></b></span><br />
<br />
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">By default, there is test method called "subTest" in the TestSuite class; it will simply print something to the console;</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">To add a new test (e.g: testSpriteRotate), just follow the way "subTest" do;</span></li>
<ul>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Define the method in .h & .cpp; example: void Example1Test::testSpriteRotate(Ref *sender);</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Add the method in "setSubTest" method: example: SUBTEST(Example1Test::testSpriteRotate)</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Do the unit test code inside testSpriteRotate method</span></li>
<li style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-size: 13px; font-stretch: normal; margin: 0px;"><span style="font-kerning: none;">Test & Run!!!</span></li>
</ul>
</ul>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><u><b>SimpleTDD Demo</b></u></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;">A simple demo of SimpleTDD is located at github:</span><br />
<span style="-webkit-text-stroke-color: rgb(4, 46, 238); color: #042eee; font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><a href="https://github.com/tklee1975/SimpleTDD-ccx3-demo"><u>https://github.com/tklee1975/SimpleTDD-ccx3-demo</u><span style="font-kerning: none;"><u></u></span></a></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"></span>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-76165113420203106592014-11-03T18:02:00.002-08:002014-11-03T18:03:25.217-08:00Four "C" of the Clean Code <span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Recently I am reading the book "<a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean code</a>" again. I have found there are 4 characteristics of the clean code. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The 4 characters of the clean code should have: </span><br />
<ul>
<li><span style="-webkit-text-stroke-color: rgb(0, 0, 0);"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Controllable</span></span></li>
<li><span style="-webkit-text-stroke-color: rgb(0, 0, 0);"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Comprehensible</span></span></li>
<li><span style="-webkit-text-stroke-color: rgb(0, 0, 0);"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Convenient</span></span></li>
<li><span style="-webkit-text-stroke-color: rgb(0, 0, 0);"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Consistent </span></span></li>
</ul>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"></span><br />
</span><br />
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><u><b>Controllable</b></u></span></span></h4>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">If there only just one concept to be remembered, it should be this one. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">If the program can be controlled by you, the author of the code or other who involved, this program will be a good program. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">For a controllable program, which is the program can be easily understood, changed, adding new features, and easy to debug. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">The more code involved, the more uncontrollable. It will become the "</span><span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;"><b><a href="http://en.wikipedia.org/wiki/Gordian_Knot">Gordian Knot</a>" </b>.</span><br />
<span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;"></span><br />
</span><br />
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><u><b>Comprehensible:</b></u></span></span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">Every program we write have two group of audiences; </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">First is the machine, compiler, syntax checker, …., they will transfer our programs to executable;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">Second is us, human being; The program should be readable so that we could understand and work on it. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">There are many chances that our programs will be read by someone else or yourself later. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">Therefore it is important to make the code comprehensible. </span><br />
<span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;"></span><br />
</span><br />
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><u><b>Convenient:</b></u></span></span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">While making a large program, we may involve a lots of code. Therefore, we need to arrange the code so that it helps to do thing fast. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">Here some examples:</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">- Find the libraries and functions available in the project and how to use it</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">- Quickly navigate to the class or method we want to go. </span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">- Easy to remember the classes involved</span><br />
<span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;"></span><br />
<span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;">To do so, we need to adopt a good naming contention and code style.</span><br />
<span style="-webkit-text-stroke-color: rgb(37, 37, 37); color: #252525; font-kerning: none; font-stretch: normal;"></span><br />
</span><br />
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><b><u>Consistent</u></b></span></span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">As we know, many words in English can refer to a similar meaning; One frequent met example in coding: number of X, count of X, size of X; In order to prevent our code audience getting confused or mislead, we need to make sure the same word have the same meaning;</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;">If you use "count" as the suffix telling how many, keep to use it over your class. </span>
</span><br />
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-kerning: none; font-stretch: normal;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<span style="-webkit-text-stroke-color: rgb(0, 0, 0); font-family: Arial; font-kerning: none; font-size: 13px; font-stretch: normal;"><br /></span>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-34586412081311189602014-09-11T12:18:00.003-07:002014-09-11T12:18:59.619-07:00TDDccx3 1.1.0 - New Submenu UI developed. The submenu of TDDccx3 is modified:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFa_W4ZWKWwJa65X3KYUjgYreHzRY3yxK5sLS04pndnMDC6r9DB-073cTHNahX6o0OcGnIrFAxqZHkoRqplS79hyphenhyphenns1l9j5L5n4CWW8o_68JB24yppjqQ183aOjK5Dervwl-vpozVvf_Q/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.03+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFa_W4ZWKWwJa65X3KYUjgYreHzRY3yxK5sLS04pndnMDC6r9DB-073cTHNahX6o0OcGnIrFAxqZHkoRqplS79hyphenhyphenns1l9j5L5n4CWW8o_68JB24yppjqQ183aOjK5Dervwl-vpozVvf_Q/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.03+am.png" height="180" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibUwor4FPgi14LsoYv8w41KHynFszch6abYJTBgmj1QSPCHyimbsRen_hU7aUdg9LmawkZnHCX4A1GdWTljnO-T8n6art_va-gi49E8v0KGbuU1MxQCoIAd2f9qeaQy61f0FLtPIWT1ZI/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.20+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibUwor4FPgi14LsoYv8w41KHynFszch6abYJTBgmj1QSPCHyimbsRen_hU7aUdg9LmawkZnHCX4A1GdWTljnO-T8n6art_va-gi49E8v0KGbuU1MxQCoIAd2f9qeaQy61f0FLtPIWT1ZI/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.20+am.png" height="180" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxuTUWHzqgFAMVeAWPX4pdtWxKMllIlapg8U4C_Y-pQF8F4HyXVrUC2-xQ6JNwfdIRlP2faxzbpIsh-c8bkNy2T0brFUopMe9NCD6PPFkFdfNjjz2T_6bzK2yYV591ZcKWPjSIBOUVWuI/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.27+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxuTUWHzqgFAMVeAWPX4pdtWxKMllIlapg8U4C_Y-pQF8F4HyXVrUC2-xQ6JNwfdIRlP2faxzbpIsh-c8bkNy2T0brFUopMe9NCD6PPFkFdfNjjz2T_6bzK2yYV591ZcKWPjSIBOUVWuI/s1600/iOS+Simulator+Screen+shot+12+Sep,+2014+3.09.27+am.png" height="180" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div>
In the new design, we want to decrease the interference of the test components;</div>
<div>
So the following changes are made</div>
<div>
- Top toolbar is removed </div>
<div>
- Provide a Hide/Show button to hide/show the menu items</div>
<div>
- Menu can be moved to wherever you want</div>
<div>
- Toggle Stat is placed in the menu items;</div>
<div>
<br /></div>
<div>
The change is just made and not yet well test. It will be polished and tested soon. </div>
<div>
<br /></div>
<div>
Available at:</div>
<div>
<a href="https://github.com/tklee1975/tddlib_cocos2dx3">https://github.com/tklee1975/tddlib_cocos2dx3</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-24321936908116136882014-09-02T09:18:00.000-07:002014-09-02T09:18:16.091-07:00A day in my coding life.Here is a short sharing of my daily coding life.<br />
<br />
While arrived to office, prepare the basic first, breakfast, water and tea;<br />
<br />
Then first thing first, I starts with a simple prayer and listening to biblical messages.<br />
<br />
And then I read some industrial news from Twitter, Google Plus, Techcrunch, ... to get updated;<br />
<br />
Next I prepare:<br />
- Spotify (provide music for my concentration)<br />
- Tomato.es (For Pomodoro Technique, one of time management skill)<br />
- Trello (For task management)<br />
- Evernote (for note taking and daily planning)<br />
<br />
And then Tomato Clock starts, several 25 minutes session begin:<br />
<br />
Every 25 minutes, I will focus on my different coding works:<br />
<br />
<ul>
<li>Planning : Fail to plan, plan to fail. Always keep works being planned.</li>
<li>Program Design : Design is the origin, without a design, it will be very hard to code. </li>
<li>Write and Run Code </li>
<li>Refactor and Documentation : It help to re-organise what I have done</li>
<li>Sharing to other coders</li>
<li>Learn something new </li>
<li>Testing : More test, more bugs unveiled and quality UP. </li>
</ul>
<br />
<br />
While my team members are all there, we start the daily SCRUM to update the progress of each others.<br />
<br />
A day of coding if full of fun and challenges !!!<br />
<br />
Wish you enjoy your work and coding as well.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-74231503264967623882014-08-06T19:21:00.000-07:002014-08-06T19:21:41.946-07:00SDK & Open Source used in my iOS project (2014)In my recent iOS project, we have used a lots of open source code and SDK like many app do;<br />
<br />
Here is the list of them:<br />
<br />
<br />
<ul>
<li><span style="font-family: Arial; font-size: 13px;"><b>Crashlytics</b>: </span><span style="font-family: Arial; font-size: 13px;">Crash Logging</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>Google Analytics:</b> User Analytics: </span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>Parse</b>: Push Notification Helper</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>EGORefreshTableHeaderView</b>: PullToRefresh</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>SDWebImage</b>: ImageView using URL</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>UIImage+ImageEffects:</b> Making Blur Effect</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>UIImage+animatedGIF</b>: Playing animated GIF in UIImageView</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>GCPlaceholderTextView</b>: placeholder show in TextView</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>URBMediaFocusViewController</b>: Enlarge the thumbnail image</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>YDSlider</b>: Slider for audio player</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>JSONKit</b>: JSON Helper</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>ASIHTTPLibrary</b>: Asynchronous HTTP Request</span></li>
<li><span style="font-family: Arial; font-size: 13px;"><b>TTAttributedLabel</b>: Make UILabel having clickable link</span></li>
</ul>
<br />
<br />
Thanks for the developers of the above project! These save us a lot of time.<br />
<br />testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-67328053745352468522014-07-13T18:23:00.000-07:002014-07-13T18:24:05.058-07:00TDDLib (cocos2d-x 3) updated: Improved UIMy TDD Testing framework for cocos2d-x 3.0 is updated.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWuV-HyXzyLYZY4xmLfsz9nmWZpHlaRzWPIRhBXOzPtFnPuo899G_TYRhqpfqpTRVaaP_Nq2gu1kVT-7bv_5QzxsFj6RnIfKNfheIW8c-p5r-catLh9_rPa3J2Qoz-Fp_DG_9deAhBgzY/s1600/iOS+Simulator+Screen+shot+14+Jul,+2014+9.17.19+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWuV-HyXzyLYZY4xmLfsz9nmWZpHlaRzWPIRhBXOzPtFnPuo899G_TYRhqpfqpTRVaaP_Nq2gu1kVT-7bv_5QzxsFj6RnIfKNfheIW8c-p5r-catLh9_rPa3J2Qoz-Fp_DG_9deAhBgzY/s1600/iOS+Simulator+Screen+shot+14+Jul,+2014+9.17.19+am.png" height="180" width="320" /></a></div>
<br />
<br />
Changes:<br />
- Modified UI<br />
- Filter test without the need to touch the "Find" button<br />
- Add Background colour setting (help to check coloured elements)<br />
<br />
Source: <a href="https://github.com/tklee1975/tddlib_cocos2dx3">https://github.com/tklee1975/tddlib_cocos2dx3</a>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-13267964659086985722014-07-11T09:51:00.000-07:002014-07-11T09:51:02.945-07:00Fixing undesired outline of Label in cocos2d-x 3.0Recently, when I work on my TDDLib project, I found that the Label of cocos2d-x 3.0 show the Label with an undesired outline which isn't I want to (The first label shown below).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghoZhxusuomkDWH1Hpg4lKJICVA3_HaPc_bvE-1j4ooMoXmhi0iEunvIY7stx2ETS7_hQ3u8h5AJw4siXRxUq_Pa90CyV00e-hzf0jTGlpOuQ2x3NVSFQAeNwmFk0ZQzWB_S5ZWjbMB_8/s1600/iOS+Simulator+Screen+shot+12+Jul,+2014+12.43.33+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghoZhxusuomkDWH1Hpg4lKJICVA3_HaPc_bvE-1j4ooMoXmhi0iEunvIY7stx2ETS7_hQ3u8h5AJw4siXRxUq_Pa90CyV00e-hzf0jTGlpOuQ2x3NVSFQAeNwmFk0ZQzWB_S5ZWjbMB_8/s1600/iOS+Simulator+Screen+shot+12+Jul,+2014+12.43.33+am.png" height="225" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
After several google search, I found the solution to fix it (The second label shown above).</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
It's simple, just call the blend of the Label to BlendFunc<span class="s1">::</span>ALPHA_PREMULTIPLIED.</div>
<div class="separator" style="clear: both; text-align: left;">
Code: <span class="s1">label-></span>setBlendFunc<span class="s1">(</span>BlendFunc<span class="s1">::</span>ALPHA_PREMULTIPLIED</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Source example:</div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s1">std</span>::<span class="s1">string</span> sysFont = <span class="s2">"GillSans"</span>;</span></div>
<div class="p2">
<span class="s1" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="p2">
<span class="s1" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">std</span><span class="s3" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">::</span><span class="s1" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">string</span><span class="s3" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> test1 = </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">"No BlendFunc"</span><span class="s3" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">;</span></div>
<div class="p3">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s3"><span class="Apple-tab-span"> </span></span><span class="s1">std</span><span class="s3">::</span><span class="s1">string</span><span class="s3"> test2 = </span>"ALPHA_PREMULTIPLIED"<span class="s3">;</span></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s4"><br /></span></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span><span class="s4">Label</span> *label;</span></div>
<div class="p4">
<span class="Apple-tab-span"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span><span class="s4">Color3B</span> textColor = <span class="s4">Color3B</span>(<span class="s5">200</span>, <span class="s5">245</span>, <span class="s5">245</span>);</span></div>
<div class="p4">
<span class="Apple-tab-span"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span></div>
<div class="p5">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="p5">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">// First Label (Undesired outline)</span></div>
<div class="p5">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">label = </span><span class="s4" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">Label</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">::</span><span class="s4" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">createWithSystemFont</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">(test1, sysFont, </span><span class="s5" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">40</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">);</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span>label-><span class="s4">setColor</span>(textColor);</span></div>
<div class="p6">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s3"><span class="Apple-tab-span"> </span>label-></span>setPosition<span class="s3">(</span>Point<span class="s3">(</span><span class="s5">250</span><span class="s3">, </span><span class="s5">300</span><span class="s3">));</span></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span><span class="s4">addChild</span>(label);</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">// Second Label (Fixed outline)</span></div>
<div class="p4">
<span class="Apple-tab-span"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span>label = <span class="s4">Label</span>::<span class="s4">createWithSystemFont</span>(test2, sysFont, <span class="s5">40</span>);</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span>label-><span class="s4">setColor</span>(textColor);</span></div>
<div class="p6">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s3"><span class="Apple-tab-span"> </span>label-></span>setPosition<span class="s3">(</span>Point<span class="s3">(</span><span class="s5">250</span><span class="s3">, </span><span class="s5">200</span><span class="s3">));</span></span></div>
<div class="p6">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s3"><span class="Apple-tab-span"> </span>label-></span>setBlendFunc<span class="s3">(</span>BlendFunc<span class="s3">::</span>ALPHA_PREMULTIPLIED<span class="s3">);</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="p4">
<span class="Apple-tab-span"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span></div>
<br />
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span"> </span><span class="s4">addChild</span>(label);</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span class="s1"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span class="s1"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span class="s1"><br /></span></div>
<br />
<br />
<br />testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-32051335554455983722014-07-09T19:25:00.003-07:002014-07-09T19:25:43.169-07:00Using AutoResize in iOS App DevelopmentWhen programming the UI of an application, we are inevitable to program an UI with dynamic width and height;<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioSHyMIWJAbZ0j3727X0TDTGr3S2AG7T8i372lT8wpVM6qtXluIK-RnD3AMz9v86d8SFTDMdOzyhQ7HMalAbl3rCGo1xC0WGsuQLxzUfx7SAJrmRiDggyAs7jC8w0bT80eUUTosaHCQc0/s1600/Screen+Shot+2014-07-10+at+10.24.25+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioSHyMIWJAbZ0j3727X0TDTGr3S2AG7T8i372lT8wpVM6qtXluIK-RnD3AMz9v86d8SFTDMdOzyhQ7HMalAbl3rCGo1xC0WGsuQLxzUfx7SAJrmRiDggyAs7jC8w0bT80eUUTosaHCQc0/s1600/Screen+Shot+2014-07-10+at+10.24.25+am.png" height="228" width="320" /></a></div>
<br />
<br />
<br />
Real Example:<br />
A view contain a footer and content with different text length, some cause 1 lines, so cause 2 lines;<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpe0gbnodblA0hdZOhWv9lSC6eLFDNpEYqt3YuhdxmYY0TtzW-p90sXdTJfewOjwlyMJWDQu172Ph9GYvjLY34keXnb2Df2ZQqAfWglq5AM6-5NXo3yd_JaWkcgIGzcxEJ1ef3ehyphenhyphenuG4g/s1600/Screen+Shot+2014-07-10+at+10.06.22+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpe0gbnodblA0hdZOhWv9lSC6eLFDNpEYqt3YuhdxmYY0TtzW-p90sXdTJfewOjwlyMJWDQu172Ph9GYvjLY34keXnb2Df2ZQqAfWglq5AM6-5NXo3yd_JaWkcgIGzcxEJ1ef3ehyphenhyphenuG4g/s1600/Screen+Shot+2014-07-10+at+10.06.22+am.png" height="192" width="320" /></a></div>
<br />
<br />
<h4>
Dynamic Layout in iOS</h4>
<br />
There are several ways to handle this kind dynamic layout in iOS programming, one of my favourite is using "Auto Resize Mask", it help to adjust the size of the subview and help the subviews sticking to the four borders;<br />
<br />
<br />
<h4>
Autoresizing mask constants</h4>
<br />
Mask related to the auto size<br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleHeight" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleHeight</a><br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleWidth" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleWidth</a><br />
<br />
Mask related to auto positioning<br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleLeftMargin" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleLeftMargin</a><br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleRightMargin" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleRightMargin</a><br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleBottomMargin" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleBottomMargin</a><br />
- <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewAutoresizingFlexibleTopMargin" style="background-color: white; color: #3366cc; font-family: Courier, Consolas, monospace; font-size: 13px; text-decoration: none;" target="_self">UIViewAutoresizingFlexibleTopMargin</a><br />
<br />
Also see: <a href="https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/Art/uiview_autoresize.jpg">Diagram about the mask</a><br />
<br />
Note: We don't need type those mask value, usually we work with the interface builder<br />
<br />
<h4>
Tips of using AutoResize</h4>
<br />
<ol>
<li>Use with Interface Builder, you can preview the appearance on how it works.</li>
<li>Uncheck the "AutoLayout" of your XIB in interface builder.</li>
<li>Don't modify the size and position on views which are well "autosized", just modify the superview size.</li>
</ol>
<div>
<br /></div>
<h4>
Deal with Autoresize bugs</h4>
<div>
<ul>
<li>Find out which layout component are resize as you expect and double check the autoresize setting.</li>
<li>Check the adjusted size in the <b>layoutSubview</b> method.</li>
<li>Can use NSStringFromCGRect to convert the view.frame to String which is easy to print out.</li>
</ul>
</div>
<div>
<br /></div>
<br />
<br />
<h4>
Reference</h4>
* <a href="https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW15">Adjusting the Size and Position of Views at Runtime (Apple Doc)</a><br />
<div>
<br /></div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-24143948620462943752014-05-28T09:39:00.000-07:002014-05-28T09:39:07.152-07:00Implementation of "Post count" of HashTag with Mysql stored proc<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">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.<br /><br />
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.<br />
<br />
To do so, I had chosen using stored proc to do this task.<br />
<br />
</span><br />
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">What’s and Why stored procedure ? </span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Combine several SQL in a named procedure. It can make the application code more simple.<br />
<br />
</span><span style="font-weight: normal;"><u><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Before using procedure:</span></u></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We need to use two SQLs to handle</span><blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">UPDATE table SET count = count + 1 WHERE tag = ‘myTag’<br />SELECT count FROM table WHERE tag = ‘myTag’</span></blockquote>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br />
</span><span style="font-weight: normal;"><u><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">After using procedure:</span></u></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Just simply use the following SQL</span><blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">CALL increase_post_count(‘myTag’)</span></blockquote>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br />
</span><h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">Stored procedure of “Increase Post count” </span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><u><u><br /></u>
Define the procedure </u><br />
</span><blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">DELIMITER //<br />CREATE PROCEDURE inc_post_count<br />(<br /> IN inputTag VARCHAR(100)<br />)<br />BEGIN<br /> UPDATE tbl_hashtag SET postCount = postCount + 1 WHERE tag = inputTag ;<br /> SELECT postCount FROM tbl_hashtag WHERE tag = inputTag ;<br />END //<br />DELIMITER ;</span></blockquote>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br />
Note: The above statement is working mysql client but not in phpMyAdmin<br />
<br /><u>Using the procedure</u><br />
</span><blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">CALL inc_post_count(‘MyTag’) </span></blockquote>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-82068932079522439702014-05-22T09:21:00.000-07:002014-05-22T19:02:09.738-07:00TDDLib for cocos2d-x-3.0 go public<span style="font-family: Trebuchet MS, sans-serif;">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. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Github: <a href="https://github.com/tklee1975/tddlib_cocos2dx3">https://github.com/tklee1975/tddlib_cocos2dx3</a></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">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. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF4NBzb0xskrHn-jHOw5VblAtX2nXBjds8J6sMkqjC-pLXqssWpZEuIwvByf0uEY8_OvGc5IcM64jKiYvVVbBOO6k6lWsVgtnPq9pJXgi2IN1fKHR2TAiIL8ML7kdXPumdR9UsGjjbpoM/s1600/iOS+Simulator+Screen+shot+23+May,+2014+12.14.04+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Trebuchet MS, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF4NBzb0xskrHn-jHOw5VblAtX2nXBjds8J6sMkqjC-pLXqssWpZEuIwvByf0uEY8_OvGc5IcM64jKiYvVVbBOO6k6lWsVgtnPq9pJXgi2IN1fKHR2TAiIL8ML7kdXPumdR9UsGjjbpoM/s1600/iOS+Simulator+Screen+shot+23+May,+2014+12.14.04+am.png" height="180" width="320" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">Testing "testSprite"</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR5YW-i08XodJNpedtQ016uc5w4BBTGsEUkqw3Bq9Sm4sWedPedB3dN0-c09FWbzv4PRDqojbLNVyid9zZIYKJn28-7p34DDjscvVt6hCAJZdjS9WWRQJuB1Uk9yAvx7SG8HdS5asi8-Y/s1600/iOS+Simulator+Screen+shot+23+May,+2014+12.14.15+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Trebuchet MS, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR5YW-i08XodJNpedtQ016uc5w4BBTGsEUkqw3Bq9Sm4sWedPedB3dN0-c09FWbzv4PRDqojbLNVyid9zZIYKJn28-7p34DDjscvVt6hCAJZdjS9WWRQJuB1Uk9yAvx7SG8HdS5asi8-Y/s1600/iOS+Simulator+Screen+shot+23+May,+2014+12.14.15+am.png" height="180" width="320" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">Testing "testLabel"</span></div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-9939108518427013192014-05-18T09:34:00.002-07:002014-05-18T17:20:43.288-07:00Map API - Looking for Places around a locationIf 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.<br />
<br />
Thus, we need to work with Map API to get things done.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoW2Lz4ghPRuIFucysosPIKKXt94EnAywwesx3jFlNpVd3y0xDIjmq_r7D383xJHlmc7B58KiJjJ78uNYmkORgasqx4SU0IsDLLUepyqoFgmi9Gb4YkU_o6Dul1W96r6X7Envn95NvICg/s1600/map.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoW2Lz4ghPRuIFucysosPIKKXt94EnAywwesx3jFlNpVd3y0xDIjmq_r7D383xJHlmc7B58KiJjJ78uNYmkORgasqx4SU0IsDLLUepyqoFgmi9Gb4YkU_o6Dul1W96r6X7Envn95NvICg/s1600/map.png" height="320" width="320" /></a></div>
<br />
<h3>
Features of the Map API</h3>
<br />
<ul>
<li>Given a location (latitude, longitude) , and then tell you the places near that location;</li>
<li>Given a name or name prefix with the location, and then tell you the places that match;</li>
</ul>
<div>
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. </div>
<div>
<br /></div>
<h3>
What's Place?</h3>
<div>
<br /></div>
<div>
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.</div>
<div>
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. </div>
<div>
<br /></div>
<h3>
Geocoding vs Place Search</h3>
<div>
<br /></div>
<div>
In the Map APIs, there are kind of information can be retrieved by the coordinate. </div>
<div>
First is the geocoding information, which it is the formal addresses near that coordinates. The method of this process is called "Geocoding". </div>
<div>
<br /></div>
<div>
Example:<br />
<blockquote class="tr_bq">
<span style="color: #45818e;"><span style="font-family: Arial, Helvetica, sans-serif;">coordinate: 38.889772, -77.042771</span><span style="font-family: Arial, Helvetica, sans-serif;">addresses:</span></span><br />
<ul>
<li><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">1964 Independence Avenue Southwest, Washington, DC 20227, USA</span></li>
</ul>
<ul>
<li><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Washington, DC 20245, USA</span></li>
</ul>
</blockquote>
</div>
<div>
</div>
<div>
<br /></div>
<div>
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. </div>
<div>
<br /></div>
<div>
Example:</div>
<blockquote class="tr_bq">
<span style="color: #45818e;"><span style="font-family: Arial, Helvetica, sans-serif;">coordinate: 38.889772, -77.042771</span><span style="font-family: Arial, Helvetica, sans-serif;">places:</span></span><br />
<ul>
<li><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Constitution Gardens (Constitution Gardens, Washington, DC 20024, USA)</span></li>
</ul>
<ul>
<li><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">West Potomac Park (Southwest Washington, Washington, DC, USA)</span></li>
</ul>
</blockquote>
<div>
<div>
<div>
<br /></div>
</div>
</div>
<div>
For my own application, I use Place Search instead of Geocode because it is more understood by the end users.</div>
<div>
<br /></div>
<h3>
Available Map API</h3>
<div>
<br /></div>
<div>
For my selection, the best are Google Map API or FourSquare API; And there are still many selections available;</div>
<div>
<br /></div>
<div>
<ul>
<li><a href="https://developers.google.com/maps/documentation/geocoding/">Google Geocoding API</a></li>
<li><a href="https://developers.google.com/places/">Google Place API</a></li>
<li><a href="https://developer.foursquare.com/">Foursquare</a></li>
<li><a href="http://wiki.openstreetmap.org/wiki/Nominatim">OpenStreetMap</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/ff701702.aspx">BING Map API</a></li>
</ul>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-16095006359614470002014-05-11T08:40:00.000-07:002014-05-11T08:51:08.079-07:00Cocos2d-x 3.0 Setup (Include Git & Github support)<span style="font-family: Trebuchet MS, sans-serif;">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;</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbLTVPJp8S4HiCzeJEYmnbdiero5WLkXFjUqZkhaXgqDjByNvolBKQ4AkpTC9OPGs_KDEjcNhNqxt6wIEOnlw_VGUqd1K_oGOIzEjF4mDEL9l_wlo1lJjcUj6VAmssZksKtwXTzOoqt60/s1600/Screen+Shot+2014-05-11+at+11.50.12+pm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbLTVPJp8S4HiCzeJEYmnbdiero5WLkXFjUqZkhaXgqDjByNvolBKQ4AkpTC9OPGs_KDEjcNhNqxt6wIEOnlw_VGUqd1K_oGOIzEjF4mDEL9l_wlo1lJjcUj6VAmssZksKtwXTzOoqt60/s1600/Screen+Shot+2014-05-11+at+11.50.12+pm.png" height="170" width="320" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<br />
<h3>
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;"><u>Steps to setup</u></span></h3>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">1. Download and zip cocos2d-x </span></h4>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Simply following the instruction at cocos2d-x official site ( <span style="color: #042eee;"><u>http://www.cocos2d-x.org/download</u></span>) to download.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div>
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">2. Setup the directory structure </span></h4>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">The following is my structure related to the cocos2dx</span><br />
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">/w/cocos2dx/engine - Place the cocos2d core at here. (The pack of the cocos2d-x project will be placed here)</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><span style="font-family: Trebuchet MS, sans-serif;">/w/cocos2dx/project - The project directory, where is my code placed at.</span></span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><span style="font-family: Trebuchet MS, sans-serif;">/w/cocos2dx/script/ - The script files simplify some task. (will discuss later)</span></span></li>
</ul>
<span style="font-family: Trebuchet MS, sans-serif;">
</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">
<br />
</span><br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">3. Run the setup </span></h4>
<span style="font-family: Trebuchet MS, sans-serif;"><br />
Just run the following commands</span><br />
<blockquote class="tr_bq">
<span style="font-family: Trebuchet MS, sans-serif;">cd /w/cocos2dx/engine/./setup.py</span></blockquote>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">
<br />
It will change your .bash_profile to add some environment variable<br /><br />Prepare the following information: </span><br />
<ul><span style="font-family: Trebuchet MS, sans-serif;">
<li>ANDROID_SDK_ROOT</li>
<li>ANT_ROOT</li>
</span></ul>
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">4. Create a new project using script</span></h4>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Use the following command to make a new project :
</span><br />
<blockquote class="tr_bq">
<span style="font-family: Trebuchet MS, sans-serif;">cd /w/cocos2dx/engine/tools/bin/cocos_console/</span><span style="font-family: Trebuchet MS, sans-serif;">./cocos.py new -p ken.game -l cpp Example1 -d /w/cocos2dx/project/</span></blockquote>
<span style="font-family: Trebuchet MS, sans-serif;"><br />
</span><br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">5. (optional) Trim down the project size</span></h4>
<span style="font-family: Trebuchet MS, sans-serif;">
</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">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 </span><span style="font-family: 'Trebuchet MS', sans-serif;">projects, we can do steps below; </span><span style="font-family: 'Trebuchet MS', sans-serif;">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)</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">Just do the following to keep the project smaller</span></div>
<div>
<blockquote class="tr_bq">
<span style="font-family: Trebuchet MS, sans-serif;">mv ./cocos2d ../</span><span style="font-family: Trebuchet MS, sans-serif;">ln -s ../cocos2d ./cocos2d</span></blockquote>
<span style="font-family: Trebuchet MS, sans-serif;">
</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br />
</span><br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">6. Setup GIT </span></h4>
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-family: Trebuchet MS, sans-serif;">Do the following step to setup GIT. </span></span></div>
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<div>
<ul><span style="font-family: Trebuchet MS, sans-serif;">
<li><span style="font-family: Trebuchet MS, sans-serif;">Install Git. (suppose Xcode will help to install the git, but it doesn't happened. just go to </span><a href="http://git-scm.com/">http://git-scm.com/</a> to download it) </li>
<li>Add the .gitignore to the project directorycd /w/cocos2dx/cp ./script/.gitignore project/Example1</li>
<li>Git initialisation<br />run "git init" in your project directory</li>
<li>Add to SourceTree (SourceTree is a GUI version of Git. available at <a href="http://www.sourcetreeapp.com/">http://www.sourcetreeapp.com/</a>)Select "Add Working copy" and the select the project directory (w/cocos2dx/project/Example1)</li>
<li>Commit the work at SourceTree</li>
</span></ul>
</div>
<span style="font-family: Trebuchet MS, sans-serif;">
<br />
</span><br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">7. Sync with Github </span></h4>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">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. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br />
There are the steps to setup repository in github.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-family: Trebuchet MS, sans-serif;"> </span></span></div>
<span style="font-family: Trebuchet MS, sans-serif;">
</span>
<ul><span style="font-family: Trebuchet MS, sans-serif;">
<li>Create a repository in www.github.com. (Assume that you are already registered) and copy-and-paste the git url.</li>
<li>Open SourceTree and select your project to add a remote location- Select the project.<br />- Choose "Repository -> Repository Setting" in the menu.<br />- Select the "Remotes" Tab.<br />- Click the "Add" button; It will show the "Add Remote" Popup.<br />- Enter "origin" in "Remote Name" and the given github url in "Remote Path"</li>
<li>Pull the master branch to github (origin location)</li>
</span></ul>
<span style="font-family: Trebuchet MS, sans-serif;">
</span><br />
<h4>
<span style="font-family: Trebuchet MS, sans-serif;">8. Start coding and Enjoy it</span></h4>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">Open the project in Xcode, build and Run it. </span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<a name='more'></a><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<h4>
</h4>
<h3>
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;"><u>Tools involved:</u></span></h3>
<span style="font-family: Trebuchet MS, sans-serif;"></span><br />
<ul><span style="font-family: Trebuchet MS, sans-serif;">
<li>Cocos2d-x : the core engine to play with.</li>
<li>Python - the script interpreter to run cocos.py</li>
<li>Git - The tool used for source control </li>
<li>SourceTree - the GUI of git, simplify the way to handle git </li>
<li>Github - The free repository available in the internet so that can keep a copy in the cloud</li>
</span></ul>
<span style="font-family: Trebuchet MS, sans-serif;">
<span style="font-weight: normal;"></span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-weight: normal;"></span><br /></span>
<br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-size: 13px;"><br /></span></span></div>
</div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-18348760285194675302014-04-24T09:53:00.001-07:002014-04-24T09:58:11.643-07:00Making python module with C++ using boost.python (mac)<br />
<h3>
<span style="font-family: Arial; font-size: 13px;"><b>1. Install Python </b></span></h3>
<span style="font-family: Arial; font-size: 13px;">For most of the case, the python is already installed.</span><br />
<span style="font-family: Arial; font-size: 13px;">The paths of my mac are as followings:</span><br />
<ul>
<li><span style="font-family: Arial; font-size: 13px;">bin: </span><span style="font-size: 12.727272033691406px;"><span style="font-family: Courier New, Courier, monospace;">/usr/bin/python2.7</span></span></li>
<li><span style="font-family: Arial; font-size: 13px;">include: </span><span style="font-size: 12.727272033691406px;"><span style="font-family: Arial;"> </span><span style="font-family: Courier New, Courier, monospace;">/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7</span></span></li>
<li><span style="font-family: Arial; font-size: 13px;">library: </span><span style="font-size: 12.727272033691406px;"><span style="font-family: Courier New, Courier, monospace;">/usr/lib/python2.7</span></span></li>
<li><span style="font-family: Arial; font-size: 13px;">archive library: </span><span style="font-size: 12.727272033691406px;"><span style="font-family: Courier New, Courier, monospace;">/usr/lib/python2.7/lib/libpython.a</span></span></li>
</ul>
<span style="font-family: Arial; font-size: 13px;"></span><br />
<h3>
<span style="font-family: Arial; font-size: 13px;"><b>2. Install boost</b></span></h3>
<span style="font-family: Arial; font-size: 13px;">Download boost at </span><span style="color: #042eee; font-family: Arial; font-size: 13px;"><u>http://www.boost.org/users/download/</u></span><br />
<span style="font-family: Arial; font-size: 13px;">Build the library: </span><br />
<span style="font-size: 13px;"><span style="font-family: Courier New, Courier, monospace;">./bootstrap.sh</span></span><br />
<span style="font-family: Arial; font-size: 13px;">and </span><br />
<span style="font-size: 13px;"><span style="font-family: Courier New, Courier, monospace;">./b2 install</span></span><br />
<span style="font-family: Arial; font-size: 13px;"></span><br />
<span style="font-family: Arial; font-size: 13px;">When success, can find the include and library in the following path:</span><br />
<span style="font-family: Arial; font-size: 13px;">include path: </span><span style="font-size: 13px;"><span style="font-family: Courier New, Courier, monospace;">/usr/local/boost/boost/</span></span><br />
<span style="font-family: Arial; font-size: 13px;">library path: </span><span style="font-size: 13px;"><span style="font-family: Courier New, Courier, monospace;">/usr/local/boost/stage/lib</span></span><br />
<span style="font-family: Arial; font-size: 13px;"></span><br />
<span style="font-family: Arial; font-size: 13px;">3. Create the hello world program</span><br />
<span style="font-family: Arial; font-size: 13px;">Find out the detail in boost.python doc; it is clear.</span><br />
<span style="color: #042eee; font-family: Arial; font-size: 13px;"><u>http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/index.html</u></span><br />
<span style="font-family: Arial; font-size: 13px;"></span><br />
<h3>
<span style="font-family: Arial; font-size: 13px;">4. Build the program to share library</span></h3>
<span style="font-family: Arial; font-size: 13px;"></span><br />
<span style="font-family: Arial; font-size: 13px;">Create a make script as follows:</span><br />
<span style="font-family: Arial; font-size: 13px;">--------------------------------------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px;">#!/bin/sh</span><br />
<span style="font-size: 13px;"></span><br />
<span style="font-size: 13px;">BOOST_ROOT=/usr/local/boost</span><br />
<span style="font-size: 13px;">PYTHON_ROOT=/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7</span><br />
<span style="font-size: 13px;"></span><br />
<span style="font-size: 13px;">LD_LIBRARY_PATH=/usr/local/boost/stage/lib</span><br />
<span style="font-size: 13px;">PYTHON_LIBRARY_PATH=/usr/lib/python2.7/lib</span><br />
<span style="font-size: 13px;"></span><br />
<span style="font-size: 13px;">echo $PYTHON_ROOT</span><br />
<span style="font-size: 13px;"></span><br />
<span style="font-size: 13px;">g++ -c hello.cpp -I $PYTHON_ROOT -I $BOOST_ROOT</span><br />
<span style="font-size: 13px;">g++ -shared -o </span><span style="color: #042eee; font-size: 13px;"><u>hello.so</u></span><span style="font-size: 13px;"> hello.o -lboost_python -lpython \</span><br />
<span style="font-size: 13px;"> -L $LD_LIBRARY_PATH \</span><br />
<span style="font-size: 13px;"> -L $PYTHON_LIBRARY_PATH</span></span><br />
<span style="font-family: Arial; font-size: 13px;">--------------------------------------------------------------------------------------------------------------</span><br />
<span style="font-family: Arial; font-size: 13px;">and run it.</span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Note:</span></span><br />
<ul>
<li><span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">to compile successfully</span><span style="font-size: 12.727272033691406px;">, need to define the correct python and boost include path</span></span></li>
<li><span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">to link successfully, need to define the boost.python and python library location</span></span></li>
</ul>
<br />
<span style="font-family: Arial; font-size: 13px;"></span><br />
<br />
<h3>
<span style="font-family: Arial; font-size: 13px;">5. Play the module in python</span></h3>
<span style="font-family: Arial; font-size: 13px;">First, need configure the environment so that python know boost.python</span><br />
<span style="font-size: 13px;"><span style="font-family: Courier New, Courier, monospace;">DYLD_LIBRARY_PATH=$BOOST_ROOT/stage/lib</span></span><br />
<span style="font-family: Arial; font-size: 13px;"></span><br />
<span style="font-family: Arial; font-size: 13px;">Then run ‘python’ and type </span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px;">import hello</span><br />
<span style="font-size: 13px;">print hello_ext.greet()</span></span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">If the DYLD_LIBRARY_PATH not define, may receive the following error message:</span><br /><span style="font-family: Courier New, Courier, monospace;">Library not loaded: libboost_python.dylib</span></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-86339459181444309272014-04-15T08:40:00.004-07:002014-04-15T08:40:57.502-07:00Make your Mysql friendly to Emoji characterIn my last projects, Mysql is usually UTF-8 as the core encoding. However, it is not good for my current project now because we will play with Emoji Character;<br />
<br />
Emoji Character is using an extended utf-8 Encoding, called UTF-8 mb4 (utf8mb4).<br />
<br />
If inserting string with Emoji Character, the mysql will alert "incorrect string" and make the SQL fail.<br />
To fix this, we need to:<br />
<br />
<ul>
<li>Change the database and table to utf8mb4 encoding </li>
<li>Change the connection encoding to utf8mb4 as well</li>
</ul>
<div>
<br /></div>
<div>
External Reference:<br /><ul>
<li><u style="color: #042eee; font-family: Arial; font-size: 13px;">http://mathiasbynens.be/notes/mysql-utf8mb4</u></li>
<li><u style="color: #042eee; font-family: Arial; font-size: 13px;">http://info.michael-simons.eu/2013/01/21/java-mysql-and-multi-byte-utf-8-support/</u></li>
<li><u style="color: #042eee; font-family: Arial; font-size: 13px;">http://my.oschina.net/wingyiu/blog/153357</u></li>
</ul>
</div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-77228949156976597072014-03-17T18:59:00.000-07:002014-06-09T20:19:28.177-07:00Calculate the distance between two geo locationsWe are developing a location based app and we encounter a problem about the geo location yesterday. Which is "how to get the distance between two points in the map". It seem to be easy if using our usual XY coordination system (the Cartesian coordinate). However, the inputs are the latitude and longitude, not the unit of meter;<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA-XW9_R0ZRu2w0z0Ki7z_YCfLFinJrtI8o75Wgv-r3DSe7bXoa1eF-yq-ZXJmKP_YkaFdhSKkVACxaGmWMY6OEDBcZoJZWEiajYdAAMrslBNekv4a77g12pPtUGES0NSMQjTgC4JYzU0/s1600/distance-between-two.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA-XW9_R0ZRu2w0z0Ki7z_YCfLFinJrtI8o75Wgv-r3DSe7bXoa1eF-yq-ZXJmKP_YkaFdhSKkVACxaGmWMY6OEDBcZoJZWEiajYdAAMrslBNekv4a77g12pPtUGES0NSMQjTgC4JYzU0/s1600/distance-between-two.png" height="400" width="362" /></a></div>
<br />
<br />
<u><b>Formula:</b></u><br />
<br />
<span style="background-color: white; color: #351c75; font-family: Arial, Helvetica, sans-serif;">acos( </span><br />
<span style="background-color: white; color: #351c75; font-family: Arial, Helvetica, sans-serif;"> cos(a.lat) x cos(a.long) x cos(b.lat) x cos(b.long) </span><br />
<span style="background-color: white; color: #351c75; font-family: Arial, Helvetica, sans-serif;"> + cos(a.lat) x sin(a.long) x cos(b.lat) x sin(b.long)</span><br />
<span style="background-color: white; color: #351c75; font-family: Arial, Helvetica, sans-serif;"> + sin(a.lat)*sin(b.lat)</span><br />
<span style="background-color: white; color: #351c75; font-family: Arial, Helvetica, sans-serif;">) x earth.radius</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Where:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">a.lat, a.long = latitude and longitude of the 1st point ( in radians)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">b.lat, b.long = latitude and longitude of the 2nd point ( in radians)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">earth.radius = the radius of the earth; (which is: 3443.9 nautical miles or </span><span style="font-family: Arial, Helvetica, sans-serif;">6378 km)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<b><u><span style="font-family: inherit;">Source Code (in java):</span></u></b><br />
<br />
<br />
<pre><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">public static double distanceBetween(double lat1, double long1, double lat2, double long2)
{
double rLat1 = Math.toRadians(lat1);
double rLong1 = Math.toRadians(long1);
double rLat2 = Math.toRadians(lat2);
double rLong2 = Math.toRadians(long2);
double part1 = Math.cos(rLat1) * Math.cos(rLong1) * Math.cos(rLat2) * Math.cos(rLong2);
double part2 = Math.cos(rLat1) * Math.sin(rLong1) * Math.cos(rLat2) * Math.sin(rLong2);
double part3 = Math.sin(rLat1) * Math.sin(rLat2);
return Math.acos(part1 + part2 + part3) * RADIUS;
}</span>
</pre>
<br />
<u><b>Reference: </b></u><br />
<br />
There are more documentation talking about the distance calculation, also google provide API to do so.<br />
<ul>
<li><a href="http://jan.ucc.nau.edu/~cvm/latlon_formula.html">http://jan.ucc.nau.edu/~cvm/latlon_formula.html</a></li>
<li><a href="http://www.movable-type.co.uk/scripts/latlong.html">http://www.movable-type.co.uk/scripts/latlong.html</a></li>
<li><a href="https://developers.google.com/maps/documentation/distancematrix/">https://developers.google.com/maps/documentation/distancematrix/</a></li>
</ul>
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-29331841726170477462014-03-16T19:05:00.000-07:002014-03-16T19:06:28.128-07:00Abnormal java.net.UnknownHostException on resinRecently, I encountered a problem while I am calling to Google API in my java code running on Resin. The problem is that: The http call raise an UnknownHostException;<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUTVacBBwcodBlXSfM79iFQNWx3yaNLofMtv44MU19P8xRI8CkwLTLFGSy5o6MPYdzHS61QzOstOPSq8GM2A_9XWsZTL6_zuQdkOtxs3JSWqFQhnqw_rrW2a23LDjKqlv3d4Pxrlj0vio/s1600/Screen+Shot+2014-03-17+at+9.53.51+am.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUTVacBBwcodBlXSfM79iFQNWx3yaNLofMtv44MU19P8xRI8CkwLTLFGSy5o6MPYdzHS61QzOstOPSq8GM2A_9XWsZTL6_zuQdkOtxs3JSWqFQhnqw_rrW2a23LDjKqlv3d4Pxrlj0vio/s1600/Screen+Shot+2014-03-17+at+9.53.51+am.png" height="98" width="400" /></a></div>
<br />
<br />
It doesn't caused by Java itself because the UnitTest show it is correct.<br />
It doesn't caused by Resin because it work in my development platform.<br />
<br />
So what go wrong? Finally, I has discovered it is wrong in the staging server environment;<br />
The /etc/hosts isn't configured as the resin want to. (... maybe it is the problem of resin too ..)<br />
<br />
To fix it:<br />
- type "hostname" to find your hostname . e.g "my.pc"<br />
- edit /etc/hosts and add the line "127.0.0.1 my.pc"<br />
- restart the server to make it effective<br />
<br />
Notes:<br />
- This problem may not be happened in all environment. My macbook doesn't have the problem.<br />
<br />
Related Links:<br />
<br />
<ul>
<li><a href="http://ajia.github.io/blog/2013/03/11/yu-dao-resin-com-dot-caucho-dot-config-dot-configruntimeexception-java-dot-net-dot-unknownhostexception/">http://ajia.github.io/blog/2013/03/11/yu-dao-resin-com-dot-caucho-dot-config-dot-configruntimeexception-java-dot-net-dot-unknownhostexception/</a></li>
<li><a href="http://forum.caucho.com/showthread.php?p=35348">http://forum.caucho.com/showthread.php?p=35348</a></li>
</ul>
<br />
<br />
<br />
<br />
<br />testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-67141704268249177562014-03-13T07:34:00.001-07:002014-03-16T19:07:02.728-07:00Make java connection pool auto reconnectRecently we encountered a problem when using java db connection pool. The problem is that the connection is being closed by the DB server since it is already timeout. To due with this, need to configure two more parameters.<br />
<br />
They are:<br />
- <span style="font-family: Arial; font-size: 13px;">testOnBorrow</span><span style="font-family: Arial; font-size: 13px;"> ; define it as "true"</span><br />
<span style="font-family: Arial; font-size: 13px;">- </span><span style="font-family: Arial; font-size: 13px;">validationQuery</span><span style="font-family: Arial; font-size: 13px;"> ; define it as "SELECT 1 FROM dual" if you are also using MySQL</span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;">Yes, It is easy to config it. But how to test it? (Many sites may not give the answer). </span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;">To verify the configuration is work, we can make a simple Unit Test;</span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;"><b><u>Step 1: Make a failure case</u></b></span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Make an unit test base on the following code;</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial; font-size: 13px;">Properties p = new Properties(); </span>
<br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">prop.put("driver", "org.gjt.mm.mysql.Driver"</span></span><span style="font-family: Arial; font-size: 12.727272033691406px;">);</span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">prop.put("url", "jdbc://localhost:3306/db");</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">prop.put("username", "user");</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">prop.put("password", "123456");</span></span><br />
<span style="font-family: Arial; font-size: 13px;">p.setProperties("testOnBorrow", "false");</span><br />
<span style="font-family: Arial; font-size: 12.727272033691406px;">p.setProperties("</span><span style="font-family: Arial; font-size: 12.727272033691406px;">validationQuery</span><span style="font-family: Arial; font-size: 12.727272033691406px;">", "");</span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;">BasicDataSource ds = BasicDataSourceFactory.createDataSource(prop);</span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">ds.setMaxActive(1);</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">ds.setMaxIdle(1);</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">ds.setMinIdle(0);</span></span><br />
<br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Connection conn = ds.getConnection();</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">System.out.println("First connection");</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">System.out.println("Sleep start");</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Thread.sleep(10000);</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">System.out.println("Sleep end");</span></span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Connection conn = ds.getConnection();</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">System.out.println("Second connection");</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">To make the connection fail at the second time, try to kill the connection in DB side while "Thread.sleep";</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<br />
<b style="font-family: Arial; font-size: 12.727272033691406px;"><u>Step 2: Fix the failure </u></b><br />
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 12.727272033691406px;">Simply change "</span></span><span style="font-family: Arial; font-size: 13px;">testOnBorrow=false" and "validationQuery=" to </span><br />
<span style="font-family: Arial; font-size: 13px;"> "testOnBorrow=true" and "validationQuery=SELECT 1 FROM dual"</span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;">Then, run the test again. we will see "Second connection" show up instead of Exception message.</span><br />
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;"><br /></span>
<span style="font-family: Arial; font-size: 13px;"><br /></span>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-86815024315866079932014-01-27T17:12:00.001-08:002014-01-27T17:12:54.081-08:00Cocos2d-x Error: "Skipping selector 'onPopupYesPressed' since no CCBSelectorResolver is present."Today, I failed to bind a button and the log said "<b>Skipping selector 'onPopupYesPressed' since no CCBSelectorResolver is present."</b>;<br />
<br />
The reason is that simply because I forget to define the "Custom Class" name in CocosBuilder !! =.=<br />
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-66852020794758952582014-01-23T07:43:00.003-08:002014-01-23T07:43:55.549-08:00制作游戏的难点<br />
<span style="font-family: Arial, Helvetica, sans-serif;">最近和友人談談各自製作遊戲的情況,發現真有點難; </span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難一:難在找到志同道合及能力互補的團隊! </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難二:難在找出好的賣點! </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難三:難在製作出好的體驗! </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難四:難在把抽象的事情具體化!</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難五:難在把設計實現出來! </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">難六:難在放下主觀想法,拿起玩家的</span><span style="font-family: Arial, Helvetica, sans-serif;">想法</span><span style="font-family: Arial, Helvetica, sans-serif;">!</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">游戏开发是梦幻的工业,这是事实,但是令一个事情,就做出好的游戏,是困难重重的,需要热情和能力兼备; </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">真正製作的遊戲開發者,就是在不斷克服困難,</span><span style="font-family: Arial, Helvetica, sans-serif;">不斷</span><span style="font-family: Arial, Helvetica, sans-serif;">改进的勇者們!</span>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-85815307630050398612014-01-20T06:32:00.000-08:002014-01-20T06:32:01.254-08:00以恩典為年歲的冠冕@2013 剛過了的2013, 神給我和我家很多的恩典:<br />
<br />
<ul>
<li>醫治母親的大病 </li>
<li>幫助天藍媽媽能有力量照顧天藍 </li>
<li>天藍健康快樂地成長 </li>
<li>我們更明白神的話和祂的恩典 </li>
<li>為我們預備了裝修的費用和母親的醫藥費 </li>
<li>轉了新工作,可以多些時間照顧天藍和太太 </li>
<li>賜予我們聰明智慧,處理家事和公事</li>
<li>爸媽租到一間又大又好的屋</li>
<li>我們可以搬去大一點的屋</li>
</ul>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-40691525624593791042014-01-09T07:03:00.004-08:002014-01-09T07:03:44.802-08:00Different points of view on different devices using Cocos2d-x<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_c4bNKUr_3qvdj0WVb6Iz068j-gBYJuQBGireIIV4EqDACtMv3HoTXS_9CbcP6gqEemloaSEqzUSP3QUFcsLktwpN2qCQ034oC1NZSy7O7yBw0-SOTUL8sftZ6OF1UOz_XojO6RQJS1s/s1600/Screen+Shot+2014-01-09+at+5.22.01+pm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_c4bNKUr_3qvdj0WVb6Iz068j-gBYJuQBGireIIV4EqDACtMv3HoTXS_9CbcP6gqEemloaSEqzUSP3QUFcsLktwpN2qCQ034oC1NZSy7O7yBw0-SOTUL8sftZ6OF1UOz_XojO6RQJS1s/s1600/Screen+Shot+2014-01-09+at+5.22.01+pm.png" height="314" width="320" /></a></div>
<br />testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-34434196449449129222013-12-20T18:42:00.003-08:002013-12-20T18:43:30.465-08:00Asset sharing with Dropbox<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyQvTT8EY2MilBBhzMBP4mgAvMaXlzqtYKgFujok28hESGjSNOAH35h7h7uMbt0JnkizTpdCIXGPcXonNFTFdmFfc-b-HcUuo6Q7OXxsQfuClQhnLtuI1zGN-25XFXRJuORI9dNsZFWFg/s1600/share-between-team.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyQvTT8EY2MilBBhzMBP4mgAvMaXlzqtYKgFujok28hESGjSNOAH35h7h7uMbt0JnkizTpdCIXGPcXonNFTFdmFfc-b-HcUuo6Q7OXxsQfuClQhnLtuI1zGN-25XFXRJuORI9dNsZFWFg/s400/share-between-team.png" width="400" /></a></div>
<br />
Our team is going to use Dropbox to share the game assets;testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-56018032653515766732013-12-17T00:06:00.001-08:002013-12-17T00:06:28.036-08:00Fixing "cocos-ext.h" not found issue<div class="p1">
When using the Cocos2d-extension (e.g ScrollView, Button) on my project, </div>
<div class="p1">
<br /></div>
<div class="p1">
I found that it is okay to compile in Xcode but not in Android; </div>
<div class="p1">
It said cannot found "cocos-ext.h"</div>
<div class="p1">
<br /></div>
<div class="p1">
The case is easy because Android.mk in the extension folder is configured wrong;</div>
<div class="p1">
<br /></div>
<div class="p1">
File location: cocos2d-x/extension/Android.mk</div>
<div class="p1">
<br /></div>
<div class="p1">
Orignal setting: </div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH) \</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH)/GUI/CCControlExtension \</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH)/GUI/CCScrollView</span></div>
<div class="p1">
<br /></div>
<div class="p1">
Correct one should: $(LOCAL_PATH) is added</div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH) \</span></div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH)/GUI/CCControlExtension \</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $(LOCAL_PATH)/GUI/CCScrollView</span></div>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-71563920623331560152013-12-12T05:59:00.001-08:002014-05-11T17:34:54.967-07:00Setup Android Project on Cocos2d-x 3.0<h3>
Important things need to make cocos2d-x android project running</h3>
<h4>
1. Make sure the Android SDK (ADT) and NDK ready </h4>
<br />
<h4>
2. Configure the Android.mk </h4>
<br />
Need to config the following variables:<br />
<br />
<div class="p1">
</div>
<ul>
<li>LOCAL_SRC_FILES : Because we may have more sources than the "HelloWorld" project</li>
<li>LOCAL_C_INCLUDES: The related header files will be searched by the compiler</li>
<li>LOCAL_WHOLE_STATIC_LIBRARIES: Our project may not need the sdk given</li>
<li>$(call import-module, moduleName) : Need to match with the LOCAL_WHOLE_STATIC_LIBRARIES</li>
</ul>
<br />
<br />
<h4>
3. Configure the AndroidManifest correctly </h4>
Need to config these two variables:<br />
<br />
<ul>
<li><span class="s1"><</span><span class="s2">uses-sdk</span><span class="s3"> </span><span class="s4">android:minSdkVersion</span><span class="s3">=</span><span class="s5">"9"</span><span class="s1">/> : Need to "9" or above to use Native Activity</span></li>
<li><span class="s2"><</span><span class="s3">meta-data</span><span class="s1"> </span><span class="s4">android:name</span><span class="s1">=</span>"android.app.lib_name"<span class="s1"> </span><span class="s4">android:value</span><span class="s1">=</span>"App"<span class="s1"> </span><span class="s2">/> : it will link to your native library called "libApp.so"</span></li>
</ul>
<br />
<h4>
4. Copy the java source to proj.android</h4>
<h4>
5. Prepare Eclipse to import the android project</h4>
<br />
<h3>
Other Troubleshooting</h3>
<div>
<h4>
Unable to load native library: "xxx.so"</h4>
</div>
<div>
Problem: Fail to define the native library</div>
<div>
Solution: config the library name correctly in AndroidManifest.xml</div>
<div>
<br /></div>
<div>
For example: your library is libs/armeabi/libGame.so</div>
<div>
the value defined in AndroidManifest.xml should be like the following:</div>
<div>
<span class="s1"><</span><span class="s2">meta-data</span><span class="s3"> </span><span class="s4">android:name</span><span class="s3">=</span>"android.app.lib_name"<span class="s3"> </span><span class="s4">android:value</span><span class="s3">=</span>"Game"<span class="s3"> </span><span class="s1">/></span> </div>
<div>
Note: No need to define the path, extension, and 'lib' prefix;</div>
<h4>
LogCat said "dvmFindClassByName rejecting 'org/cocos2dx/lib/Cocos2dxHelper"</h4>
Problem: Missing the java source folder<br />
Solution: <a href="http://www.cocos2d-x.org/forums/6/topics/36265">http://www.cocos2d-x.org/forums/6/topics/36265</a>testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0tag:blogger.com,1999:blog-3203067084396714220.post-86561015124731374862013-11-21T17:49:00.004-08:002013-11-21T17:50:26.381-08:00List of Patches for Cocos2d iphone<span style="font-family: Arial, Helvetica, sans-serif;">Here are the solutions for the problem you may encounter when using Cocos2d-iphone with CocosBuilder Extension.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Cocos2d-iphone Version: 2.0.0</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">CCBReader: v3</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><u>1. CCScrollView not showing and handle touch correct if the parent position is not CGZero</u></b></span><br />
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://www.cocos2d-x.org/forums/6/topics/15600">http://www.cocos2d-x.org/forums/6/topics/15600</a></span></li>
</ul>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<b><u>2. CCLayerColor and CCLayerGradient cannot show color</u></b></span><br />
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://kencoder.blogspot.hk/2013/11/fixing-ccbreader-v3-with-cocos2d-iphone.html">http://kencoder.blogspot.hk/2013/11/fixing-ccbreader-v3-with-cocos2d-iphone.html</a></span></li>
</ul>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<b><u>3. <span style="background-color: white; color: #333333; line-height: 20px;">CCControl doesn't change to Disable Look when control.enable = NO</span></u></b></span><br />
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://kencoder.blogspot.hk/2013/11/fixing-ccbreader-v3-with-cocos2d-iphone.html">http://kencoder.blogspot.hk/2013/11/fixing-ccbreader-v3-with-cocos2d-iphone.html</a></span></li>
</ul>
testhttp://www.blogger.com/profile/13649206310162017472noreply@blogger.com0