Category Archives: Programming

Titanium Mobile integrating Admob/Smaato with Android on Mac OSX

Titanium doesn’t have Admob/Smaato support, so it is really hard to monetize free applications without using Webview Onclick Trickery (even then you’re not utilizing the full potential of Admob’s seamless integration). Thankfully, David Ashwood has released source code for Admob and Smaato Integration on his (branch). Unfortunately, the instructions in his posts are clear but not working (some only work on Linux), however I’m using Mac OSX for development, so it doesn’t help me much. Although I had learned java jar files are platform independent, but they didn’t work in my project (but that’s topic for another day). So I figured I’ll give a broad overview of how to get it working:

Note: I’m not sure if each of these steps are necessary, but this is the way I went on doing it, so you’re welcome to ignore any step that you feel is redundant. But please do leave a comment specifying it, so in the future other developers may not face the same problems.

  1. Follow Titanium Documention to get Titanium built from source (for practice and setting up paths/classpaths that you need later)
  2. Install Android SDK and Google APIs (if you haven’t already)
  3. Clone dasher’s fork
  4. Checkout the branch
  5. If using scons, edit the android/build.xml file to fix the two paths: android.platform and google.apis. They point to the older way If using Eclipse, you can specify these two CLASSPATH variables: ANDROID_PLATFORM and GOOGLE_APIS (as the Titanium Documentation to build from Source (Step 1) suggests).
  6. Run scons or Eclipse to generate jars. I got a zip archive at the end of the process in distribution folder. (I don’t know if Eclipse does it, because I did it through scons. I would argue the regular eclipse build does it as well.)
  7. Unzip this archive in your Titanium application directory, where the following directory structure exists: mobilesdk/{platform}/{version}. Be careful if replacing files/folders. I created a new directory for the {version}, because if this build doesn’t work for whatever reason, you’ll have an option to fallback on the original Titanium version.

And amazingly, you have Admob support in 1.4.1.1 (the latest version for Mac OSX).

Last tidbit: I noticed that moving these jars are very easy, just be sure to carry the other jars along with you, like the admob-sdk-android.jar and SOMAAndroidSDK.jar. I’m not sure if you need these, but I got rid of some crashes that were happening earlier.

Import error while building Eclipse Plugin in a Java Project

I was trying to build a Java project I got from somebody using the Eclipse Gallileo install. Since the workspaces were different, my Eclipse install was confused about the eclipse plugins jar files, and it threw the following error:
"The import org.eclipse cannot be resolved"
on line: import org.eclipse.core.runtime.Plugin
and other cryptic errors: "BundleContext cannot be resolved to a type"

I resolved this by adding the appropriate jar library files from my eclipse directory. Here’s how I searched which files I needed.

  1. Go to eclipse plugins: cd eclipsedir/plugins
  2. For each suspecting jar, I do jar -tvf filename.jar | grep "searchingforthisClass"
  3. In the end I found my Plugin class: jar -tvf org.eclipse.core.runtime_3.5.0.v20090525.jar | grep Plugin
  4. Right click on the project in Eclipse, choose Properties, under Libraries tab, click “Add External JARs” button, then just locate that jar that you found above.
  5. Rebuild

PS: This is more of a reference for myself than for other Java developers, because this is probably as basic as it gets.

Convert Django MySQL Database Tables to Unicode

When I created a Django application, I hadn’t noticed that my MySQL was defaulted to latin character set (probably by Virtualmin or CentOS’s default MySQL values). So I didn’t want to delete my current project and start again. So here are the commands to convert a database to unicode:

for the database

ALTER DATABASE djangodb CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

on each table do

ALTER TABLE djangotablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

Django: “Error importing authentication backend”

This is probably a very rare error that one may encounter in Django. But I think I should share it here, as it would save about an hour of anybody else who has this problem.

Problem
Exception Type: ImproperlyConfigured at /
Error importing authentication backend

Probable Cause
I was very desparate to change the name of an app inside my Django project. I renamed the folder name and all possible mentions of the application name anywhere in the code and the database tables (Please note: This is not recommended, there is probably a better solution to do this). Once I faced that problem with no clear indication of where I was going wrong, I looked everywhere in the code and the database. After going into panic mode, I tried desperately changing and removing anything that may break. In the end, I ran out of places to find the application name but the error still existed.

Solution
I had noticed after looking at my cookies that I still had cookies from my session, which meant that everytime I connected to the server, I was trying to pass my “delicious” cookies. But just deleting your own cookies won’t do it. The session object of the user was cached in the database inside the table “django_session”. This especially stores the “AUTHENTICATION_BACKENDS” last used. So, truncate the table: TRUNCATE TABLE django_session to finally get rid of this nasty problem.

MySQL trigger error: Explicit or implicit commit is not allowed in stored function or trigger.

I haven’t seen this documented in MySQL docs, so I’ll share this little hidden nuissance. When compiling a trigger, MySQL throws the following error: Explicit or implicit commit is not allowed in stored function or trigger.

What does it mean?
The code inside the trigger is doing a commit. Looking at the code for the trigger alone is not enough, you must check all procedure/function calls, because the code inside any calls could really be (part of) the problem.

Problem?
The problem is usually we look in our code and find that there are no “explicit” commits. The problem is that there is a implicit commit happening somewhere and it is hard to pinpoint where if you didn’t know this one hidden fact:

Depending on version and storage engine, TRUNCATE can cause the table to be dropped and recreated. This provides a much more efficient way of deleting all rows from a table, but it does perform an implicit COMMIT. You might want to use DELETE instead of TRUNCATE.

Moral
DELETE FROM tablename rather than TRUNCATE TABLE tablename.

Avoid for (var x in array) when using jQuery/PrototypeJS

I was looking to make my code look more readable by “cleverly” using for (var x in array) loops instead of for (var x=0; x < array.length; x++), even though the shorter for loops are not supposed to be used with arrays, but used only with objects.

Turns out that jquery/prototypeJS put in extra hidden variables inside the array. If for whatever reason you are not using a JavaScript framework/library, you can use cross-browser shortcut: for (var x in array). However, be cautioned JavaScript experts are particularly annoyed by it.

Coldfusion 9 to 9.0.1 Update Error: “Variable ENABLEIMPLICITUDFREGISTRATION is undefined.” or Data Source page blank

If you see the following error in Coldfusion Administrator -> Server Settings -> Settings:
Variable ENABLEIMPLICITUDFREGISTRATION is undefined.

Or, when trying to add a Data Source, such as Microsoft Access (with Unicode), you see a blank page.

This is most likely because you have upgraded from a previous CF9 installation to either CF 9.0.1 or the CHF1 (hotfix 1 for 9.0.0 and 9.0.1). Sometimes you think you haven’t done an upgrade, but during the install process, pay particular attention, the CF9 Installer goes through a migration process, make sure to skip that.

It is actually easy to port over old settings by manually copying from one CF Admin panel to another, rather than try to figure out how to fix this bug. I’d like to add: there is no known fix, it is an open issue in CF Bug Tracker.