Monday, January 26, 2015

AWS Bitnami Default Passwords

In the current version as at this posting, it is output into the server log and retrived via the "View System Log" feature in the AWS console.

Reference: https://bitnami.com/stack/wordpress/cloud/amazon

AWS HVM vs PV

HVM: Hardware Virtual Machine
PV: Paravirtual machine

HVM is newer (feature of new CPUs). Some of the newer instance types only support HVM.

References:



Saturday, January 24, 2015

Ant SCP Error com.jcraft.jsch.JSchException: reject HostKey

This happens when the target server is not a "known host". Just do a normal SSH to the server and say yes to adding the server to known hosts, and after that SCP from Ant should be fine.

http://anahorny.blogspot.sg/2013/05/solution-for-comjcraftjschjschexception.html

Wednesday, January 21, 2015

REST: When to Use GET, PUT, POST, DELETE in Non-CRUD Situations

In normal CRUD situations, the answer is obvious. In non-CRUD situations, this gets a bit more tricky.

I think the best way to approach this is based on the following quoted from REST Wikipedia page

"The PUT and DELETE methods are referred to as idempotent, meaning that the operation will produce the same result no matter how many times it is repeated. The GET method is a safe method (or nullipotent), meaning that calling it produces no side-effects. In other words, retrieving or accessing a record doesn't change it."
  • If the REST end-point has no side effect (e.g. search), use GET.
  • If it is idempotent, it is possible to use PUT or DELETE depending on the nature of the request
  • If not idempotent and has side effect, use POST

Saturday, January 3, 2015

SimpleDateFormat Strange Results / Thread Safety

SimpleDateFormat can give strange results when running on a server when multiple threads share the same instance. This is because it is not thread-safe due to intermediate results being stored in instance variables. To avoid this problem always instantiate a new SimpleDateFormat object when needed or find a way to ensure there is one instance per thread (e.g. using ThreadLocal).

References:

Thursday, December 11, 2014

C++ Necessary to Call Base Destructor?

The answer is no, it is automatically called, but it is also somehow important that the destructor is virtual if the class will be inherited.

Reference: http://stackoverflow.com/questions/677620/do-i-need-to-explicitly-call-the-base-virtual-destructor

Cocos2D-X: Convert String to Integer and Testing For Numeric Value

These can be done quite simply by converting the String to a Cocos2D-X String object and then calling the "intValue()" function on the String. If it is a numeric value, the function will return the value which you can use, or if it is not a numeric value, it will return 0 so it also serves for a test for numeric value, unless of course the value is "0" and you should test for that first.

int val;
String* str = String::create(“123”);
// test for 0
if(str->compare(“0”) == 0){
   val = 0;
}
else {
   val = str->intValue();
   if(val == 0){
       // String is not numeric, handle the error here
   }
   else{
       // String is numeric and its value is saved in the “val” variable
   }
}

Wednesday, December 10, 2014

Cocos2D-X: EventListenerTouchOneByOne no viable overloaded '='

In Cocos2D-X version 3.0 and newer, there is a new way of handling touches (see example code below).

However the first time I used this, I encountered a compile error with message "EventListenerTouchOneByOne no viable overloaded '='" in lines 4-6 below. When this compile error happens, one reason is because of a wrong return type on their callbacks.
   EventListenerTouchOneByOne* touchListener = EventListenerTouchOneByOne::create();
   touchListener->setSwallowTouches(true);
   touchListener->onTouchBegan = CC_CALLBACK_2(MyLayer::touchBegan,this);
   touchListener->onTouchEnded = CC_CALLBACK_2(MyLayer::touchEnded,this);
   touchListener->onTouchCancelled = CC_CALLBACK_2(MyLayer::touchCancelled,this);
   touchListener->onTouchMoved = CC_CALLBACK_2(MyLayer::touchMoved,this);

   _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

The "onTouchBegan" callback has return type "bool". The rest need to have return type "void". Otherwise you will get the compile error above (I had all of them with return type "bool").
bool MyLayer::touchBegan(Touch *touch, Event *event) {
return true;
}
void MyLayer::touchEnded(Touch *touch, Event *event) {
}
void MyLayer::touchCancelled(Touch *touch, Event *event) {
}
void MyLayer::touchMoved(Touch *touch, Event *event) {
}

Monday, December 8, 2014

Cocos2D-X Dynamic Label Height

Setting height to 0 seems to do the trick here.

Cocos2D-X Display Long Text

When displaying long text in Cocos2D-X, it doesn't seem possible to use a single Label when the text is quite long (e.g. 2000+ characters), as the Label goes completely blank instead of displaying text. Maybe it is because Cocos2D-X uses a texture for this and this somehow blew the texture size limit. To display long text in Cocos2D-X, use multiple labels e.g. one for each paragraph.

Note: to get the height of each label so as to know where to position the next one, call "getBoundingBox()" on the label.

Thursday, December 4, 2014

Cocos2D-X: Substring

It seems like the best way is to convert to a std::string first and use its substr function, so e.g. from a Cocos2D-X String object:
cocos2dxString->_string.substr(pos,len);

Note: for Cocos2D-X 3.0 and above

Reference: http://www.cplusplus.com/reference/string/string/substr/

Git Push Specific Branch

E.g. to push master branch only:
git push origin master


Reference: http://stackoverflow.com/questions/1947972/how-can-i-push-a-specific-branch-of-git-to-my-server

Wednesday, December 3, 2014

Cocos2D-X: Conversion Between String, std::string, and C String (i.e. char*)

"String" refers to the String class (previously CCString and analogous to the NSString in Objective-C). This is for Cocos2D-X 3.0 and above.

From C String to String, it's actually the standard constructor
String* cocos2dxString = String::create(“xxxxx”);

From String to C String
cocos2dxString->getCString();

From String to std::string
cocos2dxString->_string;

From std::string to String (this requires an indirect conversion it seems)
String::create(cocos2dxString->_string.c_str());

From std::string to C String
stdString.c_str();

Tuesday, December 2, 2014

Cocos2D-X Formatting Number to Two Decimal Places

Format with "%.2f" assuming the number is a floating point type.

Reference: http://stackoverflow.com/questions/4784336/two-decimal-places-using-printf

Cocos2D-X Wrapping Text

To do that, call the "setDimensions" function on the Label. The wrapping will be done automatically. Just ensure that there is sufficient height for the additional lines.

Gimp MacOS "Embedded Color Profile"

In summary, if you don't know otherwise, convert it.

Reference: http://docs.gimp.org/en/gimp-imaging-color-management.html

Error Unzipping File on MacOS: "Error 2 - No such file or directory"

Not sure why this happens but this means the ZIP file is corrupted.

To fix it:

zip -FF zipfile.zip --out repairedcopy.zip

Reference: http://apple.stackexchange.com/questions/135853/error-opening-a-zip-file-no-such-file-or-directory

Tuesday, November 18, 2014