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!

Wednesday, February 29, 2012

gdb print errno

This command under gdb debugger will print errno: p (int)(*__error()) 

Tuesday, February 28, 2012

Mac OS X tips

Here is few tips for Mac OS X that I use quite often:

$ nm -A {file name} - to get list of symbols defined in the dynamic library.


$ otool -L {file name} - to get the list of shared libraries used by the dynamic library or executable.


$ lipo -info {file name} - to get the information on what CPU architectures are supported by the library or executable.


$ lsof -i -P | grep -i "listen" - to get the list of open ports with processes names that your machine is listening to.

$ man -k dtrace - lists lots of useful dtrace tools available, that allow to trace for example IO activity, processes, and many more

Monday, February 27, 2012

iOS ARC first impression

I started to use iOS ARC (automatic reference counting) feature on one of the brand new projects recently. It feels a bit weird leaving the dangling pointers around and takes few hours to get used to it.
Few open source projects I'm using actually followed the precedent and had the latest code already compatible with ARC. The rest of the non-ARC code is not that difficult to mix with existing project just have to use the compile flag for the files that is not ARC compliant: -fno-objc-arc

Overall it seems like the developers' job got a bit easier, leaving up to compiler to track the memory allocations and releases.
Feel free to post your thoughts on ARC and maybe you know some problems that I might get into down that path.
Thanks!

Tuesday, February 21, 2012

The Digital Content Problems and Thoughts


Stumbled on the this article today:
http://conversation.which.co.uk/technology/digital-download-legal-rights-after-death-amazon-itunes-apple

"As it stands, the rights of iTunes and Amazon customers look pretty shaky when it comes to passing on downloads. If you buy a music track from a digital store, you’re essentially buying a license to play that track – a license granted to you only, which isn’t transferable upon death."

I guess that's why I still buy paper books and miss the old-style music media (CDs, tapes). The product that you can actually own, exchange and share freely with your friends and family.

The modern media distribution channels like iTunes or Kindle for example, in my humble option, promote somewhat egoistic thinking in many ways. Try to give your music collection or books that you have in one of your electronic DRM protected collections to your friends and family, good luck with that.
As this article points out you actually don't own what you buy, you can't transfer the ownership, such as give the book or the music album to anybody you want (it's not like giving the paper book).

In case of Kindle, Amazon controls you library and can delete any book at any time, as it did previously already. And if you die your relatives could not inherit what you have collected.

In many ways the content ownership and distribution got so much distorted by having so many "middle men" that the both ends of this system the content author and the content consumer are not getting the best deal they could.

Eventually I think, something has to change and one of possible ways the change might happen is with cutting off the "middle men" and by establishing the direct channels between the content authors and the content consumers.

I really hope it would be DRM-free, you own what you buy and you are free to use it however you
want with authors permission.

Monday, February 20, 2012

Android: "About those vector icons"

One of my friend, previously Windows programmer, started to do Android development recently and was confused with all the variations of screen densities and resolutions he has to deal with.
The first heated argument was about why Android can't use one-for-all image resource and scale it properly for different densities.
In fact Android actually does this for you, but the result kind of sucks most of the time.

The next argument was why can't they use the vector graphics for the images.
I remember I was looking into this myself long time ago and found an article with very detailed explanation, thanks to Kirill Grouchnikov. Posting it here so I don't forget the next time where it is:
http://www.pushing-pixels.org/2011/11/04/about-those-vector-icons.html

Friday, February 17, 2012

Anonymous Pro font

I tried Anonymous Pro font the terminal app and MacVim:
http://www.ms-studio.com/FontSales/anonymouspro.html

It looks good in size 14 bold with antialiasing on.
I like it so far, though this could and would change I'm sure :)

Thursday, February 16, 2012

Git-flow on Windows

I had to spend a day on Windows (OS) today.
Making bunch of open source tools (git  aka msysgit, ssh, cmake, nmake etc.) to work together on Windows is not that pretty.

I really like using git-flow that streamlines the development process with git very nicely.
Here is the useful link on how to get git flow playing nicely with msysgit:
http://blog.reichertconsulting.com/archive/2011/07/04/git-flow-installation-on-windows-using-msysgit.aspx

Basically you would have to get the missing getopt.exe with dependencies from http://gnuwin32.sourceforge.net/packages/util-linux-ng.htm.

Hope this saves you a bit of time.

Tuesday, February 14, 2012

Vim thoughts

One of the frustrations of getting used to Vim editor, is when you get back to the "real world" (browsers, editors, IDEs, etc.) the navigation with h,j,k,l buttons doesn't work, instead they all require you to use "arrow" buttons. IMHO the "h,j,k,l" navigation is so freaking awesome.


Update (02-14-2012):
Vlad, sent me the link to Vimium http://vimium.github.com/ - the Crome extension. Still, as I type this post I have to use arrow keys to move the cursor.
Also need to figure out how to do the same kind of thing for the terminal app, the mail app, etc. ....well, pretty much for every app that uses scrolling and navigation. I wish there was some global setting on Mac OS X to allow to do just that in one single change.

Random Act of Kindness

I went to the Fresh Fields grocery store today and while at the register I
realized that I forgot my wallet at home. I started to move my stuff back to
the basket explaining the situation to the cashier. She smiled and offered to
pay for everything, saying that I can bring money back later (it wasn't like
$20, the total was around $140).
The fact of receiving such trust from the person who doesn't know me at all was a really awesome
experience.
I found myself thinking, that with all the negative energy pouring out from the news, radio, TV,
magazines, sometimes we forget that there are a lot more nice people around.
I took the cachier's name and the phone number and of course
brought the cash back in an hour.
Trust, after all, is such a fragile thing, so when you get it, you really
don't want to ruin it.
... still thinking about what happened today ...

Saturday, February 11, 2012

Building MacVim on Mac OS X

Here are some instructions:
https://github.com/b4winckler/macvim/wiki/Building

The problem that I stumbled upon was the errors with libicon:
Undefined symbols for architecture x86_64:"_iconv", referenced from: ........

The libicon on the system is not compiled for 64bit by default.
To fix this you need to get the latest libiconv-1.14:
http://www.gnu.org/software/libiconv/#downloading

Configure it with:
CFLAGS='-arch i386 -arch x86_64' CCFLAGS='-arch i386 -arch x86_64' CXXFLAGS='-arch i386 -arch x86_64' ./configure
then >  make && make install

After that you can get the MacVim source code and build it fine, got 7.3.401 now.

Latest Vim for Mac OS X

The 7.3 version on Vim that comes with Mac OS X is getting old. It doesn't support some of the latest features and you would not be able to use some of the interpeters like ruby that is not supported out of the box.
One way to improve this is to install MacVim, another one is to recompile Vim from source code configuring some of the missing features. Here is how I configured it for myself for example:

* Get source code:
> hg clone https://vim.googlecode.com/hg/ vim

* Compile & Install:
> cd vim
> ./configure --enable-luainterp --enable-perlinterp --enable-pythoninterp --enable-tclinterp --enable-rubyinterp --enable-cscope
> make -j4
> make install

By default everything will be installed user /usr/local, so make sure that /user/local/bin is specified before /usr/bin in your PATH environment variable, or use a different prefix for ./configure  that already specified before /usr/bin path for example --prefix=/opt/local.

After these steps I got Vim 7.3.434 on my machine.

Wednesday, February 08, 2012

Chrome for Android - remote debugging

I finally got Galaxy Nexus phone,
and the same day stumbled upon the Chrome for Android beta announcement:
http://googleblog.blogspot.com/2012/02/introducing-chrome-for-android.html

Installed it, and, boy, it is fast and awesome :)

Here is just a bookmark for myself on how to debug web apps with Chrome on the phone:
http://code.google.com/chrome/mobile/docs/debugging.html

Saturday, February 04, 2012

Vim, some useful links

I started using vim more actively recently and really enjoying it.
Here is a good find:
http://code.google.com/p/vimcolorschemetest/
The page has links at the bottom with hundreds of colorschemes to preview.

Here is a good article with useful links:
http://nvie.com/posts/how-i-boosted-my-vim/

Also, really liked Derek Wyatt's videos:
http://www.derekwyatt.org/vim/vim-tutorial-videos/

Wednesday, February 01, 2012

Ant macros for Git checkout

...just stumbled upon a couple of useful macros for git checkout here :
<macrodef name = "git">
    <attribute name = "command" />
    <attribute name = "dir" default = "" />
    <element name = "args" optional = "true" />
    <sequential>
        <echo message = "git @{command}" />
        <exec executable = "git" dir = "@{dir}">
            <arg value = "@{command}" />
            <args/>
        </exec>
    </sequential>
</macrodef>
<macrodef name = "git-clone-pull">
    <attribute name = "repository" />
    <attribute name = "dest" />
    <sequential>
        <git command = "clone">
            <args>
                <arg value = "@{repository}" />
                <arg value = "@{dest}" />
            </args>
        </git>
        <git command = "pull" dir = "@{dest}" />
    </sequential>
</macrodef>