We are a Factory!

Years ago I worked at a digital agency were an all company meeting was organised to rally the troops. The CEO took the stage and the first words out of his mouth were:

“We are a factory!”

I understand why CEO’s an other management types like to think of their organisation as a factory. When you think of a factory you think of things like streamlined processes and efficiency and CEO’s like their organisations to be like that.

However, not all organisations are factories. A factory is a very different environment compared to a creative environment. The way I see a factory is as large collection of simple tasks were as a creative environment is typically a small collection of complex tasks.

Factories are usually limited to producing the exact same thing over and over again with only predefined variations. E.g. the assembly line in a Toyota car factory can only produce the same model car over and over again until they physically reconfigure the assembly line to produce something different. Going to a Toyota car factory and asking them to build you a Ferrari is going to be futile, they can’t do it. Because factories produce the exact same thing over and over they can really break down the production process and heavily optimise and streamline it.

A creative environment is the complete opposite of that of a factory. In a creative environment problems are solved. A typical creative environment is a group of smart people solving difficult problems. Different problems might have commonalities but they will never be exactly the same. If you’re a software developer, graphics designer, architect or lawyer, the work you do and the problems you solve all share a common ground but they are unique each and every time and they all require their own unique solution and approach.

Applying Henry Ford style management in a creative organisation is asking for trouble. If you are in charge of a creative organisation where people expect to work autonomously and you start to micro manage them you will create friction and that will be catastrophic in a creative organisation. When a creative environment has a low retention rate then this is usually because of the management style applied in that environment.

We’re not a factory!

Posted in Opinion | Comments closed

WordPress Database Connection Error

The other day I ran into a problem with one of my clients websites that was throwing the Nemesis error for all WordPress developers:

Error establishing a database connection.

Not a very nice error to present to your users.

I was wondering if it was possible to change this message to something more meaningful, or at least, more user friendly. So I came up with the following message instead:

This website is currently experiencing some heavy traffic and is unable to fulfill your request.

The website administrators are working hard at the moment to allocate extra resources.

We appreciate your patience.

The idea is not to present the user with some technicality but to turn the error message into something slightly more positive. If a website is receiving “heavy traffic” then it must be in high demand right? This means that many people want what’s on this website. So even though the website is returning an error it’s not because it’s broken but because the demand is so high, which sort of makes it OK…

Of course, in reality there is a problem with the website that needs to be fixed but I think that presenting a message with a different tone can make a huge impact on how the visitor perceives the problem.

To change the error message for your WordPress installation create a file called db-error.php located in the wp-content directory of your WordPress installation. You can simply fill it with the HTML that you want. However, be aware that at this point the template system has not been loaded yet so you can’t access any of your template resources. At first glance this might come across as an oversight on the behalf of the WordPress core developers but many templates/themes need to access the database for various bits of information such as the website title etc. So you have to make do with the static page.

Posted in Programming | Comments closed

The Bank Transfer

I’ve been running into issues with banking here in Australia. I’d like to share with you some of the ridiculous scenarios I’ve been in. So, this will be the first installment of a series called “Broken Bank”.

The Transfer

Years ago I went into the bank to transfer money. I had recently moved to Australia and I didn’t have a new credit card set up yet to pay the down-payment on a new computer I wanted to buy online. So I go into the bank and wait in line. After 10 or so minutes it was my turn and I explain to the lady at the counter that I wanted to transfer money from my bank account to this other bank account and handed her a piece of paper on which I had carefully written down all the details. She looked at it for maybe 10 or 15 seconds and then slowly started to mumble something. Then she looked up and said to me “No. We don’t do that”. I asked her, “Sorry, what do you mean?”. She said, “We don’t transfer money like this. Well, we can, but it costs $25 and takes 5 working days”. When I asked her why she couldn’t tell me but the problem turned out to be that I was banking with NAB and I wanted to transfer money to CommBank. Apparently banks in Australia are so disjointed that they can’t transfer money to each other without undertaking a herculean effort. Her suggestion to me was to do the following: “Take the money out of the ATM and bring it to a CommBank branch to deposit into the bank account”.

Now, this is a organisation of which it’s core business is transferring money…

Banks in Australia are seriously broken!

Posted in Broken Bank | Comments closed

The Future of Music: Bytebeat

If you enjoy music this might come as a shock/surprise to you but there is a new form of music out there. No, not a style but a new form. It’s called “Bytebeat” and I must say I greatly enjoy it.

My personal favourite at the moment is a track called Crowd, however, if your system doesn’t play OGG’s out of the box there are some other samples on SoundCloud:

But what exactly is Bytebeat? This form a music is not created by instruments in the traditional sense. The music you hear is actually created by a formula. This is the formula for the track Crowd:

((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7

Pretty nifty. This tiny formula creates a little over 8 and a half minutes of music.

It sounds a bit rudimentary at the moment but I guess this form of music is still very much in the hands of engineers. Maybe you can compare it with the first piano or organ, I’m sure it wasn’t created by a musician but an engineer instead. It would be interesting to see how this is going to sound in the future when musicians get their heads around this.

There seems to be an iOS application that will let you create this type of music called GlitchMachine. If you’re on iOS you might want to give it a try.

If you want to read more: http://canonical.org/~kragen/bytebeat

Posted in Stuff | Comments closed

Asynchronous Auto-Complete Input Fields with Bootstrap

Bootstrap is a great HTML framework and I’ve been using it a lot lately for most of my projects.

The other day I needed to add asynchronous auto-complete functionality to an input field and Bootstrap seems to offer type ahead functionality out of the box. However, from the documentation it wasn’t instantly clear on how to implement this with an asynchronous ajax call to retrieve the data.

It turns out to be pretty straight forward:

1
2
3
4
5
6
7
8
9
10
$('#myinput').typeahead( {
  source: function( query, process ) {
    $.post("/get-data", {
      query: query
    },
    function( data ) {
      process(data);
    } );
  },
} );

Besides including the bootstrap.js file into your page, you also need to include bootstrap-typeahead.js to add the auto-complete functionality.

Your server script needs to return a single JSON array with the entries you want to appear in the drop-down list. Also note, for Chrome I noticed I had to add the autocomplete="off" parameter to my input tag to prevent it from displaying the built-in browser auto-complete drop-down.

This was tested with Bootstrap v2.2.2

Posted in Programming | Comments closed

The Scale of Perfection

A great thinker once said:

Time is money.

When you start writing code for a living you’ll soon find out how true this statement actually is and unless you have a client who’s after perfection and willing to pay you by the hour for achieving it, you better be damn sure that your estimates are right.

I run a small web development business and in my line of work making accurate estimates is probably the most difficult part about my job. In essence, making estimates is a catch 22. The more time I invest in making an estimate, the more accurate that estimate will be, however, I do not get paid to make estimates. I.e, most of my clients will not pay me for making accurate estimates. This leaves me with the only viable option I have: to guess.

Of course, a guessed estimate isn’t just a random number picked out of thin air. It’s based on years and years of experience. What the good ‘ol gut is telling me.

One important aspect of experience is that when experience increases, the quality of the work also increases accordingly. This means that at some point it becomes difficult to do a mediocre job. Your experience has a direct effect on the quality of the work you deliver. E.g. young and inexperienced programmers are often not so much aware of all the things that can go wrong with the code they write. They mostly focus on the path of least resistance without realising the various “edge cases” such as stuff that could break or external dependencies that can stop working.

So, we can say that experience has a direct effect on the quality of work you deliver and therefore experience also has a direct effect on the estimates you make. In other words, someone with more experience will make different estimates than someone with less experience. Sounds reasonable, right?

Most of my clients intuitively think that because someone has more experience they will work more efficient and that therefore the estimates should be lower. However, this is a fallacy. We all know that delivering high quality work takes more time. I.e. craftsmanship.

So, what does this have to do with the Scale of Perfection? Let’s look at a simple graph:

This graph tries to demonstrate that the Perceived Quality decreases even though the Effort continues.

It’s often very difficult to explain to my clients why a certain job takes a certain amount of time and therefore has a certain associated cost. At the start of a project the Perceived Quality increases rapidly because you go from nothing to something in a short space of time.

Clients like this. They can see progress. However, when work moves behind the scenes and aren’t directly visible to the end user it becomes more difficult for my clients to evaluate progress and justify the cost. To them it might seem that nothing has happened for a week because they don’t “see” any difference and probably ask themselves; “What’s this guy doing, what I’m I paying him for?”. This is what I mean with Perceived Quality.

Note that the Perceived Quality is not the same as the Actual Quality. While the Effort continues, the Actual Quality keeps increasing. E.g. does your client see the value in implementing solid error handling? They might not at first until something goes wrong and when it does they will come back to you and ask you why it’s not working. You might rightfully say that this should be defined in a scope of work or a requirements document. This true. However, my clients are usually not in the business of software. They simply want a website or application that works and a scope or work and requirements document is usually not something they have a direct interest in.

Let’s look at another graph:

In the graph above, the red dot represents an unfinished product. The green dot represents a mediocre but supposedly finished product and the blue dot represents a finished product with a solid layer of polish.

Inexperienced developers will be happy to call a project finished at the green dot. The work is perceived to be finished and all functionality appears to be working. However, after a week or two orders have stopped coming in. After investigation the seems that there was a problem sending out emails because the hosting company changed something in the configuration of the web server. It was only because the client stopped receiving order emails and tried to submit a dummy order that he noticed the order wasn’t arriving. The inexperienced developer didn’t built in any error handling when sending out an email. When emails couldn’t be send out, the error message simply disappeared into the void. It’s unknown how many orders the client lost and what revenue the client missed out on.

The inexperienced developer simply wasn’t aware of things that could go wrong and didn’t cater for it. He certainly didn’t make developing error handling part of his estimate and was therefore cheaper when the client received his quote for the costs of the project.

Would this client have been better of in hiring a more experienced developer? A developer that would have taken notice of the things that could go wrong? A developer that probably would have been more expensive? The client would definitely have received a different estimate and very likely had to pay more to have his website build by a more experienced developer. However, the likelihood that this client would have had problems with his website would definitely have been less and the chance on losing out on revenue very slim.

Perceived Quality is a real thing and unfortunately it’s not always easy to explain why something is of better quality because it appears to “just” work. We only kick and scream at things when they’re broken and don’t coincide with our expectations. The Scale of Perfection is very much part of making correct estimates and being aware of it might make you look at you own estimates in a different way.

Posted in Business, Management, Productivity | Comments closed

Prometheus

I watched Prometheus again over the weekend. Actually, I didn’t. I only watched half. I had to stop half way through because it was so boring and cliché.

If you’re a lover of Sci-Fi, like me, then you’re probably just as disappointed after seeing Prometheus as I was. The first Alien movie released in 1979 is probably THE best Sci-Fi movie ever made. Difficult to top, even by the guy who made it.

Maybe my expectations of Prometheus were to high but then again, Ridley Scott did give us Alien, Blade Runner and Gladiator (OK, that last one is not Sci-Fi and already a bit Hollywood-esque but still a good movie). For those of you who didn’t know, he’s also responsible for the original 1984 Apple Mac commercial. Not a bad portfolio.

The premise of Prometheus is interesting. An Alien species seeds humanity through their own DNA. Somehow ancient human civilizations create star maps of the planetary system their makers originated from. Archaeologists are send to this planet system to investigate and that’s where the movie begins.

One of the cool things about the original Alien movie is where they enter the crashed alien space craft and they find the fossilised body of an alien species. The body seems to be seated in some sort of device, a telescope of some sort, and it’s clear that the chest of the creature has burst open. The original Alien movie doesn’t go into what this creature is or was, they’re to busy fighting for their lives I guess.

Prometheus picks up on this part of the story and I was hoping that they’d done something really interesting with this but they didn’t. Instead it seems like the movie has ended up as a compromise between a bunch of Hollywood studio execs who want a movie for an as broad as possible audience and the faded talent of a once brilliant film director/producer.

Prometheus has ended up as a boring and predicable 2 hour brainless Hollywood action flick. The moment characters are introduced you know who’s going die. It’s like watching an episode of Star Trek where there is suddenly a crew member added to the away team who you’ve never seen before. You know he’s going to die. Watching Prometheus is exactly like that.

It would have been so great if Prometheus had been a lot more scientific. I was actually thinking what it would have been like if Prometheus would have been shot as a fake documentary. I think that would have been very interesting, not only to watch but also for the fan base that has been established over the 30 odd years since Alien was released. It would also have been a great opportunity to give a new spin on the genre of Sci-Fi. We live in an age where everyone is much more in touch with technology and science. To me, Prometheus is a wasted opportunity to do something new and exciting.

Anyhow, I believe they’re working on a squeal to the prequel. I won’t hold my breath. I’m sure it’s going to be another blend Hollywood monstrosity. One can only hope I guess…

Posted in Opinion | Comments closed

Galaxy Nexus Review

I’ve had my Galaxy Nexus for about a month now and I thought I would be nice to write up a little post regarding my experiences with the device.

This is my first “modern” mobile phone. The previous mobile phone I bought was a Nokia 3660 and I’m pretty sure that was in 2004. That makes it a whopping 8 years between devices, going from a Symbian Series 60 to the latest state of the art Android Ice Cream Sandwich device. I was expecting a rough transition..

I’ve never really been much of a mobile phone person. In fact, I don’t really like phones in general. I tend not to carry around my phone as you would expect from any other “normal” person these days. If you look at my 8 year old Nokia 3660, you’ll notice it’s in pretty good condition. In fact, it almost looks brand new. It’s because it’s been mostly lying on my desk for the better part of it’s existence.

I bought my Galaxy Nexus from eBay for $450 AUD, including shipping. That’s a pretty good price and it definitely helped in my decision to buy it. An iPhone is at least $200 AUD more expensive and I was actually considering buying one.

I had been contemplating buying a new mobile phone ever since the Google Nexus phone was released. But since I don’t use mobile phones that much, so purchasing it or any of it’s successors never really became a priority. When the Galaxy Nexus was released together with a major update of the Android OS I figured it must be a good time to jump on the touch screen band wagon and get myself one of these modern slabs. To be honest, the decision between buying an iPhone and the Galaxy Nexus was divided up between 40% (iPhone) to 60% (Latest Android). I’ve never been a fan of Apple and it’s products but I must say, I’m impressed by the iPhone. However, in the end I succumbed to my hacker instinct and ordered the Galaxy Nexus.

The verdict

Now, at this point it might be good to point out the verdict instead of going through a detailed discussion of my findings and end with a conclusion. When it comes to the verdict I must say, I’m disappointed in the Galaxy Nexus. There are two main reasons for this disappointment, 1) The on-board software and 2) The device responsiveness. It might be that these things are intertwined though. Even-though there are some great things about this device (the display!) I will only focus on the negative here since it had such a great impact on my experience with the device. The bad outweigh the good.

The Galaxy Nexus is the latest of the Android OS incarnations (Ice Cream Sandwich) and the device comes loaded up with a number of programs (or “apps” as the kids these days call ‘m). Since it’s produced as a collaboration between Samsung & Google you’d expect all the pre-installed software to be of good, if not, top quality. However, this is not the case. Most of the software that comes with a Galaxy Nexus out-of-the-box, is well, kinda crappy.

The first thing I noticed when I started playing around with the device was the clock. I don’t like analog clocks. They don’t make sense to me and don’t tell me time accurately enough in the blink of an eye. I prefer a digital clocks with good ‘ol numbers. The Galaxy Nexus has a great digital clock on-board, but this clock is a separate app which means you can’t set it on your desktop (or what ever the hell they call it these days). You need to explicitly open it and when you do, it looks great. Yes, there’s the time in digital format in the top right corner of the screen but then why include a clock widget in the first place? My other gripe with the default clock is that you can only set an alarm up to 24 hours into the future. WTF? Say it’s Monday today and I want to set an alarm for Friday. Can’t do. How stupid is that? This is 1.2Ghz dual core device and I can’t do something as simple as setting an alarm a few days in the future. Not a good start.

When I started playing with the camera I noticed something quite disturbing. Whenever I pressed the button to take a photo it takes more then 1 second for the camera to actually take the picture. So, I decided I wanted to take a cute photo of my dog. I point the camera at the dog and pressed the button. Low and behold, I got a blurry shot. When I pressed the button, a fraction later the dog moved it’s head. Dogs have a tendency not to sit still for long and a 2 second pose is just not doable. It basically makes the camera useless. Out in the wild all you get is blurry shots, unless the rest of the world is willing to stand still and pose for you while you try to take your picture.

I have an old digital photo camera (also Samsung). I think it’s about 5 years old and is 5 mega-pixel camera. Turns out the that camera on the Galaxy Nexus is also 5 mega-pixel. I was slightly disappointed since you can really see the low quality of the photos, especially on the awesome display. I must admit, I’m not digital camera expert. Far from it. But isn’t 5 mega-pixel rather, old? It was another disappointment.

I like maps. So one of the first “apps” I tried was Google Maps and Google Earth. It’s cool how you can rotate the map and align it to how you’re looking at the world and with geo-location enabled you can quickly get an idea of where you are. One thing I quickly noticed though; Turning the map (having your index finger steady on the map and rotating it with your middle finger) doesn’t work very well. It seems the application is busy doing something else in the background (loading stuff?) and it becomes quite frustrating when it’s not responding. It often takes more than 5 seconds or more before it’s catching up with you. I ended up screaming at Google Maps and Google Earth a lot and I basically stopped using it.

When I navigate the device I hold in my left hand and navigate it with my right (index finger). Holding it my right hand an navigating it with my thumb doesn’t really seem to work me. It feels like it’s about to slip out of my palm onto the floor. Also, navigating it with my thumb gives me almost instant RSI. I don’t have small hands but the device is quite chunky so for me two hand handling seems to be the best way. I did notice, and I don’t think this has anything to do with the Galaxy Nexus, when I hold the device in my left hand and navigate it with my right, after some time I notice that my right hand has turned into a claw, almost frozen. When I become aware of it and I stretch my fingers, all my fingers seem to hurt slightly. Anyway, I hold the device in my left and I’m not sure about the design decisions here, but the buttons seem to be awkwardly placed. My left thumb sits above the volume and my index finger sits on the power button. When I need to adjust the volume it means I have to physically slide the entire device up so my thumb can access the volume. By doing this, the balance of the device become awkward. It doesn’t tip over and fall out of my hand, but it’s intrusive enough to be annoying. My index finger on the power button is useless since I’m not going to need it. Also, when you watch a video and you tilt the device horizontal, the volume seems to be reversed. Pressing left is louder and on screen the volume moves right. I understand why, but I think it would have been better to have the volume being visualised vertically instead of horizontally.

So, overall. I’m disappointed with the Galaxy Nexus experience. The things I list here are just those I remembered from the top of my head. I know there are some great things about this device but I was expecting more. Hopefully most of the software issues (especially the responsiveness) will be sorted in the near future through software updates. I will keep using the Galaxy Nexus and hopefully I find some work arounds for my problems. However, I don’t think it’s going to be another 8 years before I buy my next mobile phone.

Now, where did I put those iPhone brochures…?

Posted in Opinion | Tagged , | Comments closed

Telstra, really?

I was browsing Telstra’s online shop today. This is what I was presented with, each time I loaded another page:

Really? What has the operating system got to do with anything? I run a perfectly fine version of Chrome, albeit on Ubuntu Linux. Should that really matter? It’s not 1998! C’mon guys!

Posted in Opinion | Comments closed

Silos and Bands

Some background first; Over the years I’ve worked in few, what you’d call, digital agencies. These are essentially advertising agencies working online. They work with their clients to mainly create banner ads, Facebook Apps & Pages and product specific micro-sites. The holy grail in these agencies is “the viral” campaign.

In these digital agencies there often are few key skill-sets that are intrinsic to the work. These are (broadly speaking); Designers, Developers & Producers. In smaller digital agencies there is usually, next to the Managing Director (MD) who works on the business end, a Creative Director (CD) who manages the production team. In the larger agencies, next to the Creative Director, there usually is also an Executive Producer and a Technical Director.

This is all good of course. Work comes in. Work gets done. Everyone works hard. Everyone plays hard. Agencies grow. People get hired and teams expand.

There seems to be tendency however, that when agencies grow, that silos are created. Designers sit over here. Developers sit over there. Producers sit on another floor, etc. Result; over time, communication breaks down.

When you put a bunch of developers together they want to do development stuff. They want to use software development processes and version control systems because on the Internet they are talking about how important that is. Which it is.

The designers can’t be bothered with any of this. They just want access to a big network drive where they can park their 500Mb Photoshop files.

The producers sort of see the value in having a process but don’t really know where to start with all this. They have the will but lack the savviness of the developers about the details; “A bug tracking system? That sounds good. Set it up!” and then they never use it.

Silos create division.

When you play music in a band you’re not only learning how to play music with other people, you’re learning how to play music with the same group of people. Practice is very important here. Making music with other people can be a bit daunting at times and can cause some friction. Tastes differ and not every bass player plays well with every drummer. A team needs to “click”. It would be easier not to practice playing together and just practice individually. When you finally scored that gig you jump up on stage and tear the walls down, right? I don’t think so..

Just like you learned how to play your instrument (learned to write code, learned how to design, learned your skill) you need to learn how to play in the band, the team, learn to work with other people. If you only play with a bunch of other guitarists you never learn anything about the drums or how to work together with the drums, let alone the singer.

Bands promote communication.

So, rather than having the developers sit over here and designers sit over there, wouldn’t it be better to create a band? Putting together a designer, a developer and a producer. From that point on those people always work together on projects. Over time they learn each others needs and therefore need less communication and less formal process. Each band can work slightly different because people are individuals with individual tastes, and that’s OK. In a band people can work better because they have a deeper understanding of their team mates needs which means they can work faster and produce higher quality work.

Now go start your own band!

Posted in Management, Productivity | Comments closed

WordPress Pagination

A while ago, while looking for inspiration regarding pagination in WordPress, I came across a post by Steve Taylor.

The function he presented in his post was easy to use and to the point. However, after closer inspection I noticed that a few things about it that could use some improvement.

The first thing I noticed about Steve’s function was that it would create an unlimited number of pages. E.g. If you would have 1000 posts and be displaying 10 posts per page, Steve’s function would create links for 100 pages. I definitely needed to limit this. To remedy this I introduced a $page_range parameter with a default value of 3. So, in the case of the 100 pages the user would only be presented with a range of 3 pages at a time, the first range would be page 1 to 3, the second range page 4 to 6 etc.

The second thing I noticed was the $baseURL parameter on Steve’s function. The way Steve was generating the page URL’s was a bit crude. I replaced this with some internal functions WordPress makes available which eliminated the need for a $baseURL parameter altogether.

The only thing I haven’t changed about Steve’s function is the way HTML is outputted within the function itself. To make the function truly reusable the pagination logic and the presentation of it should definitely be separated.

Anyway, without further ado:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function pagination( $page_range = 3, $query = NULL )
{
   global $wp_query;
 
   if( empty( $query ) )
   {
      $query = $wp_query;	
   }
 
   $page = $query->query_vars["paged"];
 
   if( !$page )
   {
      $page = 1;
   }
 
   $page_start = floor( ($page - 1) / $page_range) * $page_range + 1;
   $page_end = $page_start + $page_range - 1;
 
   if( $page_end > $query->max_num_pages )
   {
      $page_end = $query->max_num_pages;
   }
 
   echo '<ol class="pagination">';
 
   if( $page > 1 )
   {
      echo '<li><a href="'.previous_posts(FALSE).'" rel="prev">Previous</a></li>';
   }
 
   for( $i = $page_start; $i <= $page_end; $i++ )
   {
      $selected = "";
 
      if( $page == $i)
      {
         $selected = " class=\"selected\"";
      }
 
      $url = get_pagenum_link( $i );
 
      echo "<li $selected><a href=\"$url\">$i</a></li>";
   }
 
   if( $page < $query->max_num_pages )
   {
      echo '<li><a href="'.next_posts($query->max_num_pages, FALSE).'" rel="next">Next</a></li>';
   }
 
   echo '</ol>';
}
Posted in Wordpress | Comments closed

Ubuntu 11.10, Unity and Gnome 3

Heaven almighty. What has happened? Unity and Gnome 3 have been forced upon us. Luckily there is salvation.

I don’t know about you but after installing Ubuntu 11.10 I nearly had a heart attack. Hello Canonical! My massive wide screen display is NOT a tablet. It’s part of a work station. There is a reason I have a massive high resolution screen. It’s because I want to display as much stuff on one screen as possible. However, these days massive 512×512 pixel icons are all the rage. Time for some tweaking.

Out of the box Gnome 3 isn’t much better but luckily we can tweak Gnome 3 to be a slightly more pleasant experience. After a fresh Ubuntu 11.10 install (with Unity), open a terminal and run the following commands:

1
sudo apt-get remove overlay-scrollbar liboverlay-scrollbar-0.2-0 liboverlay-scrollbar3-0.2-0
1
sudo apt-get install synaptic gconf-editor gnome-tweak-tool

This will install Gnome 3. Now, reboot and on the log in screen make sure that you select a “Gnome” session. You do this by clicking on the little “cog” icon in the top right corner of the log in panel next to where you type your password.

Once you’re logged in you can now start to modify your fresh Gnome session. E.g. I always have my task bar at the bottom of the screen. To move it I ALT-Right clicked the panel at the bottom of the screen and deleted it. I then ALT-Right clicked the top panel and set it’s location to the bottom. By ALT-Right clicking the elements on the panel you can either Delete or Move them. E.g. you can Move the clock to the right hand side if the middle is a bit to prominent for you. Anyhow, you can customize the panel by adding more applets to it such as a Workspace switcher. Again, ALT-Right click the panel and select “Add to Panel”.

There are still a few bugs in Gnome 3, such as the prominent Nautilus menu at the top of the screen, but hopefully this will all be worked out in due time.

Posted in Linux | Tagged , , | Comments closed

Productivity

As a programmer, how productive I am is for the greater part defined by the environment I’m working in. Over the years I’ve worked in places that really understood this and I’ve worked in places where they didn’t had a clue.

Since early 2010 I’ve been working from home. It’s the first time I’ve actually done this for such an extensive period of time, but finally I could work in peace and would no longer be interrupted by the environment that was supposed to support me.

At least, that is what I thought. Unfortunately it didn’t really worked out that way. The greatest enemy of all programmers reared it’s ugly head: Procrastination.

After months of trying to get to grips with this I finally found out what worked best for me. For me this happened to be a strict regime. This how my typical work day is divided in chunks of hours:

06:00 – 07:00 Wake up, breakfast, shower & getting dressed
07:00 – 11:00 Work
11:00 – 13:00 Break
13:00 – 17:00 Work
17:00 onwards Free time

This schedule gives me a solid 8 hours worth of work with plenty of time for a decent break in the middle AND spare time at the end of the day to do what ever I want to do. The schedule is important because it defines what hours I should be spending on work. This is good because if something random pops in my head such as “How do you do this or that with MongoDB?“, rather than to act on it with impulse and start tinkering with MongoDB I look at the clock which tells me I have another 2 hours to go, I make note of my thoughts and continue working. If after those 2 hours I’m still interested in perusing my thoughts, I will have time to do so.

Another thing that works for me, besides the schedule, is that the day before, I make a list of what I will be working on the next day. To me this is key to avoid procrastination, having a todo list where I can tick things off. It also allows me to start thinking about certain problems the day before so that by the time I sit down at the keyboard it’s mostly a matter of typing things in (mostly).

When you look at my schedule you might find the 2 hour lunch break exceptionally long but I found that I need a decent break in the middle. I can’t work 4 hours solid, shove a sandwich down my throat and then do another 4 hours. The 2 hour break might seem long but for me it gives me enough time to relax a bit, have a phone call with people I work with, respond to a few emails or go for a walk.

After having done this for a while I can see, or more likely feel, that the quality of the hours I spend working have really increased. I feel less distracted by the things around me and I have a lot more focus on the things I need to accomplish that day. Rather than spending 15 hours messing about I’ve done 8 hours of solid work instead.

Posted in Productivity | Comments closed

Backing up with CRON and rsync

Everyone makes regular backups and so do you, right?

I run an Ubuntu desktop and I have set up nightly backups. Every day at midnight my /home directory is synchronised onto a dedicated backup drive using the following rsync command:

1
nice -n19 rsync -rltDuqAog --delete --exclude='*.gvfs' /home/me/ /media/backup

As you can see. I run rsync with a nice run-level of 19. This gives rsync basically the lowest priority, which is OK.

I then use a bunch of parameters. This is what they mean:

-r Copies directories recursively.
-l Copies symlinks as symlinks.
-t Preserves modification times.
-D Preserves device and special files.
-u Skips files that are newer at the destination.
-q Quiet. Don’t output anything.
-A Preserve ACLs (implies –perms or -p).
-og Preserve Owner and Group attributes.
--delete This is important. Basically rsync synchronizes files that have been changed. But what if you delete a file from the source? This option deletes it from your target as well, keeping both file systems truly sync’ed.
--exclude='*.gvfs' Excludes a particular file or directory. I had to add this since rsync would crash on this particular directory each time I ran it.

To be on the real safe side I would of course make a backup of the backup and if I would, I could of course use the same rsync command.

For more advanced rsync tickery, check out the post Easy Automated Snapshot-Style Backups with Linux and Rsync by Mike Rubel.

Posted in System Administration | Tagged , , , | Comments closed

Configuring WordPress for multiple domains

One if the things you will run into while doing WordPress development is switching between your local development environment, the staging environment and, eventually, the production environment.

If you set up a new WordPress website and you use the out-of-the-box configuration mechanics, you will find that WordPress stores the website domain in the database. This means that whenever you e.g. generate a URL in your theme or insert an image in a post that that particular domain will be used to create the URL with. If you switch between environments this will become an issue.

Luckily there is a convenient way around this problem. In our wp-config.php we can set the WP_SITEURL and the WP_HOME constants and if we do, we’re overriding the value that is stored in the database. Once you set these constants you will also notice that you can no longer edit these values from the administration panel under Settings -> General.

Another thing you will run into when switching environments is your database details. If you run your website on shared hosting you don’t always get to choose your database name and/or database user name. This means that when you switch environments you also want to change these credentials.

What you don’t want is to manually edit your configuration each time you switch environment. How can we fix this?

Now that you have a way to programmatically set the domain for your website, it would be nice to automate things depending on which domain the website runs on. E.g, throughout the development live-cycle of our website we eventually switch between the following three domains (environments):

1
2
3
http://dev.example
http://stage.example.com
http://www.example.com

The first domain is the local development environment domain, the second the staging environment and the third one the production environment. We can configure our website in such a way that depending on either one of these domains our website runs on it picks up the correct configuration. Let’s look at some code. We start by adding the following to the beginning of wp-config.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
global $domain_config;
 
$domain_config = array(
   'default' => array(
      'db_host' => 'localhost',
      'db_charset' => 'utf8',
      'debug' => TRUE,
   ),
   'dev.example' => array(
      'siteurl' => 'http://dev.example',
      'db_user' => 'example_dev',
      'db_name' => 'example_dev',
      'db_password' => 'dbpassword',
   ),
   'stage.example.com' => array(
      'siteurl' => 'http://stage.example.com',
      'db_user' => 'example_stage',
      'db_name' => 'example_stage',
      'db_password' => 'dbpassword',
   ),
   'www.example.com' => array(
      'siteurl' => 'http://www.example.com',
      'db_user' => 'example_prod',
      'db_name' => 'example_prod',
      'db_password' => 'dbpassword',
      'debug' => FALSE,
   ),
);
 
global $config;
 
$config = (object)array_merge($domain_config['default'],
   $domain_config[ $_SERVER['HTTP_HOST'] ] );

As you can see we define a data structure that represent our three different environments. The default structure we use for either default values and/or values that aren’t set in other configurations.

When we create the $config object we basically merge the default configuration with the configuration indicated by $_SERVER['HTTP_HOST']. The $config object now holds all the configuration values for our website. We can now set all the necessary values to configure our website:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
define('WP_HOME', $config->siteurl);
define('WP_SITEURL', $config->siteurl);
 
/** The name of the database for WordPress */
define('DB_NAME', $config->db_name);
 
/** MySQL database username */
define('DB_USER', $config->db_user);
 
/** MySQL database password */
define('DB_PASSWORD', $config->db_password);
 
/** MySQL hostname */
define('DB_HOST', $config->db_host);
 
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', $config->db_charset);

Now that we have the configuration part out of the way there is still one major issue we need to address. Whenever you insert an image into a post or page, the full URL to that image is stored in the post or page data. This means that if you insert an image on your local development box and you then move your website to your staging environment, the images suddenly won’t load because it’s trying to load the image from an unreachable domain (at least for people who don’t have a local development environment set up). This means that you need a way to filter your post and page content before you output it in your theme. To the rescue; the_content filter. Add the following code to your theme’s functions.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function my_the_content_filter( $content ) 
{
   global $config;
   global $domain_config;
 
   $siteurls = array();
 
   foreach( $domain_config as $values )
   {
      $siteurls[] = $values['siteurl'];
   }
 
   $content = str_replace($siteurls, $config->siteurl, 
         $content);
 
   return $content;
}
 
add_filter( 'the_content', 'my_the_content_filter' );

The above filter will turn the hard coded URL’s which where stored in the database relative to the current website configuration. So, if you inserted an image on your local development machine and the URL stored was http://dev.example/wp-content/uploads/myimage.jpg and you’re moving to the staging environment, the outputted URL will now be translated to; http://stage.example.com/wp-content/uploads/myimage.jpg.

We’re all done. You can now safely move your website from environment to environment without going through the hassle of manually configuring it each time or content links breaking.

Posted in Wordpress | Tagged , , | Comments closed