Software Development

You are not authorized to post comments.

URL Shortener Web Application Using Django

I created a URL shortener web application using Django (a Python web framework). I have made the source code available on GitHub and it is under an open source license (MIT license).

The shortened URLs use the base 62 value of ids of the model they are stored in, using the code from here (it uses A-Z, a-z, and 0-9), which should be fairly compact for a long time. A count of how many times the URLs are used is kept. The main page shows the 10 most recent and 10 most popular URLs.

You can see a running instance at n1l.us (which I am using to link to this blog and other links to my own content) and uu4.us (which I am using for all other URLs). I currently don't allow public submissions of URLs on either of those sites, but I will be opening it up for uu4.us at some point (perhaps once I add some defenses against spammers). The application itself has a configuration option to be able to require or not require login to be able to submit URLs (the REQUIRE_LOGIN setting in settings.py). Note that if you require logins, you have to use the admin app (at /admin/) as I have not created a separate login page.

I've so far done the bare minimum as far as HTML/JavaScript is concerned (and there is no CSS to speak of yet). Just enough to get things working. So don't expect a good looking site with this yet. It does produce a functional bookmarklet, assuming that you set SITE_NAME correctly for your site. Though I should probably make the bookmarklet check for rev=canonical to be a good web citizen.

The biggest issue with Adobe Flash Player

Update: Looks like they have fixed this in Flash Player 10.1

The biggest issue with Flash Player at the moment is that there is no way to create a top-level exception handler. What this means is that there will be exceptions (errors) that you simply cannot trap in your application code, even if you put try/catch all over your code (and especially if you are using Flex's MXML). This means that creating things like an error reporting tool are impossible for applications that run in the Flash Player (that includes AIR apps, too, not just browser apps). If you are running the debug version of the Flash Player, you will see uncaught exceptions, but the typical user is not going to be running the debug version. In the regular version of the Flash Player, uncaught exceptions just fail silently (often causing strange behavior), giving no indication to the user that an error occurred.

There is an issue in Adobe's issue tracker for this:

http://bugs.adobe.com/jira/browse/FP-444

It is the highest-voted issue specifically for the Flash Player. It is only surpassed by the request to keep developing Flash Builder for Linux, which I think is an important issue, but this issue is much more important. If you haven't already, create an account on Adobe's issue tracker and vote for this issue.

CXF SOAP client built using Maven

I recently created some SOAP web service clients using Apache CXF (which is a project that resulted from the merging of XFire and Celtix). Rather than hunt down all the jar files I needed and write an Ant script to do the build, I decided to use Maven for this. It worked nicely and saved me some time (I can't say the same for some of the more complex projects I've tried to use Maven with).

I found the following blog entry very useful for setting this up:

How to create a WSDL-first SOAP client in Java with CXF and Maven

One thing I did different was use a property to specify the CXF version in one place:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cxf.version>2.2.1</cxf.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
    </dependency>

Pay attention to what it says about the cxf.xml file. I used the Maven Eclipse Plugin to generate my Eclipse project files. If you do this, but forget the cxf.xml file, your client may still work fine in Eclipse, but when you try to use the Maven-built jar file, you will get an error like this:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:314)

MyEclipse 7.0 Java template configuration bug

Update: This has been fixed in MyEclipse 7.1.

There is a bug in MyEclipse 7.0 which causes the template configuration preference to quit functioning. When I go into the template configuration, I get a dialog with the heading "Could Not Accept Changes" and the following error message:

The currently displayed page contains invalid values.

And the configuration page is almost completely blank. It just says "Create, edit or remove templates:".

This has been reported at this forum topic and they are aware of the bug. It exists in 7.0 M2 and 7.0 GA. MyEclipse 6.5 (w/ Eclipse 3.3) doesn't have this problem.

Workaround

I use this rather inconvenient workaround to get around this:

My workaround is to use a clean copy of Eclipse (that doesn't have MyEclipse installed) with its own workspace, and edit my custom templates in that copy. Eclipse stores custom templates in this file (along with a lot of other configuration):

ECLIPSE_WORKSPACE/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs

So what I do is I copy the line that starts with "org.eclipse.jdt.ui.text.custom_templates=" followed by XML from the clean copy to the one with MyEclipse installed. And restart Eclipse to pick up the change.

If you try this workaround make sure to make a backup of this file before you edit it, just in case something goes wrong.

A useful introduction to JavaScript video lecture

I came across the following video ("The JavaScript Programming Language") that is a lecture by Douglas Crockford (who is a "JavaScript Architect" at Yahoo!) in which he discusses JavaScript. It is split into four 30-minute parts (totaling 2 hours):

It's useful to download the slides because the video doesn't always show them when he is referring to them.

It is a good introduction to JavaScript, explaining how parts of the language works as well as offering advice on how to use (or not use) various features of it. He also talks some about the history of the language.

Getting Postgresql running on Ubuntu and OS X (Leopard)

Here are some good articles on how to get going with Postgresql on Ubuntu:

http://help.ubuntu.com/community/PostgreSQL

And Mac OS X 10.5 (Leopard):

http://www.z1r0.com/2008/03/configuring_postgresql_82_in_o.html

Note that version numbers don't matter, as I was able to apply these instructions to Postgres 8.3.

I also find the pgadmin3 tool to be very helpful with Postgres. In Ubuntu you can find it in the repositories, in Mac OS X, you can get a binary to install from here.

Java/.Net 2.0 web service interop with XFire

In this entry I discuss reasons to switch from Axis to XFire, and then how to get XFire as a server working nicely with .Net as a client.

I have written some past entries about Java/.Net web service interop, specifically how to get a Java Axis server working with a .Net 1.1 client. Now with .Net 2.0 we have nullable types built in to the language which removes the need to use the 3rd party library NullableTypes to handle nullable values.

Getting Ruby on Rails to work on Debian unstable

I had Rails installed using Debian packages from the official repository and thought I'd try out RoR development. So I started the cookbook example in the article Rolling with Ruby on Rails. Not so fast, I was getting an error because it was not properly translating the domain object name to the correct database table. It was not translating "Recipe" into the "cookbook.recipes" table like it should, and instead was looking for the table "cookbook.Recipe". I worked around this by changing the database table, but that only worked until I tried to add more than one record.

Syndicate content