Sam @ Xnet

Archived Posts

Making better use of mod_deflate

By Sam, on Wednesday, 14 Jan 2009 at 1:40 a.m.

Output compression using Gzip and Deflate is a common feature of modern webservers. Webpages can be compressed by the server and then decompressed by the client seamlessly.

By default (at least on debian/ubuntu) Apache has a module installed and enabled called mod_deflate. While great, here is the default configuration:

<IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html text/plain text/xml
</IfModule>

Now at a glance this is fine, But modern webpages consist of more than just html, we have CSS, Javascript, RSS and even JSON, all of which can benefit from compression but aren't enabled by default.

Here's a modified config file that will compress these files:

<IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript text/css application/rss+xml application/json
</IfModule>

This config is usually located at /etc/apache2/mods-enabled/deflate.conf.

With this done jQuery (minified) goes down from 54KB to just 16KB of data send to the client :D

Multiple Onload Functions

By Sam, on Wednesday, 7 Jan 2009 at 2:26 a.m.

Here's a quick way not so good way (see update) of getting multiple javascript functions to be called when the page has finished loading.

Add this to the pages Head section:

<script type="text/javascript" charset="utf-8">
var onload_functions = new Array();
window.onload = function() {
    for (i in onload_functions) {
        var onload_function = onload_functions[i];
        onload_function();
    }
}
</script>

And then where you need an onload event callback do this:

onload_functions.push(function() {alert('The page loaded...'););

Update:

As pointed out by phihag, this solution isn't great, instead try using phihag's code or use jquery and just $(document).ready(function{} {alert('The page loaded...');});.

CSS Columns and the Box Model

By Sam, on Thursday, 1 Jan 2009 at 11:19 p.m.

One of the greatest frustrations for me when designing a website has been using css to layout a multi-column format (like this one).

I've found that it is important to understand the box model. more importantly knowing that when you set the width of a block element (ie div) it sets the width of the content. The padding, border and margin is wrapped arond it.

Box model image

Comments fixed!

By Sam, on Friday, 12 Dec 2008 at 1:52 a.m.

It seems that when i upgraded to django v1.0 it broke the captcha as all template variables are now auto-escaped, whereas previously escaping had to be done explicitly this meant that you would see the html, the field is now marked as safe and so fixed! :)

This really does prove to me the value of testing as its been weeks since I upgraded, I never noticed because as a site admin I dont see it. Doh!

On a side note, i'm wondering what peoples opinion on captcha is? personally I see it as essential, and that re-captcha is the best, second only to googles own.

New Look!

By Sam, on Wednesday, 26 Nov 2008 at 2:25 p.m.

Heres a new theme and header image, what do you think?

Stack Overflow Beta

By Sam, on Friday, 22 Aug 2008 at 5:08 p.m.

For those of you who dont follow Jeff Atwoods blog, he and Joel Spoolsky are creating a question and answer site for programmers called Stack Overflow.

Its in late beta now, and its great, to make it more than just your basic Q&A site theres a reputation score (based on how many people have up-voted your questions/answers) and badges, which were inspired by Xbox Online. The community is also top-notch.

[Continued...]

SB Audigy SE OEM Drivers

By Sam, on Thursday, 21 Aug 2008 at 12:29 a.m.

I have a Sound Blaster Audigy SE 7.1 (Part number SB0570), which is an OEM part i picked up from Ebuyer on the cheap.

The only problem with OEM parts and creative is that they dont support them (not even the drivers!), so here they are for anyone who needs them.

Audigy SE Drivers.rar [7.45MB]
Audigy SE Drivers.zip [8.75MB]

[Continued...]

SSH Passwordless Login

By Sam, on Saturday, 2 Aug 2008 at 12:45 a.m.

Here is a script that adds your SSH public key to a remote hosts authorized_keys file. Thus enabling you to login without a password.

[Continued...]

New Webhost!

By Sam, on Wednesday, 30 Jul 2008 at 7:06 p.m.

Moved to xenEurope

I was using a westhost VPS, and although this was fine and the support was brilliant, with the server being in Utah, USA, the latency was poor (~250ms), The server also seemed fairly loaded.

So I'm now with xenEurope, which so far is great, a proper VPS server instead of the cut-down redhat one that westhost provides (with no root access), I now have root access and so have the ability to set it up how i like :D I've have setup a Debian 5 (Lenny) server, running apache2, postfix+dovecot (mail), bind9 (dns), MySQL and webmin (web-based server administration). And all in 128Megs of ram :)

The latency for me is just 30ms, and the server is very snappy (as you may notice). But the best part is the price, at 10Euros/month its far cheaper than most UK VPS hosts while being as good.

Database (over) usage

By Sam, on Wednesday, 9 Jul 2008 at 1:23 a.m.

(Rant about drupal not django btw)
Since creating this website (in django) ive been interested in how it uses the database, dajango doesnt provide an easy way to show this on a per page basis, so instead i chose to use the log feature in MYSQL.

To enable it add log=/var/log/mysqld.log to your my.cnf file in the [mysqld] section and then restart the database.
You may not want to leave this on indefinably, as it spits out every database query (leading to a large logfile)

[Continued...]

<<< Newer Posts | Older Posts >>>