Friday, March 30, 2012

Google IO 2012: here I come!

The Google IO conference registration becomes tougher and tougher each year.
As I mentioned before Google decided to do one registration for everybody this year, no preregistration.
I haven't seen the official report, but the "sold out" message on the web site appeared in under 30 minutes since the registration opened. 
Many of my friends were trying to get in with no luck. 
After about 10 mins of unsuccessful attempts to registrer I got to the screen with registration confirmation. Yep, I got lucky this time. 
I'M GOING TO GOOGLE IO, YEAAHHH !!!! :)
I'm very excited and looking forward to it :)

javascript web development

Just wanted to share a few useful libraries if you plan to do a pure javascript web development:

* jQuery http://jquery.com/ - who doesn't know it, right ?

* Backbone.js http://documentcloud.github.com/backbone/ - a useful and light MVC framework, that effortlessly works with JSON server-side APIs

* RequireJS http://requirejs.org/ - the framework that provides bunch of useful functionality, such as automatic namespacing for the modules, javascript minification, pluggins support etc. One of the useful plug-ins is I18N that provides a good support for localization.

* Dust  http://akdubya.github.com/dustjs/ - fast and light templating engine.

Enjoy!

MongoDB: copy collections


Recently I got involved in the node.js type of project, with MongoDB back-end. Last time I played with MongoDB was more than a year ago, so I'm pretty much refreshing my memory at this point.

Here is,  for example how to copy the data from one collection to another:

db.srcCollection.find().forEach( function(c){db.destCollection.insert(c)} )


Thursday, March 22, 2012

Android: Updated SDK Tools and ADT revision 17

Google released the new update for Android SDK tools and ADT 17. Lots of yummy goodies inside.

I'm particularly excited about the new x86 emulator image running in virtualization mode (means faster emulator), that what I actually needed to test some of my native libs on x86 architecture.

For more details go to this link:
http://android-developers.blogspot.com/2012/03/updated-sdk-tools-and-adt-revision-17.html

At the end just wanted to add: I'm very impressed how well Google executes on it's Android initiative.

Wednesday, March 21, 2012

MacPorts: p5.12-term-readkey compilation failed

Just got the p5.12-term-readkey compilation failed error when I tried to upgrade outdated ports.

Here is the link to the ticket for more details:
https://trac.macports.org/ticket/33675

The solution:

$ sudo port -n upgrade --force perl5.12
$ sudo port clean p5.12-term-readkey

After that just continue upgrading the ports.

Tuesday, March 20, 2012

Objective-C "abstract" base class

Once upon a time I needed to port some Java code from Android to Objective-C iOS.

Just wanted to share one useful tip on how to express the abstract class in Objective-C.

Basically in the "abstract" base class the "abstract" methods should be implemented like this, for example:


- (int) myAbstractMethod {
    [self doesNotRecognizeSelector:_cmd];    
    return 0;
}

Then the method should be implemented as needed in the concrete child class.

Monday, March 19, 2012

"How Much Would You Pay for the Universe?"

I just have to repost this inspiring video, because it feels exactly as Neil deGrasse Tyson said:
"Nobody’s dreaming about tomorrow anymore".

Thursday, March 15, 2012

Google IO 2012

By the way, the Google IO 2012 registration dates were announced a couple of days ago:
https://developers.google.com/events/io/register

I'm really looking forward to it. Hopefully I'll get the ticket (if I'm lucky enough).

I went to Google IO for two years before in 2010 and 2011.
The last year registration was crazy, thankfully I got my ticket with preregistration invite.

Google did many things right for the registration process this year: there will be no preregistration, everybody will get the change to try to register, they rised the ticket price and they do not allow the tickets transfers (which should hopefully reduce number of tickets being resold on eBay, etc.)

To me the Google IO experience is more than just attending the sessions,  after all you can watch the sessions in the comfort of your home for free. The free hardware is a plus, but it doesn't really matter, I would attend the conference without this as well.

To me Google IO experience is a good boost of creative energy that gets me charged at least for few months after the conference. I could say that it kind of brings the best of software engineer in me (true story, not a cliché).

See you at Google IO!

P.S. keeping my fingers crossed

Thursday, March 08, 2012

iOS device: EXC_BAD_ACCESS error with EXC_ARM_DA_ALIGN code

I spent a day hunting down one nasty bug in my code.
This code worked fine on Android ARM7 build, iPhone simulator (i386) build,
but started to crash once I run it on iPhone 4 device.

The code was implementing simple wrappers for the mutex, the event and the thread API.

For example the mutex handle looked something like this:

typedef struct _MUTEX_HANDLE {
    .........
    pthread_mutex_t mutex;
} MUTEX_HANDLE;

Then the event and thread structures where built upon this.

The problem only surfaced on iOS device, with error EXC_BAD_ACCESS and the code EXC_ARM_DA_ALIGN. I checked and double checked all the structures in memory their alignment etc., and still could not see anything wrong.  I searched online and got distracted with many articles reporting the similar type of problem and suggesting memcpy as a solution in order to "fix" this alignment issue.

The definitions of the pthread handles though was kind of curious:
struct _opaque_pthread_mutex_t { long __sig; char __opaque[__PTHREAD_MUTEX_SIZE__]; };
in addition to the signal handle there was an array.

Eventually I narrowed this down to the simple assignment by value where I just initialized 
pthread_mutex_t variable and assigned it by value to my structure member.

static int createMutex(MUTEX_HANDLE **pHandle) {
    pthread_mutex_t mtx;
    int err = initMutex(&mtx);
    if (!err) { 
        MUTEX_HANDLE *ph = malloc(sizeof(MUTEX_HANDLE));
        if (ph) {
           ph->mutex = mtx; //the problem is here, never do this!!! 

The pthread_mutex_t type is very simple structure on Android with one int member, so I kind of assumed that assigning pthread_mutex_t by value would not incur that much overhead or side effects and just did what I did above. So, this was not the best decision on my part.

The fix was to eliminate the temporary pthread_mutex_t variable on a stack and use the mutex member of the MUTEX_HANDLE structure directly: 

static int createMutex(MUTEX_HANDLE **pHandle) {
    MUTEX_HANDLE *ph = malloc(sizeof(MUTEX_HANDLE));
    if (ph) {
        int err = initMutex(&ph->mutex);

So, the EXC_ARM_DA_ALIGN error was just a big distraction that had me wasting quite a bit of time looking in the wrong direction. 


iOS 5.1 and Xcode 4.3.1 upgrade

I got the iOS 5.1 upgrade for my iPhone yesterday.
Then the Xcode needed to be upgraded to 4.3.1 in order to work with my phone with iOS 5.1.
Then cpp compiler link got screwed up again.
In the previous post I mentioned that you can fix with creating the new link:
sudo ln -s llvm-cpp-4.2 cpp


The old directory /Developer is gone now and the new one where you have to create the link is:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

Enjoy!

Tuesday, March 06, 2012

Upgraded to Xcode 4.3, got missing cpp

Xcode upgrade to 4.3 had bitten me again, it removed the workaround for cpp compiler that I had to put in awhile back.

In this case I was building libcurl and got this error:
./configure: line 2062: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp: No such file or directory

sure enough the workaround as I posted before (Native libraries porting to iOS) is to create the missing symbolic link in the /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin directory:
ln -s llvm-cpp-4.2 cpp

Friday, March 02, 2012

XCode 4.3 and Mac ports

Just upgraded to XCode 4.3 and Mac ports started to give me this warning, when for example I tried to upgrade:

$ sudo port upgrade outdated
Warning: xcodebuild exists but failed to execute
Here is some help on this: https://trac.macports.org/ticket/33398

In order to fix this problem just  execute:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Mac OS X hidden files in Finder app


Just wanted to share a couple of functions from my .bash_profile that allow to show or hide the hidden files and directories in Finder app on Mac OS X.

function showHidden {
defaults write com.apple.finder AppleShowAllFiles TRUE;
killall Finder;
}

function hideHidden {
defaults write com.apple.finder AppleShowAllFiles FALSE;
killall Finder;
}


Enjoy!