Tuesday, December 18, 2012

Android building unsigned APK

Just a small Android development tip:

The Android export wizard that comes with Eclipse allows you to build the "release" APK of your application but expects you to have the signing keys at the time of the build, otherwise it doesn't allow to proceed. Sometimes you just need to send the unsigned APK to your client and allow them to sign it later.

The easiest way to accomplish that at the moment is to do the build with Ant (build.xml).
In order to generate the build.xml file you can run the following command in your application directory:
android update project --path .

This will create the build.xml file for you project. Then run:
ant release

and this will create the -release-unsigned.apk in your bin directory.
Sometimes (most of the time) the android tool doesn't pick the right name for the project and you might   end up with something like MainActivity-release-unsigned.apk, in that case just edit the project name property in the build.xml.

Note that if your app depends on the other library projects, then these also need to have the build.xml generated for them.

Wednesday, December 12, 2012

A couple of links on Android UI development

A friend of mine posted a couple of links related to Android UI development. Just leaving it here:
http://www.androidviews.net/
http://androidkickstartr.com/

Monday, December 10, 2012

Gitk on Mac OS X tip

Just a quick tip, if you are annoyed with
"CFURLCopyResourcePropertyForKey failed because it was passed this URL which has no scheme:" error messages in the terminal while running gitk.
Just add an alias into your .bash_profile:
alias gitk='gitk 2>/dev/null'


Monday, December 03, 2012

Code by Brian

My friend Brian started his own Android blog:

Code by Brian

Lots of useful stuff there and there is more to come.

Enjoy!

Sunday, December 02, 2012

Great article on Android UI performance by Romain

Stumbled upon this great article on Android UI performance problems detection tools, tips&tricks by Romain Guy on Google+:

http://www.curious-creature.org/docs/android-performance-case-study-1.html

Enjoy!

Monday, October 22, 2012

Android: pulling APK from non-rooted device and exploring the source code

Here is a simple way to pull the installed app APK from non-rooted device.
Well this technique worked on my Samsung Tab 10.1 tablet and didn't work on my Nexus Galaxy phone.

The main problem here is that with non-rooted device one can not browse the file system, to figure out which packages are installed, and their file names.

Here are the steps how to do this with SDK adb tool.
1. Pull down the packages.xml file to get the files that describes the packages that are installed on the device:
adb pull /data/system/packages.xml

2. Find the package tag that you are interested in. It should have a property codePath="/data/app/[name].apk"

Pull the apk file with:
adb pull /data/app/[name].apk

Now you are free to "reverse engineer" and explore the package with for example Android apktool for example.

Here is how get the decompiled java source code from the apk file.

1. Extract classes.dex:
jar xvf [name].apk classes.dex

2. With the help of dex2jar tool (http://code.google.com/p/dex2jar/), convert dex to jar:
d2j-dex2jar.sh classes.dex

3. Now you can explore the source code in the classes-dex2jar.jar with any java decompiler like for example JD-GUI (http://java.decompiler.free.fr/).

Enjoy!

Friday, October 19, 2012

Mandiant on Android

I went to MIRcon 2012 conference this week and one of speakers was a guy from our company who does some R&D for Android at our New York office.
I found his blog very interesting and just wanted to share here:
http://thecobraden.blogspot.com/

Enjoy! :)

Friday, September 21, 2012

The Easter Egg in Android tools

Try:

aapt dump badger [you app name].apk

and have a nice badger :)

Thursday, September 20, 2012

npm xmas

I haven't looked at npm code before, and today I did.
So if you run: npm xmas
you will be in for a surprise ;)

Thursday, September 06, 2012

A feature of Android "Jelly Bean": android:isolatedProcess

Just stumbled upon one interesting feature of the Jelly Bean.
The service tag got a new attribute android:isolatedProcess. 

"If set to true, this service will run under a special process that is isolated from the rest of the system and has no permissions of its own."

The application of this feature is quite limited, but interesting from a security perspective.

Basically, if you need to run some script (javascript, lua, etc) that you received from untrusted source or maybe some third-party library that might have some security issues, it allows you to isolate that part of you application in it's own "sandbox" process that doesn't inherit all the permissions of you primary application.

Friday, June 08, 2012

JSLint Vim plugin

I got involved in helping with the web project recently with lots of javascript (client and server-side frameworks etc) pretty much everywhere.
Yeah it's kind of amazing what javascript has become, amazing and a bit terrifying, cause the things can get real messy real fast without proper coding discipline on the team.

Anyways, I started to use jslint a lot in order to keep things cleaner and neater.
Here is an extremely useful Vim plugin that I use a lot recently:
https://github.com/hallettj/jslint.vim 
The inline highlighting with quickfix window support are awesome features and you can use ~/.jslintrc file to define your globals "directives" for jslint to avoid polluting the source code with it.

Enjoy!

Thursday, May 10, 2012

Mac OS X tar util adds files with "._"


So, if you got surprised after uncomressing the tar.gz file that was created on Mac OS X and finding a bunch of extra files starting with "._" for every file and directory, here is a solution for you.
To avoid these extra files to be added into tar.gz on Mac OS X, define the environment variable:
export COPYFILE_DISABLE=true

Wednesday, May 09, 2012

Android NDK8 now with MIPS arch support

With the support for MIPS architecture in the latest release of NDK8, the life of NDK developers became a bit more difficult again. We have 4 architectures to cross-compile a bunch of native libraries for: armebi, armebi-v7a, x86 and mips. I guess, this is just one more push to move towards Java code for better portability and smaller .APKs, etc.

By the way the issue with libc on x86 builds that I was posting about since NDK6 still exists.
One the native libraries that I use fails to build with the following errors:
undefined reference to `siglongjmp'
undefined reference to `sigsetjmp'
See here: http://aleksmaus.blogspot.com/2011/11/more-fun-with-android-ndk7.html

The x86 build fails with both Mac OS X and Linux NDK8.

If anybody on Android NDK team reads this, please, please, please fix it.

Monday, May 07, 2012

Mac OSX file handles limits

 I stumbled on this issue many times trying to run the services that open too many handles on Mac OS X (Lion). Even when you see the ulimit tool returning "unlimited" value, it's not actually unlimited.

Here are the couple of commands that I have to run to actually increase the number of allowed opened handles:
$ sudo launchctl limit maxfiles 500000 500000 
$ ulimit -n 500000


Wednesday, May 02, 2012

Bulding AOSP on Ubuntu 12.04

Update (July, 11, 2012):
Just built the Android 4.1.1 (Jelly Bean) branch from AOSP on Ubuntu 12 with no problems whatsoever. This makes this post no longer relevant.
Many thanks for that to Android development team.

//************************************************************************


I just started to play with Ubuntu 12.04 and stumbled on few issues while building Android source tree (AOSP master branch).

Here are few things that might be useful to know in order get AOSP building:

1. First, follow the instructions here http://source.android.com/source/initializing.html to install all the dependencies and set everything up.

2. Then install Sun JDK6, here is the link to the latest download at the moment:
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html

After downloading it, execute these commands:

$ chmod u+x jdk-6u32-linux-x64.bin
$ ./jdk-6u32-linux-x64.bin
$ sudo mv jdk1.6.0_32 /usr/lib/jvm/
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_32/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_32/bin/javac" 1

then switch to this version of java with:
$ sudo update-alternatives --config java
and
$ sudo update-alternatives --config javac

You can probably get away with OpenJDK6 (disable the java version check in the build/core/main.mk). I remember I had a problem compiling one of the CTS tests and fixing that required some java code modifications.

3. The failure while building qtools build can be fixed with changing
common_cflags := -O0 -g 
to
common_cflags := -O0 -g -Wwrite-strings -fpermissive
in the sdks/emulator/qtools/Android.mk

4. The failure with OpenGL libraries linking can be fixed with 
sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so

5. The failure while building obbtool, can be fixed in the  
build/core/combo/HOST_linux-x86.mk file by changing the following line
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
to
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

6. The failure with:
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1
can be fixed with adding the 
#include <stddef.h>
at the top of the external/mesa3d/src/glsl/linker.cpp file.

7. The failure external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
can be fixed by changing the external/oprofile/libpp/format_output.h file
mutable counts_t & counts;
to 
counts_t & counts;

8. The failure external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
can be fixed by adding 
#include <cstddef>
into the external/gtest/src/../include/gtest/internal/gtest-param-util.h file. 

9. The failure /external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
can be fixed by adding 
LOCAL_LDLIBS := -lpthread -ldl 
into external/llvm/llvm-host-build.mk file.

10. For the failure frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
I just commented out that line since the ParamName is not used anyways.

This might not be the best solution, but it builds and leaves me some time to improve it if I need it.

Hope this saves you a bit of time.

Friday, April 20, 2012

Javascript from the command line 2

I already wrote about this here: Javascript from command-line on Mac OS X.
Here is another tip.
The console.log() is not available for jsc, and you have to use the debug() API.
In order to keep using the console.log() calls just define:
var console = {log:function(msg){debug(msg);}}

Enjoy,
Alex

Wednesday, April 11, 2012

JSON.NET for ASP.NET

I had to add a JSON service to a very old ASP.NET 2.0 website I worked on quite awhile back.
Upgrading to the latest ASP.NET 4.0 was not an option. So the first thing that comes in mind is to quickly implement Http handler. Here is a pretty nice JSON serialization library that I stumbled upon and that worked for me quite well: http://json.codeplex.com

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!

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>

Friday, January 27, 2012

Samsung Galaxy Tab 10.1 - Stuck on Boot (link to article)

My Samsung Tablet "has died" today. It got stuck on boot for some reason.
I hooked it up to the computer and checked the logcat (adb logcat). 
It was trying to open the account database on the device, that for some reason got corrupted and after the failing to do so (unable to open database file, db=/data/system/accounts.db) it rebooted over and over again. The database can be easily fixed on the rooted device, but mine was not rooted yet.

After a bit of googling I found this useful article that describes exactly the same problem on exactly the same device and provides the solution:

Essentially, the solution comes down to deleting all the user data (aka factory reset), here are the steps from the article:

"In case you are wondering how to hard-reset your tab, you can follow these steps:
1) Power off the device by holding the power key for about 8 seconds
2) Press the volume down key (the one to the left, as I always confuse them) and then the power key
3) Within a couple of seconds, you'll see two logos on the device, one for USB and another, that looks like a Android dude shoveling earth
4) Press the the volume down button to select the the USB icon, and then press the volume up button to make the actual selection
5) Your device is now in the "fastboot" mode
6) Finally, open up your terminal/shell and type fastboot -w, which will completely erase your userdata and cache partitions (took about 12.5 seconds for me). I got the fastboot by building it from source, but you can download pre-built binaries from various sources on the web
7) Restart your device
8) You should now be prompted to set it up... all over again"

Many thanks to the author of that article Aleksandar Gargenta. 

Javascript from command-line on Mac OS X

Here is a "trick" to get the javascript command-line tool "jsc" available on Mac OS X,  just add a link, for example like this:
sudo ln /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ~/bin/jsc
then just run "jsc".

Friday, January 13, 2012

YAML parser for Android

I needed YAML parser for Android this week and after a bit of research I found that SnakeYAML might work: http://code.google.com/p/snakeyaml
The only problem was if you try to use the latest code the application would fail with exception that looks something like this in the logcat:

VFY: unable to resolve exception class 21 (Ljava/beans/IntrospectionException;)


This happens due to the dependency on java.bean package APIs that is used to parse getters/setters types of properties (methods). 
There is a prebuilt library already available in the download section for version 1.8 adjusted for Android: http://snakeyaml.googlecode.com/files/snakeyaml-android-1.8-SNAPSHOT.jar (thanks to Alexander Maslov), but I wanted to use the latest code. 
The adjustment for Android is quite straight forward:
* Remove all the imports of java.bean package components
* Remove the throws IntrospectionException from methods declarations in few files (grep, there are only 4 .java files to change 
* In the introspector/PropertyUtils.java adjust the getPropertiesMap method implementation, throw away the use of Introspector. Yep, the library will not support java getters/setters methods serialization after that, only fields, but that worked fine for me.
* Remove introspector/MethodProperty.java file
* If you want to save some time and don't care building and running tests (I know it's wrong, but still), then you can build the .jar library with mvn package -DskipTests=true command.
* Add the final .jar file into your Android project and enjoy YAML on Android

Update (02-22-2012):
Alexander just landed the patches for Android (http://code.google.com/p/snakeyaml/source/list).
Now the latest source code can be easily built with one command: mvn package -Pandroid or to skip the tests mvn package -Pandroid -DskipTests=true. After the build,  just use snakeyaml-1.11-SNAPSHOT-android.jar.

PipedInputStream default size on Android

The PipedInputStream on Android is 1024 bytes by default.

protected static final int PIPE_SIZE = 1024;

In many cases this value is too small, so the constructor with the size parameter should be used instead.

Thursday, January 12, 2012

Android application signing with PKCS12 (.p12) certificate

Here are few useful commands to sign the Android application with PKCS12 certificate.

* Import PKCS12 cert into keystore file:
keytool -importkeystore -srckeystore mycert.p12 -destkeystore mycert.keystore -srcstoretype pkcs12

* Change the certificate alias in the keystore if you like:
keytool -changealias -keystore mycert.keystore -destalias new_cert_alias -alias original_cert_alias

* List the keystore certificates (-v for verbose)
keytool -list -v -keystore mycert.keystore

* Sign the Android APK
jarsigner -verbose -keystore mycert.keystore myapp.apk cert_alias

* Verify that the APK is signed
jarsigner -verify -verbose -certs myapp.apk



OAuth2 with Google C2DM (push)

I had to implement the server prototype for Google C2DM (push) the other day.
The easiest option to get the auth token is to use ClientLogin API: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html  that returns the auth token in one call. One of the problems with this approach was that I either had to store the credentials on the server in order to refresh the auth token if it expires or notify the system administrator to go ahead and re-authenticate through the dedicated web page on the server. 

The better approach is to use OAuth2 API instead: http://code.google.com/apis/accounts/docs/OAuth2WebServer.html
There are couple of things are not well documented:
* When you register the app on the https://code.google.com/apis/console/ there is no C2DM service API to choose. That's fine for now, though it might change later probably.
* One of the parameters "scope" for the https://accounts.google.com/o/oauth2/auth call needs to be set to 
scope=https%3A%2F%2Fandroid.apis.google.com%2Fc2dm (https://android.apis.google.com/c2dm url-encoded)
* Set parameter access_type=offline.This will provide you with the refresh_token in the authentication response, that you can use to renew the auth token when it expires. 

Hope this will save somebody few minutes. 

UPDATE (January 19, 2012):
If you stumble upon the MismatchSenderID error, make sure that when you start authentication (https://accounts.google.com/o/oauth2/auth) that you are not already signed in under your personal google account (hint: the browser cookies) . You should be signed under the google account that you created and that got approved for C2DM.



UPDATE (July 2, 2012):
As of the Google IO 2012 the C2DM API is officially deprecated and this article is not really that relevant anymore.
The new sign ups and the quota increase requests are not going to be processed anymore and Google highly recommends to migrate over to the Google Cloud Messaging (GCM), which is still free and has lots of improvements and additional features. I personally think GCM is awesome. 
Please refer to the official GCM page for more details:
http://developer.android.com/guide/google/gcm/index.html
I'm looking forward to change my code to work with GCM pretty soon and will try to write another post on the transition process. Enjoy!

Wednesday, January 04, 2012