Monday, July 16, 2007

Caching in Php

Php by default tries as hard as it can to make the web browser not cache pages. While I can understand the rationale behind this a bit, sometimes you want caching. Caching is actually a good thing! you know. It means faster load times and lower bandwidth and processing requirements.

So I was surprised by how hard it is to turn off this aggressive non-caching policy. I googled for a few minutes and browsed the php documentation without finding an easy way of doing it. Ok, so you can use the following code snippet to enable caching in php (the argument to the function is number of seconds the page is valid):

function send_cache_headers($expire) {
  header("Cache-Control: max-age=$expire");
  header("Pragma: cache");
  header("Expires: " . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire));
}

Labels: , , ,

Sunday, July 15, 2007

The Days of Web Standards

As I mentioned before, I was going to appear at The Days of Web Standards, 2007. And as also mentioned, I was working on an ajax messaging library. I'm sitting here at the Days in Akihabara now, listening to one of the last presentations for the day. There's quite a lot of people here, and there's a certain conferency mood in the air. I have the W3C on my left and the Mozilla Corp. on my right. Got some nice Firefox stickers.

I combined the two mentioned matters and did a presentation and demo developing a chat widget using the freshly-released Ajax Messaging Library. Well, it's in early beta quality with many features planned but not yet implemented, but it works! Even on stage (except for a small bug, hehe). Anyway, it's out there now! I'll write more about it later.

P.S. I did the presentation in my socks; my shoes were drenched this morning by Typhoon no. 4.

Labels: , , , , ,

Friday, July 13, 2007

Me and The Gimp (and Four-Wheeled Cars)

I use The Gimp to create graphics for my projects. The main reason is because it's free (as in beer) - I usually don't warez software except old games that don't sell any more anyway. That goes doubly for software I use to create software. So Photoshop is out of the question. And The Gimp is a really good application.

But as anyone who uses The Gimp can tell you, its interface sucks. It has always sucked and continues to suck to this day. Interestingly, quite often some discussion pops up regarding this sucky interface, and whether anyone should do anything about it - or whether war is actually peace.

Just the other day there was this article linked on Slashdot about some academic-type dudes who have developed a modified gimp that collects usage data, to analyze how people use it and possible be able to improve the interface.

Ok, it's done at a university so I realize it's just someone's waste of time and government money, but still... Anyone who's ever used gimp can tell you that there's just one simple, outstanding issue that accounts for roughly half of its suckiness: The Windows (imagine that in place of "The Horror" from Apocalypse Now!). The Gimp opens gazillions of windows - and they're not contained in one parent window, like every other application in the world, no - they behave like independent application windows. You don't need academic studies to figure that out. So if you're editing the graphics to a web app for instance, you switch to Firefox to see the result, and then back to The Gimp, and you have to open like 8 separate windows to get your UI back to the state it was before switching to another application. This gets deadly tedious.

If I were tasked with designing a commercial car - and I'm a software engineer, mind you - when I got to the matter of how many wheels to equip the vehicle with, I would go with 4. Just like that - it's a no brainer. Every other car out there has 4 wheels. I think it must make structural sense, and people are used to cars having 4 wheels. A mechanical engineer or a car marketing specialist could probably tell you more. The gods know how many wheels The Gimp's designers would fit on their cars.

Guys! Don't go buying that Photoshop license just yet! I have a solution to the problem! (If you run Linux you can skip the rest of this paragraph.) Just use a virtual desktop manager - like the *nix guys do. I use one called Yod'm 3d. Unfortunately it's been bought up by some suspicious company and made commercial, but the last freeware version, 1.4, works good enough and can be downloaded (legally) for instance from The Pirate Bay. Just run The Gimp on a virtual desktop of its own. Linux people have been doing this for ages, but it's never been habit in the real world, although I heard the next version of Mac OS will have virtual desktops. Anyway, you can have it today, in your Windows. (I used to run only Linux for many years, so I got this habit of using virtual desktops extensively back then.)

There are still a few nuances to work out of The Gimp though. But it doesn't require a Ph.D. to figure them out. If you, like me, never start using Photoshop, then at least you won't be annoyed simply because The Gimp is different - it should be!

I wish it had a line drawing tool though.

Labels: ,

Thursday, July 5, 2007

A JavaScript messaging library

I'm working on a library for sending messages between browsers using JavaScript, XMLHttpRequest, and PHP/sqlite on a server. The idea is that even though it's not possible to open a connection of sorts directly between the clients (i.e. web browsers viewing a page, or even different pages, or running a widget), you can pull for updates in a way that will make it seem like you have a connection open. Not only that, but all client listening on the same channel, so to speak, will receive the messages, so it's like broadcasting. Technically this is nothing fancy, it's just that you don't see it much, and if implemented and packaged nicely I think it'll be useful and fun to use.

How do I know this works? Because it's based on a much cleaned up version of the code used on paintmyblog.com - which has proven itself already. I look forward to writing some cool apps using this library, and I hope other people will use it as well. Expect the first release next week.

Labels: , , , , , ,

Tuesday, July 3, 2007

Useful JavaScript Programming Sites

There are some sites I tend to consult all the time while programming in JavaScript. Let's see what they are...

Core JavaScript 1.5 Reference - Mozilla Developer Center
A thorough and complete reference for the JavaScript language and standard library, with examples and links to more information, etc. Really good.
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference

Gecko DOM Reference - Mozilla Developer Center
Complements the above reference with a complete reference to the document object model, i.e. all the methods and classes that are available in JavaScript for manipulating the web page in the browser.
http://developer.mozilla.org/en/docs/Gecko_DOM_Reference


Canvas Class Reference -
Apple Developer Connection
If you like playing with the canvas tag like I do, then this is the place to go for reference documentation on the 2d graphics context object. Complete and handy with all in one page.
http://developer.apple.com/documentation/AppleApplications/Reference/SafariJSRef/Classes/Canvas.html

Prototype JavaScript Framework API
The reference documentation for the Prototype framework. Of course, this is only useful if you're using Prototype. But if you're not, you better have a really good excuse... such as using some bloated alternative like the Yahoo UI Library or Google Web Toolkit.
http://www.prototypejs.org/api

Dojo ShrinkSafe

Dojo ShrinkSafe shrinks the sizes of your JavaScript source files by removing whitespace and renaming local variables to shorter names, and some other stuff. Saves bandwidth and loading time without really giving much up, except debuggability. But you're not doing debugging on your live site anyway, right? Riiight?!
http://alex.dojotoolkit.org/shrinksafe/

Labels: , ,