Tuesday, January 03, 2006

 

Photo blogs

Been looking for a way for a mate of mine to liberate his site from the generally useless hosting I provide him with as a favour. (I have cheap reseller hosting, but my provider keeps mucking up permissions, DNS, you name it. Haven't got round to moving.)

Anyway, what he really has is a blog, although it's currently managed by a CMS (He started it in the days before blogs). Trouble is, he has stacks of photos on his site as well. See http://www.marcosworld.com.

Anyway, it seems that you can now IM pictures to your blog, but I'm not sure this suits the large number of pictures he's showing. I think this might be more suitable: http://www.flickr.com.

Flickr seems to offer lots more organisational options, and also supports upload from camera phones (moblogging). Looks like it'll do the trick for him in combination with Blogger.

Friday, December 30, 2005

 

I really want a new digital camera!

I use iStockphoto.com quite a lot. I use the site for two purposes: If I'm planning a painting, I might buy some photos and take some ideas from them, and I also use them for web design.

I currently own two cameras: A really old Epson digital camera, which is clunky and outdated now, although it was good, er, five years ago (blimey, longer than I thought!). The other is a Canon EOS 300V or something like that, and it's an average conventional SLR. I really want to invest in a decent digital SLR, like the budget Canon 350D or Nikon D50. Trouble is, I'm on a budget.

Actually, I'm totally brassic all the time (Don't have what could be described as a budget). There are just too many other things that demand my money.

Now, I thought that I'd quite like to start selling some of my photos on iStockphoto, which might go some way to pay for the camera. Now, I've just discovered that I'd need about 500 decent photos on the site to pay for the camera in a year. I don't think that my photography is that good. Damn.

Wednesday, December 21, 2005

 

Experiences porting from PHP to Java

Recently, I've been occupied porting an app to Java. The original app was written by myself in PHP, and is running with no problems at all. The problem is that the platform it's on isn't supported 24/7, while PHP isn't supported in the main hosting environment. Hence I had to use Java and rewrite the app.

Now, I had the advantage of knowing the app inside and out, although my Java experience (<> 5 years). Additionally, I'm using Oracle for the port, which I've never needed to use before.

I suppose it's inevitable that I'll need to learn Java at some stage, but that doesn't mean that I have to like it :) Can't say that I like Oracle much either at the moment, although I can see benefits over MySQL when it's used in anger.

Problem number 1 for me is of course getting used to datatyping. I use types in PHP too, but of course I only do this when I want to force something to be an int, or something. I find it really boring having to do something like this:

int i=1;
String s = "1";
if (new Integer(i).equals(new Integer(s).intValue())){...


while in PHP, I'd just do this:

if (i==s){

OK, I know that they're different types, but who cares? Most of the time, this data's coming from a text source anyway, like form input, and any implicit cast from int to string is what is intended anyway (like comparing an int counter in a 'for' loop with a string).

Anyway, I do like a lot of things about Java, don't get me wrong, but there are some things that annoy me.

Another example: I'm using a PreparedStatement type to get my SQL ready. Just seemed to be the 'Java' way of doing things. So, being unfamiliar with the type, I just started coding according to how I expected it to work. When it didn't work, I had loads of grief debugging the SQL. Problems:
  1. With an SQL statement like insert into foo(columnA, columnB) values (?,?), I decided that the first ? should be index 0, the next ? should be index 1, etc. Wrong. When I'd sorted that error, which was admittedly quick and easy to sort...
  2. I'd put the ?s in quotes, like this: '?', without realising that that's what setString() does.
  3. You can't see the SQL that's produced and actually sent to the database! At all! toString(), as is too common in Java, doesn't provide any useful information, there's no 'getSQL()' method, no 'getLastStatement()' kind of method in a Connection type, etc. You can't get it in debug mode in Eclipse either. Arrgh! I wish I'd just either hard-coded the SQL, or used a kind of pseudo statement-template now, so I had some means of getting back the actual SQL (so I could execute it manually to test it).
On the other hand, a bit of persistence with another problem has resulted in some pretty useful code. I needed to shell to execute remote commands with SSH and use SCP. I tried jsch, but there is no documentation, bugs in the code (putting a password in a user auth object made no difference - it was never used...) and incomplete examples. So, I decided that I'd just try to capture everything that would normally be sent to stdout so I could parse it for human-readable errors and other messages.

Here's a basic version of the code:

r = Runtime.getRuntime();
p = r.exec(cmd);

InputStream in = p.getInputStream();
InputStream error = p.getErrorStream();

StreamEater seIn = new StreamEater(in);
StreamEater seEr = new StreamEater(error);

ht.put("error", seIn.getString());
ht.put("output", seEr.getString());


What I discovered is that you need to empty both the InputStream and the ErrorStream before the command will return. And all sorts of stuff can be put in the error stream, like information about the host you're connecting to. What's more, you can't just empty the error stream then empty the input stream in sequence, because this isn't always going to work. What you need is a class that just takes a stream as input and reads everything from it, then supply some way of getting the resulting string (I used a string buffer).

This is better than my existing PHP solution. exec() in PHP only returns the last line of output. Passthru() does, but it doesn't return anything, just sends output to stdout (browser, typically). Of course, having written this, I've looked in the PHP online manual and found proc_open(), which seems to support everything I need. It was introduced in PHP 4.3.0. *Sigh*

Friday, December 16, 2005

 

Mozilla Thunderbird 1.5

I've been getting a bit impatient with Thunderbird 1.0 recently. It seems to take ages to delete messages - the entire computer becomes unresponsive for a few seconds before it finally deletes them.

I thought I'd check to see if Thunderbird has been updated, and sure enough, there's a version 1.5 RC1 available.

I installed this using the default options without really thinking (It was early in the morning) and was relieved to find that all my accounts are intact in the new version.

One of the things I was interested in checking out is the RSS support. Sure enough, RSS support has been extended, and it's now possible to channel several RSS feeds into a single folder. For someone like me with several interests, it's a bit of a godsend, but organisational capabilities are still a little clunky - for example, the 'manage subscriptions' page doesn't allow you to add or delete folders - you have to do that by right-clicking the 'news and blogs' icon in the left hand pane.

A lot of the other enhancements seem to be playing catch-up to Outlook. However, I'm glad not to have to use Outlook, so good work guys.

Did it speed up deletion of messages? Nah. Maybe next time. Or maybe I should actually spend some time getting spam filtering to work properly for me (too many false positives last time I tried).

Sunday, December 11, 2005

 

Oil depot fire in Hemel Hempstead

Off topic for the blog, but blimey! You see this stuff on the news. Sometimes they happen a bit close to home, like the London bombings. But I've never been so close to the trouble before. This morning at just after 6 am, a massive expolosion woke me up. I jumped straight out of bed and knew immediately that it wasn't thunder. It was so loud! I went into the hallway and the loft hatch had fallen down. It turned out later that this had happened to most of the town...

We guessed what had happened before it came on the news. The oil depot up the road had exploded. It was still dark, though, and quite foggy, so we couldn't know for sure until we'd seen it on the news. At first it was thought that a plane had crashed into the depot, since it's on the flight path into Luton airport, but now it seems that it was an accident. Some accident!

Right now, I'm at home, because the smoke is being blown away from our house. If that changes, I guess we'll probably go and stay somewhere else. There's no sign at the moment that the fire is going to be put out today.

Don't think I'll be staying at work for long tomorrow.

Thursday, December 08, 2005

 

Why the blog?

OK, I'm going a bit mad with blogging recently. Dunno why I didn't take it up before now. Recently, I've put together this Formula 1 site and this site about the VIA Epia-N board.

Well, I program in PHP in my day job for a large telecomms company in Slough. What I do is basically rapid development stuff with PHP, MySQL and Apache. They're very kindly cross-training me to Java, and that's one reason I thought of writing this blog.

I also write code and publish it on PHPClasses.org in my spare time, and that's another reason for this blog. Just to talk about the development process, new stuff I come across, etc.

So, anyway, more later once I've played around with the templates and all that:)

This page is powered by Blogger. Isn't yours?