Categories
Computing Java

Generating Short Alphanumeric Identifiers in Java

I will make it short and sweet, for a change: suppose you have a large number that you want to distribute to users, and you want to instead to give them a shorter, easier to share string of characters.  220p9 instead of 3453453. Neat, no?

I grappled with this, being a moron, for way too long – looking into Apache Commons Id. The issue is that I also needed to use this ID with a database, and that means that there could be issues of concurrent requests for identifiers and other messy situations. I also did not need something overly fancy, just alphanumeric identifiers. The problem was that I was too stressed to think, if I may be excused. Anyway, the solution is just silly:

Let the database generate the usual integer unique identifiers that grow with time. Whenever you need to use a short, alphanumeric identifier, simply use base conversion, to base 36, on that number. How easy is that? The conversion, in Java is done using the Long or Integer objects’ toString(number, radix) methods. To convert back use the valueOf() method.

Pretty bad of me.

Share
Categories
Computing

Enabling Tags in Windows Live Writer for WordPress

I started using Windows Live Writer about 6 months ago as it was a surprisingly useful tool coming from the most surprising source, Microsoft. It actually worked, see. One feature that I was missing though, and made me stop using it was the fact that I could not get it to tag posts. I love tagging, well, I fell in love with tagging and I was willing to bear the awful editors WordPress provides in order to just do that, tag. So today I updated the version of Live Writer to the latest release candidate. Never mind the totally awful classic Microsoft uber uber bloatware (to download one update you end up with almost 200MB of unrelated crap) – the fail machine cannot change, can it? – and voila, I have the new Live Writer. And it still cannot tag the way WordPress does it. Its tagging is meant to correlate your posts to sites like Delicious and Technorati. Not what I wanted. Luckily I found this awesome tool that turns on a setting in Live Writer to do that. Run the downloadable program, restart Live Writer and press F2 to show an additional form, that includes tags for your own blog. Yay!

This is how it looks in the end. Yay useful. Thanks Microsoft!

tags-enabled

Share
Categories
Commercials Computing Java WebSphere

Building an IM Bot with the Smack API. Avoid setting Roster Permissions

So I built what is an instant messaging bot using the Smack API and the Openfire XMPP server. Doing it is pretty simple of you read the documentation and Smack’s developer notes. The bot relies on a queue-like object that Smack gives you called a PacketCollector. All you need to do is log in to the server, and let the packet collector wait for incoming messages. Clearly, you need to respond to the messages and use thread tools to do the waiting and all, but in general, the effort is relatively straightforward.

Share
Share