Live Mirror

Here’s a C# program to mirror all changes in one directory with another.

I build it to let me edit a PHP web project on my development PC and have it mirrored to my development server, without any action on my part.

Its all being hosted at Google Code, go on give it a try :)
Continue reading

MySQL backed SMTP+IMAP Mail server on Debain Lenny

This is a guide for setting up a mail server with a mysql backend for users and domains using Dovecot for the IMAP Server, Postfix for the MTA and SpamAssassin for preventing spam and all with SSL client-server encryption.

I’ll also assume you have a MySQL server ready for use.
Continue reading

Smullyan’s Paradox

Here is one of the best paradoxes I’ve seen in a long time:

“At a desert oasis, A and B decide independently to murder C. A poisons C’s canteen, and later B punches a hole in it. C dies of thirst. Who killed him?

A argues that C never drank the poison. B claims that he only deprived C of poisoned water. They’re both right, but still C is dead. Who’s guilty?”

[Via Futility Closet]

Hardware vs Software Raid

Hmm.. Which is better?

I would say software raid is better*, my reasons:

  1. Software raid follows the OS around, upgrade all your hardware, your raid array will still work (In Theory)
  2. Software is easy to update, Firmware is not
  3. If your on a budget, do you really want to trust a cheap raid controller?

[*] Under most conditions, ie. without big budgets, mission critical servers etc…

See Also:
Stackoverflow Blog: Tuesday Outage: It’s RAID-tastic!
Linux: Why software RAID?

Converting Videos for the Creative Zen

I have a Creative Zen, its a very nice little mp3/video player, and while it plays xVid/DivX/WMV its a bit picky about what it will play.

So ive created this script to convert videos to a format it will play (320×240, xVid, with auto black bars to maintiain aspect ratio & 128KB ABR MP3 audio).
Its a Bash script using Mplayer / Mencoder.

Files

Lambda's and Anonymous functions in C# 3.5

Here’s a lambda function in use with the new extensions for a List object.

personnel.foreach(x => x.DoSomeCoolStuff());

Continue reading

360° Angle Class for C#

Here is a nifty class to handle an angle. it will wrap around increments and decrements that exceed 360 or 0, e.g. adding 20 to 350 will give 10 not 370 and subtracting 10 from 5 will give 355 not -5.

  • Implicit conversion to and from double
  • ToString and GetHashCode are mapped to the inner angle
  • Operators +,-,>,>=,<,<= have been implemented.
  • Mixing this class and doubles in statements works seemlessly.

Code sample:

Angle angle = 0;
double angle2 = angle + 5;
Console.WriteLine("a1:{0) a2:{1}",angle,angle2);
//Output: a1:0 a2:5

Files

Making better use of mod_deflate

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:


      AddOutputFilterByType DEFLATE text/html text/plain text/xml

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:


      AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript text/css application/rss+xml application/json

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

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:


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

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