Dear people from the future: Here’s what I’ve figured out so far

XKCD have struck gold again in a fabulous display of satirical and mildly geeky observational humour. This is posted below, for your amusement.

XKCD - Wisdom of the ancients

All long help threads should have a sticky globally-editable post at the top saying 'DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far ...'

 

Tags: , , ,

PHP – Obtain the maximum allowed file upload size

PHP – Obtain the maximum allowed file upload size

This was actually remarkably difficult to do, in terms of the volume of code required. It uses the fact that there are 3 things which affect the size of a file which can be uploaded: upload_max_filesize, post_max_size and memory_limit. The below code is useful for providing the user with the upload limit on a file upload form.

The code also uses the PHP quirk feature whereby casting a string, which starts with digits, to int will return the int value of the first digits – e.g. (int)’123abc321′ evaluates to 123.

This may, however, be a ridiculous way to do it  and an easier way may exist. Feel free to comment if you know one.

  1. function max_upload_size() {
  2. // Multipliers to make byte values from php.ini shorthand
  3. $suffix_multipliers = array(
  4. 'K'=>1024,
  5. 'M'=>1024*1024,
  6. 'G'=>1024*1024*1024
  7. );
  8.  
  9. // Values to consider
  10. $vals = array(
  11. 'upload' => ini_get('upload_max_filesize'),
  12. 'post' => ini_get('post_max_size'),
  13. 'mem' => ini_get('memory_limit')
  14. );
  15.  
  16. // Convert above values to bytes based on their shorthand notation
  17. $byte_vals = array();
  18.  
  19. foreach ($vals as $name=>$val) {
  20. if ($suffix = preg_match('/[a-z]+$/i', $val, $matches)) {
  21. // "10M" cast to int is 10
  22. if (isset($suffix_multipliers[$matches[0]])) {
  23. $byte_vals[$name] = (int)$val * $suffix_multipliers[$matches[0]];
  24. }
  25. else {
  26. $byte_vals[$name] = (int)$val;
  27. }
  28. }
  29. }
  30.  
  31. // Get the key(s) of the smallest entries
  32. $smallest_keys = array_keys($byte_vals, min($byte_vals));
  33. // Get one of these
  34. $smallest_key = reset($smallest_keys);
  35.  
  36. // Return the smallest
  37. return $vals[$smallest_key];
  38. }

Cabling your house with cat5e… Geeky or essential?

Cabling your house with cat5e… Geeky or essential?

When I bought my house, I wired it with Cat5e cable for data networking. I ran 2 cables to each of the 4 main rooms – front room, back room and 2 bed rooms. This is mostly because I’m a massive geek but this has gotten me thinking… is this unnecessary geekiness or something that every house should have? Wireless networks are notoriously slow (relative to wired networks), prone to interference, and expensive to set up.

A decent SOHO ‘N’ router will set you back about £50 these days. This isn’t bank breaking and most modern laptops will come with on-board wireless as standard. But what about your other devices? My desktop PC, my main TV and my bedroom TV’s Freesat HD box aren’t wifi enabled – rather they just have a standard Ethernet port. It is undoubtedly going to become more common for every day household devices to require a connection to the Internet and the current trend seems to be that Wifi support is an optional extra – which comes at cost.

It is said that you can run a length of decent Cat5e cable for 100m before experiencing noticeable signal deterioration. This can be run through walls, ceilings, gardens and constructions which act as Faraday Cages. Wifi, on the other hand, requires boosters, range extenders and high amplification antennas to cover large distances or overcome signal inhibiting obstacles.

A wired network is always going to be faster, more reliable and seemingly better supported by today’s network enabled devices. I’m not disagreeing that wifi has a place – its convenience for portable devices far outweighs its drawbacks but behind every good wireless network is a hard wired backbone. You can install a bunch of cheap wireless access points around your house – each attached to wall ports on your hard wired network.

So, what about the installation? I had the benefit of starting with a blank canvas of a house in which I could rip up floorboards and knock holes in walls. I’ve seen networking done in inhabited houses  but it’s more challenging and really shouldn’t be considered unless you have modern stud partition walls – mine are all solid brick. I have documented below, in picture form, my wiring. Sadly I don’t have any pictures of the installation – rather only the finished product.

First, you’ll need a real of Cat5e cable and some cabling rods. I won’t go into the differences between cables – Google will help you with that.

Cat5e cable and some cabling rods

Cat5e cable and some cabling rods

I’ve started under my stairs. This is a good location to start at because it’s where my fuse box is. Electricians are notoriously lazy and when they put the fuse box somewhere, it’s because it has good access to run cables to anywhere in the house. In here, I have put a patch panel. This is a small wall mounted patch panel which I picked up for not a lot of money from Screwfix.

12 port wall mounted patch panel

12 port wall mounted patch panel

The ports on the panel all connect into a Network switch. My switch is a Netgear GS724T managed 24 port gigabit switch. This was pretty expensive and probably overkill for most people. I only have it due to being a massive geek. You’ll likely get by on a cheaper unmanaged switch.

Netgear GS724T 24 port managed Gigabit switch

Netgear GS724T 24 port managed Gigabit switch

The patch panel has 1 cable going from it to each wall port around the house. I’ve routed these from the panel to the ceiling and under the floor through 2 cheap household drainage pipes. I’m not too concerned with the under stairs decor and thus didn’t bother to channel out walls for these.

Drainage pipes used to route cables

Drainage pipes used to route cables

The cables go up through holes in the ceiling and handily come out under the floor right at the top of the stairs.

Cables go into the ceiling

Cables go into the ceiling

You’ll see in the above photo that there’s also a TV cable going through the pipe. These cables were run at the same time. Each of the cables end up on wall plates around the house. I’ve used modular plates so I can put other things on them too, like TV ports.

Modular RJ45 wall plate

Modular RJ45 wall plate

It’s fast, it’s reliable, it was relatively cheap and was kinda entertaining to install. Give it a try!

When it comes to technology… the media is ignorant

When it comes to technology… the media is ignorant

Every now and then I see, floating around the newsstand, a technology oriented article which catches my attention. Sadly, more often than not, I breath a sign of ‘how can you be so darn ignorant’ after reading. I realize that this is the way the media works these days and that biased reporting to help achieve political goals is common place. However, when it comes to technology, one would think that ulterior motives, political or otherwise, would be non-existent.

I recall an article a few years back which told me that the Internet is full and that a “new protocol” (IPv6) has been invented to save us all. The more astute of you will know that IPv6 was in fact proposed in 1998 and is in fact not “new” at all. The newspaper was 10 years late in its reporting of this and managed to include more technical inaccuracies than your average PC World employee spouts in a day.

What prompted me to blog about this is a Daily Mail article – The REAL cost of Apple’s iPhone 4S. Firstly, don’t mistake me for an Apple fanboy. My point would stand, regardless of the product. It seems The Daily Mail are too busy cuddling up to The Tories to make time to think about what they’re writing before printing it. The premise of the argument is based solely on the iPhone 4S retailing for significantly more than its raw components cost. It seems that things such as R&D costs, software development costs, marketing costs and distribution costs have completely slipped their mind.

It’s a little saddening that public opinion is affected so much by the media and that reporting bias and ignorance is allowed to prosper.

Solved! Debian Wheezy – SASL LOGIN authentication failed: no mechanism available

Solved! Debian Wheezy – SASL LOGIN authentication failed: no mechanism available

I’m not sure why I ever run an `apt-get upgrade` on Debian as I usually spend the next week fixing the issues it’s created. Today’s problem was preventing postfix authenticating smtp users with saslauthd and thus stopping e-mail sending. The log file (/var/log/mail.err) produced the oh so helpful message “SASL LOGIN authentication failed: no mechanism available”.

Google wasn’t much use in diagnosing this as a few people had reported having the issue on Debian but no solution was available. I fixed it by downgrading 5 sasl packages to their Squeeze releases. Commands below:

  1. mkdir /tmp/saslfix
  2. cd /tmp/saslfix
  3.  
  4. wget http://ftp.us.debian.org/debian/pool/main/c/cyrus-sasl2/sasl2-bin_2.1.23.dfsg1-7_i386.deb
  5. wget http://ftp.us.debian.org/debian/pool/main/c/cyrus-sasl2/libsasl2-2_2.1.23.dfsg1-7_i386.deb
  6. wget http://ftp.us.debian.org/debian/pool/main/c/cyrus-sasl2/libsasl2-modules_2.1.23.dfsg1-7_i386.deb
  7. wget http://ftp.us.debian.org/debian/pool/main/c/cyrus-sasl2/libsasl2-modules-sql_2.1.23.dfsg1-7_i386.deb
  8. wget http://ftp.us.debian.org/debian/pool/main/c/cyrus-sasl2/libsasl2-dev_2.1.23.dfsg1-7_i386.deb
  9.  
  10. dpkg -i *.deb
  11.  
  12. /etc/init.d/saslauthd restart
  13. /etc/init.d/postfix restart