Posts for the ‘Hacks, Tips, Tricks’ Category


Building, Installing, Configuring The Android Platform and Android SDK on Ubuntu 9.10 64-bit x86

Wednesday, November 11th, 2009

Android SDK LogoUbuntu Logo

This post is about my battle of building, installing and configuring the Android Platform and the Android SDK on Ubuntu 9.10 64-bit x86. Insult to the injury, all that is happening in a VirtualBox VM on a Mac running Snow Leopard.

Please remember, this is NOT intended to be a step by step instruction manual. RTFM ;)

Follow the regular installation instructions and possibly throw in the following in the mix, when and if you have to.

You will need the Android Source to build (doh!). Here.

Obstacle #1. No Java 1.5.0 in Ubuntu 9.10. Gotta have it, otherwise Android “make” barely bothers to launch.

http://java.sun.com/javase/downloads/index_jdk5.jsp is a starting point. I grabbed the rpm build.

Assuming you have the “rpm” (otherwise apt-get install rpm), install the downloaded package. –force-debian –nodeps flags may be required.

Now you have Java 1.5.0 in place, you need to setup your environment properly.

1
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.5.0_22/bin/java 50
1
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.5.0_22/bin/javac 50

** change your jdk1.5.0 path if necessary

Getting close.

The “apt-get install” in the documentation http://source.android.com/download includes “sun-java5-jdk“, so take it out and run the command as follows:

1
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

Try the “make” now.

Next is installing the Android SDK on Ubuntu 9.10. Grab it at http://developer.android.com . Unzip, move it around etc.

Starting with Android SDK r3, you need to pick and choose what you want to download and install. “./android” under the “tools” directory does that for you. However, every single time I tried this on my Macs, I got the “You might want to force download through HTTP in the settings.” error. So be it, go the the options, simply check the “Force https://… sources to be fetched using http://…” option and download happily ever after. This was a no-go in my Ubuntu 9.10. The trick to properly enable and utilize that checkbox is to run:

1
export GDK_NATIVE_WINDOWS=true

Now, you should be able to download the SDK without the https:// mallarky.

After all this, hopefully, you should be Android’ing in your Ubuntu box in no time ;)

Good luck.



Crockford on JavaScript — Act III: Function the Ultimate

Wednesday, February 24th, 2010

Act III: Function the Ultimate. We’re going to be talking about functions tonight. Functions are the very best part of JavaScript. It’s where most of the power is, it’s where the beauty is. Like everything else in JavaScript, they’re not quite right, but you can work around that, and there’s a lot of good stuff here.

Keep watching for the rest….



Launching Eclipse from the Command Line with Workspace Argument on Mac OSX

Wednesday, November 25th, 2009

Title says it all. :)

Launching Eclipse from the Command Line with Workspace Argument on Mac OSX…

1
open Eclipse.app  --args -data /projects/workspaces/myworkspace


Must Call This Function!

Tuesday, June 30th, 2009

I was going through some code refactoring today, and needed a certain set of classes calling a particular function during their initialization.

I needed the function to be absolutely (i mean absolutely) implemented by any deriving classes of the base object.

I needed the function called automatically, so I won’t have to remember calling it anytime I derive something new out of the base class.

So, here is how I accomplished this lovely must-call-this-function pattern.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
interface ISample
{
    public function makeSureThatThisFunctionIsCalled();
}

abstract class ASample extends TheParentClass implements ISample
{
    public function __construct ($someParams)
    {
        parent::__construct($someParams);

        $this->makeSureThatThisFunctionIsCalled();
    }
}

class Sample extends ASample
{
    public function __construct($someParams)
    {
        parent::__construct($someParams);
    }

    public function makeSureThatThisFunctionIsCalled()
    {
        // do whatever you need to do here....
    }
}

class AnotherSample extends ASample
{
    public function __construct($someParams)
    {
        parent::__construct($someParams);
    }

    public function makeSureThatThisFunctionIsCalled()
    {
        // do whatever else you need to do here....
    }
}

The code should be self explanatory for the OOP savvy folks. Here is a very short description of what happens here.

Our actual class “Sample” extends the abstract class “ASample” which in turn implements the interface “ISample” (don’t worry about extending the TheParentClass). Implementing the “ISample” will require us to actually implement the makeSureThatThisFunctionIsCalled() function somewhere either in “ASample” or “Sample” class. We need class specific implementation of the function, so “Sample” and “AnotherSample” classes implement it.

Oh great, yay! We enforced our derived classes implement a function of the interface. Big deal!

How will we make sure that “makeSureThatThisFunctionIsCalled()” function will actually get called ?

In this sample, all the deriving class constructors call their parent::_construct which keeps bubbling up to TheParentClass so on and so forth…

So, we simply stick in “makeSureThatThisFunctionIsCalled()” in the immediate parent’s constructor and tada !!!

Our must-be-called function is surely getting called during the object’s initialization.

This may sound like a glorified initializer, but you never know. You may just need something like this.



Passing Hudson Environment Variables as Parameters

Sunday, November 22nd, 2009

Sick weekend; flu, cold, whatever it may be. Hence, for the lack of anything better to do, I gorged myself back into some build-package-release stuff for the Aliro project. The first biggest piece was integrating Hudson, SVN, Ant. And below is a short note for something that made me chase my tail for a bit.
If you’re putting together a build system, most likely you’ll need to pass some variables/parameters into some other processes. In my case, I needed to pass a few Hudson environment variables as parameters to Ant; Hudson workspace path, build number etc. The following table contains a list of all of these environment variables that can be passed around as parameters from Hudson.

Environment Variable Description
BUILD_NUMBER The current build number, such as “153″
BUILD_ID The current build id, such as “2005-08-22_23-59-59″ (YYYY-MM-DD_hh-mm-ss)
JOB_NAME Name of the project of this build. This is the name you gave your job when you first set it up. It’s the third column of the Hudson Dashboard main page.
BUILD_TAG String of hudson-${JOBNAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.
EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the “build executor status”, except that the number starts from 0, not 1.
JAVA_HOME If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME/bin.
WORKSPACE The absolute path of the workspace.
SVN_REVISION For Subversion-based projects, this variable contains the revision number of the module. If you have more than one module specified, this won’t be set.
CVS_BRANCH For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.
*from http://wiki.hudson-ci.org/display/HUDSON/Building+a+software+project

Now you know the names, all you need to do is build.path=${WORKSPACE} in the Ant properties box in the Hudson project configuration. Of course, you can access that parameter as ${build.path} in the Ant build xml or properties files.

Hudson kicks off the Ant, the command line looks like:

1
ant -file build.xml -Dbuild.id=${BUILD_ID} -Dbuild.workspace=${WORKSPACE} init


StumbleUpon’ing Into Yahoo! Search via Yahoo! Pipes

Friday, March 6th, 2009

If you see “No Results” in the box above, it’s because WordPress messes up with the javascript embed.

You can try this on your own StumbleUpon.com account @ http://pipes.yahoo.com/yipes/yourstumbles

What is this ? How does this happen ?

Per Yahoo!;

Pipes is a powerful composition tool to aggregate, manipulate, and mashup content from around the web.

And it really is.

(more…)



Two Simple Scripts to Detect Spammers in SMF

Saturday, February 14th, 2009

I’ve been going through some spring cleaning in our forum today, and ended up running few SQL scripts against our SMF forum database to get a better idea of who might be spamming us.

I got some counts from those simple scripts below, and registered a lot of “Ban on IP” and “Ban on email” triggers. Perhaps, they might be useful for somebody else too.

1
2
3
SELECT `memberIP`, count(`memberIP`) AS `how_many` FROM `smf_members` WHERE `is_activated=0` GROUP BY `memberIP` ORDER BY `how_many` DESC

SELECT `memberIP`, count(`memberIP`) AS `how_many` FROM `smf_members`GROUP BY `memberIP` ORDER BY `how_many` DESC

This spamming stuff sucks big time. Every other month, I end up wasting 4-5 hours of my time trying to clean the crap of those low-lives leave behind.