How To Edit the Hosts File in Windows 7

I’m an Administrator on my installation of Windows 7 and had to edit the hosts file for one of my projects. I wasn’t able to make the changes though because it kept saying file was in use. I realized that I need to run notepad as the administrator and then I could make my changes!

  1. I went to the start menu, and typed in notepad.
  2. Right clicked on the notepad icon and selected Run As Administrator
  3. Clicked yes when it confirmed whether it should
  4. Navigationed to c:WindowsSystem32driversetchosts

Hope this helps!

MODx How To Properly Link To a Page

In MODx, it is always preferable to link to another page using the document id instead of using the friendly alias because sometimes MODx Evolution has a package that is appearantly capable of using the alias instead of the document id to provide a working link to another page.

The reason you shouldn’t use the alias instead of the document id is because it isn’t unheard of to have google or other search engines incorrectly access another page perhaps one that isn’t even available.

Using the document id is done in the following manner for Evolution:

>a href = "[˜77˜]"<Link to document 77>/a<

Using the document id is done in the following manner for Revolution:

>a href = "[[˜77]]"<Link to document 77>/a<

The documentation for MODx Revolution is really geat and should be used to learn additional things.

Hope this helps!

MODx Revolution – Dynamically Generating Google SiteMap XML

Google SiteMap and the other web tools provides a way for the owner or webmaster of a site to easily submit all of the pages to Google and keep track of which ones are crawled and indexed. Wikipedia provides a much more detailed description which goes beyond the scope of this post.

I didn’t want to have to manually try and figure out which links are children of other links for my own site (which again only has 5 pages anyway!) or other things like that, so I was looking for an automatic way to generate the google sitemap and then be able to provide it to google.

MODx Revolution has a plugin called GoogleSiteMap which uses a snippet called GoogleSiteMap I created a page, set the template to empty, and called the snippet directly on the page and then took the xml it created and pasted it into an xml file to submit. The XML it generates even correctly does the last modified date.

Hope this helps!

Centering a DIV Horizontally

Assuming you have a basic knowledge of css and html putting a div in the horizontal center of a containing block isn’t too difficult. I’m going to center a div with only text, but the exact same css may be used for a div containing images,inputs, etc. I’m going to assume you are using html or xhtml strict and have a div that has the following code:

<div id="toBeCentered">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat</div>

All new web designers and developers assume that the css can simply be text-align:center; , but this isn’t correct because this centers the contents of the box instead of the box itself.

#toBeCentered {

To make the div center horizontally we need to ensure we do two things:

      Set a width to the div
      Set the left & right margins to auto. Web browsers are required to give the margins equal width which will set the div exactly in the center. works width.

We must instead change the css to auto the left and right margins and must set a size to the div. Setting a size to the div

#toBeCentered {
width: 200px;
margin-left: auto;

Hope this helps!

Wayfinder in MODx Revolution

When I first tried MODx Revolution (which I did try before MODx Evolution) I found the documentation to be pretty good except about snippet syntax. The tag syntax has changed from MODx Evolution to MODx Revolution.

[Wayfinder? &startId=`0`]

has to changed to

[[Wayfinder? &startId=`0`]]

More information can now be found here for all of the tag syntax changes.

Setting Focus to 1st Text Field in jQuery

Setting focus to the 1st field in jQuery is actually really simple: there are some plugins that also can do it automatically on each reload of a form.

I usually just use the following code on any pages where there is a form.

<script type="text/javascript">
$(document).ready(function() {

Hope this helps.

MODx – Evolution – 1st Impressions

I haven’t been using MODx for very long, but I have worked with several other content management systems previously and experienced both the good and the bad with them. MODx appears to be a fairly simple MVC style content management system with a bit of a pluggable architecture. I haven’t written any plugins for MODx, but it appears that hooks are used just like WordPress does.

I have found MODx to be very easy for creating fully tableless XHTML compliant sites and creating very search engine friendly websites. Very easily, it is also possible to hide what cms is running the site by using the easily created pretty urls. (There’s just a couple of simple settings and a file renaming.)

I found the templating system to be extremely frustrating because the template is actually stored in the database instead of in the file system like done in most traditional CMS. I really find editing the templates, snippets, and larger chunks extremely frustrating to edit in the manager because of the lack of syntax highlighting, and issues with formatting.

Of course, the manager does offer the advantage of being able to edit content and site structure from pretty much anything that can access the internet and doesn’t mind some fairly heavy javascript use. MODx’s requirements for webhosting aren’t exactly hard to find either although there is a forum of reviews and suggestions.

Overall, MODx doesn’t appear to be too bad for smaller boutique websites which are a large chunk of my current business. I believe I would recommend it to fellow freelancers for smaller websites that don’t have much need for plugins or high amounts of customization.

Unobtrusive JavaScript And Why it Matters

Many more senior web developers can remember throwing tags all over the contents of websites and using tables for the presentation of content: these practices are said to be intrusive and a maintenance nightmare especially when the font colour should be pink instead of black on a header.

Unobtrusive JavaScript is another best practice for later maintenance of the site. Unobtrusive JavaScript involves removing the behaviour layer from the structure and content. Instead of having JavaScript mixed throughout the content it is either placed into an external file or placed into the head of the document.

The major advantage of the Unobtrusive JavaScript is that it can also be used for progressive enhancement and other techniques for browsers that offer advanced DOM 2 support. All JavaScript frameworks that I am aware of actively encourage Unobtrusive JavaScript as do many CMS and frameworks.

There are of course some issues with unobtrusive JavaScript because it does take more lines of script and requires discipline, and the use of good coding patterns.

PHP Object/Variable Life Time

Many junior PHP developers seem to feel that PHP objects and variables are retained between requests. In PHP4 and PHP5, no variables are retained outside of the contents of $_SESSION and other stores between requests.

Continue reading

Book Review: Code Craft

“Code Craft” (ISBN: 1-59327-119-0) was written by Pete Goodliffe. The book is relevant to all developers: code is very language agnostic. Code Craft doesn’t just cover the design of the program, but also includes quite a bit of content on the process the program goes through “in the trenches.”

The book does include some minor annoyances such as the “Good Programmers… Bad Programmers..” part which is often a large part of each chapter’s content summary. Code Craft also suffers from a visually boring layout. Unfortunately, there are also some parts where it feels like Pete has taken a lot of work from secondary sources and just sort of glued it together.

The first time, I read Code Craft I had just started my first professional programming job. Reading Code Craft really made me ensure that I started using source control management, and really started to pay attention to the process of software design which I didn’t really grasp while in school. Immediately, these first few things were noticed at that first job and got me some kudos from the more senior programmer who reviewed a lot of my initial work.

Code Craft is a larger technical book and spends a lot of time describing the process that software should go through and other softer skills than just the technical side of things. There are sections on growing code, different architectures, and even coding itself but over all there’s something for most programmers even if the main idea already appears in other books.

Although, I think the book is excellent there isn’t exactly new concepts that can’t be found in other books such as Code Complete, Refactoring, and even a bit in Design Patterns. I don’t regret spending the $30 or so on the book, because I really do feel that I learned new things, was even entertained a little bit because Pete’s humour is light and even a little funny at times. Pete’s work has definitely helped me to create more meaningful software and to act as a mentor even when I didn’t have one.

How To Post Great Freelance Gigs

I have been trolling Craigslist and Kijiji lately in hopes of finding some additional freelance work to add to my portfolio before I become a full time freelancer/consultant. Read the advertisements has proven to be a terribly frustrating experience. Advertisers need to always remember that the more details they provide will lead to a much more realistic budget and a system that better meets their needs.

Advertisements need to be as detailed and as short as possible. If the programmer is expected to modify or write plugins for an existing application or website you need to provide details on how the previous system is implemented. Ideally, you will answer all of the following questions. What programming language? What database is it using? Who is hosting it? Is there any sort of documentation? Do you have programming guidelines?

Regarding the actual project or changes to an existing project require you to answer additional questions. Is it completely new project? Who will own the work (source code, graphics, etc)? What’s the timeline? What should the application do? What is the scope of the project?

Always remember that you also get what you pay for and that if you pay minimum wage or outsource to another country (China,India, Brazil, etc) you will likely get inflexible crap that will have to be redone if your site or application goes through some sort of expansion.

Learning Drupal

For the last couple of weeks, I have began playing around with Drupal because I’m so sick of fighting proprietary CMS. The proprietary CMS suffers from the vendor updating only updating the CMS when convenient for them and this ends up holding the purchaser hostage. Overall, I know that drupal has enough of the functionality that I need in modules and the core to significantly improve the efficiency of my programming and possibly offer a large learning opportunity on software architecture.

Continue reading

Drupal + TinyMCE

I’ve just really began to try and experiment with using Drupal, modules, and really starting to customize how things work. I have really been playing with open source Content Management Systems off and on over the years because I don’t feel that depending on proprietary CMS is the right approach and definitely rolling your own is not only difficult, but extremely unnecessary. Trevor Twining wrote an excellent blog article regarding using an open source vs proprietary CMS.

While following the steps outlined in the Read Me file for the TinyMCE plugin, I wasn’t able to use it at first because of an error and eventually found the solution here. Basically, the solution is find the following line in modules/tinymce/
'#default_value' => isset($edit->rids) ? array_keys((array) $edit->rids) : NULL, and replace it with '#default_value' => isset($edit->rids) ? array_keys((array) $edit->rids) : array(),

PHP Update Finally Depreciates PHP MSSQL driver

The biggest advantage of the change is being able to better take advantage of Microsoft SQL Server features that probably made you choose to use SQL Server in the first place.Making the change wasn’t overly difficult because I took time and wrote a simple Database Access Layer.

Continue reading

Book Review:The Passionate Programmer

“The Passionate Programmer” is an excellent read and that I feel I have learned more about myself than I would have ever thought. I would never say that it is the next Code Complete or Code Craft, but it can definitely help you develop a meaningful career.

Continue reading – Web Hosting Review

Purchasing web hosting service is extremely easy; however, purchasing great web service is extremely difficult. Some of the web hosts pretty much register the domain and give you access almost immediately to some temporary space while the DNS wait period occurs.

I can’t remember how long it took for me to get access to the temporary space on 1and1, because I started hosting with them around 2003 / 2004. I have used 1and1 pretty much exclusively since purchasing my first domain name and can’t say I have a lot of complaints although there are definitely somethings I wish they did differently.

I haven’t had any issues with the actual web hosting although I do find it frustrating that things like FTP accounts are so limited. I was thinking about including hosting in my web design/development projects and allowing the company FTP access but that would limit me to 50 clients per package. An important thing to keep in mind is that if you are going to use a 1and1 database (MySQL / MS SQL) is that it is behind a firewall and you must use their web based tools.

Customer Service
The four times, I have had to deal with 1and1 I was extremely disappointed with the level of customer service. For example, there was a severe email outage for about two days and staff seemed to be indifferent to the issue. Before you go with 1and1 make sure that you know exactly what you are doing, and that you have patience because their technical support/customer service is terribly slow. The FAQs aren’t exactly great and often don’t really contain remedies to the problem: for example why is DOMDocument disabled and how do I fix the problem? Well, 1and1 doesn’t actually say at the time of this writing!

Billing Practices
I’m not exactly thrilled with having to pay for a full year’s service at a time and not getting any sort of deal for allowing them to use my money for free for like 12 months. Cancelling domains and packages is quite tricky on the billing/cancel application partly because you have to respond to an email at least once and then wait some period of time (2 months?) and make sure again that the item is actually cancelled.

Final Thoughts
1and1 was the cheapest host that I could basically find around 2003/2004 and still seems to be one of the cheapest. I wouldn’t describe the experience as great but I also wouldn’t say it was terrible. If you are price conscious, willing to learn, and have patience then your 1and1 experience will probably be similar to mine.