random posts about nerdy stuff

Using a BaseURL in Your Code

Each developer's system is different. When setting up a codebase for deployment in different environments, it's important to define your globals in such a way that they're easily changed to work in each environment. My local development environment uses MAMP Pro with all of my sites in a ~/Sites folder on my Mac, organized by a series of parent folders.

My site's configuration file lets me define a unique set of details based on my environment, whether it's a subfolder on my localhost, a dev site subfolder on the remote host or the live site itself. These unique values might be database connection credentials, paths to server files, or settings on whether or not to show debug output or send emails.

Here's an example of a conditional that sets some constants for when I'm working locally on my primary computer. The DOCUMENT_ROOT is the path to a secondary volume on my mac called "Data", which I know is unique for my own environment.

if($_SERVER['DOCUMENT_ROOT'] == '/Volumes/Data/Sites'){
    define('ROOTPATH', '/folder/');
    define('ROOTURL', 'http://localhost/folder/');

The code can use this snippet to determine what ROOTPATH and ROOTURL to use when it's running on my local machine. Some other developers use ABSPATH or ABSURL (ie: absolute path, etc). That ROOTPATH and ROOTURL can then be used in my code to ensure things like links, images, and other urls are all pointing to the right stuff. When building out my code, all I have to is make sure I include those values when referencing site assets, like in this example image tag:

<img src="<?=ROOTPATH?>images/logo.png" alt="My Logo" />

If I pass my codebase off to another developer, all they need to do is update the configuration file with their own environment details, paths and other settings that might be applicable. Good code setup means you can easily change something once, in just one place, and that update is reflected throughout the site.

Never assume a site path is in the root of the domain.

In the code blocks above, note that I use a ROOTPATH and a ROOTURL variable, which have different values. For any site elements like images that are pulled from the same domain as the website, I use an absolute path minus the parent domain. This way, the assets don't require looking at the full domain path to download the file, a minimal, but handy page load benefit.

CMS systems like Wordpress have something similar, though their Site URL values are hard coded in database content. This means that if you assign an image to a post, that reference to the image is a full URL, http:// and all, to the image asset. There are scripts out there that will search and replace one URL string to another, however this adds an extra step when moving a site between environments.

If you plan your code right, other developers should have an easy time setting your codebase up on any supported environment. Server paths differ per environment, so it's best to plan for the inevitable and make it easily updatable.

Virtual Machine Wallpapers

As a web designer, I have to open up multiple verisons of Windows running various web browsers and versions of each. To do this, I've found that VMWare Fusion works great. I can run most any operating system right on my Mac without needing multiple computers on my desk. To keep things tidy, I put together some consistent desktop wallpapers for each operating system that matches the OS branding colors. Most Windows primary color is blue, but they each have their own unique hue that sets them apart from the others.

VMWare Fusion Screenshot - multiple versions of Windows

If you have a similar setup, or just want some super-simple desktop wallpaper to remind you which version of Windows you're looking at, feel free to download them from the links below.

VMWare Desktop Wallpaper

All images are 1920x1080 in high quality PNG format, perfect for any VM you might want to run. Hope you find these useful.

How to Communicate via Email

Email is great. It lets you converse with other people with messages without interrupting them like a phone call or text message would. A phone call, though useful in many cases, is sort of like say "Talk to me now, I need your undivided attention", whereas an email lets you say what's on your mind allowing the recipient to get back to you at their convenience. This is especially handy when the answer you're looking for isn't something that's needed right away or particularly quick to answer.

The websites and email applications that we manage email messages in are great organizational tools. By using common subjects, they can put entire discussions into "threads" which collects everything into one place. This can be very helpful when going back to see what was said earlier in the conversation and for a record of any decisions or answers that have been given. All major email applications including web-based readers like Gmail support message threads.

Only a well formatted email message will find itself organized into an email thread.

When sending the first message and when replying, it's important to maintain that format that was started in the beginning of a discussion. If a client emails me a message with the subject "website", when I reply, it'll go directly into their thread with the subject "Re: website". If I were to reply and change the subject, or write a NEW message altogether, it will no longer be part of that discussion thread. It takes an extra step to get things disorganized like this, but I see it more often than I should.

When writing an email, it's up to the sender to be clear and concise with what it is you're asking. This is all based on Letter Writing 101, just because it's digital doesn't mean proper etiquette should be ignored. Give the recipient the info they need, don't assume they know what you're thinking or have them try to guess what you're trying to say. You don't know what the other person's inbox looks like, they might get hundreds of emails every day. Do what you can on your end to make sure your message is easy to find and easy to read. I personally get quite a few emails with the subject "website"... that tells me very little about what it is your asking me. Be specific with your subject, like "Request for a website redesign", or even more so: "Website redesign for". With only the subject, I know exactly what it is you're looking for.

The message itself should contain a few elements

  • Description of your question/comments
  • Specific links to, or description of what it is your question/comments are referring to
  • If you're experiencing an issue, what steps did you take when you saw the issue?
  • When finding an issue, what web browser and operating system are you using?
  • Your name and any other relevant contact info other than your email address

When you have a thorough email to send, it gives the recipient everything they need to send you the answers you're looking for. The better the initial question is, the fewer back and forth emails it takes to get the complete picture. Though there are many services for sending files to someone (see my Resource Page for links), it's helpful to tell the user what you're sending and when a series of multiple emails will be complete. For example, if you're sending a series of 5 attachments one email at a time, include in the body of the email which number of how many this particular set of attachments this message might be, ie: "2 of 5".

Tips on what NOT to do... EVER

  • Send an email with ONLY a subject
  • Email someone a "Did you get my email?" email
  • Attach something to an email without any note on what it is or what it's for
  • Send a series of single-question emails in a succession

With clear and concise emails, your recipient can have all the info they need to quickly get back to you, and keeps everyone's inbox neat and tidy.