Windows 8 and the Hosts File

Whilst setting up my new development environment in Windows 8 I ran into a little annoyance. I needed to edit my ‘hosts’ file to make local ‘.dev’ domain names. Generally, I would do this in Notepad++ (like everything else not PHP, HTML, JS, etc) but for some reason it won’t do it. So I end up using Notepad.

Using Notepad is annoying enough, but that isn’t what I am writing about. When opening the ‘hosts’ file in Notepad it wouldn’t let me save. Citing something about inadequate permissions. Apparently, you have to run Notepad in “Administrator Mode.” This is a pain in the ass because you can’t just go to Explorer, find the file, and do an “Open with…” command. You have to actually go to the sometimes handy, oft times infuriating Start Screen, find the Notepad tile, right-click it and chose “Run as administrator” option, and then find the file via Notepad’s “File > Open…” prompt. I edit the ‘hosts’ file quite a bit as I am constantly working on new projects, so this just wasn’t cutting it. After a bit of research I stumbled across Viper007Bond’s blogpost Editting Your Hosts File in Windows. This post show’s you how to create a shortcut that runs as administrator by default.

This is a simple thing to do and frankly I am embarrassed for not knowing it off-hand. Here is the fix:

  1. Open Explorer to the place that you want to put your shortcut (I like to put it in ‘C:\wamp\’)
  2. Right click an empty spot in Explorer to get the contextual menu and choose “New > Shortcut”
  3. Put the following in the textbox below the “Type the location of the item” label:
    %windir%\system32\notepad.exe %windir%\system32\drivers\etc\hosts"
  4. Give the shortcut an appropriate name (i.e. “hosts”)
  5. Click the “Finish” button
  6. Now right click the newly created shortcut to view its contextual menu and click “Properties”
  7. Choose the “Advanced…” button
  8. Check the box labeled “Run as administrator”
  9. Click OK twice

Now when you open this shortcut you will be able to edit ‘hosts’ without hassle.

P.S.

This could be easily converted to a Start Screen tile if that is your thing.

facebooktwittergoogle_plusredditpinterestlinkedinmail

Getting a “403 Forbidden” on Windows 8 with WampServer

Recently, I bought a Windows 8 machine. When I was setting up my development environment I realized that opening up my browser and pointing to ‘localhost’ was returning a ’403 Forbidden’ error.

This is how I fixed it:

  • Open the “httpd.conf” file. (C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf)
  • Find the line with the following text:
    Listen 80
  • And change it to:
    Listen 0.0.0.0:80

 

facebooktwittergoogle_plusredditpinterestlinkedinmail

Setting Primary Group for a Linux User

Many web developers work within developer groups in the LAMP development environment. As such, we would like to be able to set our Linux user accounts to create files and directories with the appropriate group attributes. Coming from a fresh install a user named ‘foo’ will likely create files with the following attributes:

foo@svr:~$ touch test1
foo@svr:~$ ls -l
-rw-r--r-- 1 foo foo 0 Feb 6 18:04 test

Notice that by default the file was created with the user’s personal group ‘foo’. However the user is a part of a group ‘bar’ and is sick of changing the group attributes of their artifacts. The following command does the trick:

foo@svr:~$ usermod -g bar foo

Now the same test yields the following results:

foo@svr:~$ touch test
foo@svr:~$ ls -l
-rw-r--r-- 1 foo bar 0 Feb 6 18:04 test
facebooktwittergoogle_plusredditpinterestlinkedinmail

Setting Default Permissions for Linux User

Many web developers work within developer groups in the LAMP development environment. As such, we would like to be able to set our Linux user accounts to create files and directories with the appropriate file permissions for groups. Coming from a fresh install a user named ‘foo’ will likely create files with the following permissions:

foo@svr:~$ touch test
foo@svr:~$ ls -l test
-rw-r--r-- 1 foo bar 0 Feb 6 18:04 test

And directories with the following permissions:

foo@svr:~$ mkdir testdir
foo@svr:~$ ls -l testdir
drwxr-xr-x 1 foo bar 0 Feb 6 18:04 testdir

By default the user creates files with permissions of 644 and directories of 755. This isn’t conducive to group work. What would be conducive would be file permissions of 664 and directory permissions of 775, giving group the same rights as the owner. In order to change this permanently a user has to change their global umask value. In order to do that the user has to edit their ~/.bashrc file:

nano ~/.bashrc

And append the following to the bottom of the file:

umask 002

Now the same test yields the following results for files:

foo@svr:~$ touch test
foo@svr:~$ ls -l test
-rw-rw-r-- 1 foo bar 0 Feb 6 18:04 test

And directories:

foo@svr:~$ mkdir testdir
foo@svr:~$ ls -l testdir
drwxrwxr-x 1 foo bar 0 Feb 6 18:04 testdir
facebooktwittergoogle_plusredditpinterestlinkedinmail

GitHub Public Repository

At the behest of one of my readers, I have created a GitHub page and some repositories for the code that I produce. Feel free to check it out at http://wescrow.github.com/. I’ll be working to build up my collection.

facebooktwittergoogle_plusredditpinterestlinkedinmail

Setting Git Config User Values

Before you go crazy making all kinds of commits on your first git repo, it’s a good idea to set your user values for git.

There are two that you need to worry about. They are your name and your email address. Setting these values will allow you to see clearly who made commits (and I guess how to contact them). This is especially important if you are working on a dev team and you need to keep track of who has done what.

Here are the commands that you need to run:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
facebooktwittergoogle_plusredditpinterestlinkedinmail

What is Git?

Have you ever worked in a large scale institution that pushes massive amounts of data onto the web? Have you ever spent hours writing implementation plans for moving code from dev to production? Have you ever saved a file over someone else’s work losing it forever? What about straight screw-ups? Ever make one that you wish desperately you could reverse?

That and many other reasons all lead you to wonder if there is a better way of managing your workflow. If you’ve coded for any length of time you know that there is an answer: the Version Control System (VCS).

Git is one of these VCSs. In fact, it’s a fairly popular one around many PHP water coolers.

What it does

Git does a lot of cool stuff. Here are the main benefits as I see them:

  • Platform independent – OK. I don’t know if it is technically platform independent but it does have a version for each of the major OSs.
  • Easy – Git is pretty intuitive. If you’ve ever worked with a command line interface in the past it should be cake to pick up. If not, there are several GUIs that you can utilize.
  • Fast web app deployment – Git is super light-weight (tracks only the changes you make) so while the initial pull might be hefty, all of the subsequent pulls and pushes are lightning fast.
  • Conflict resolution – Git doesn’t lock files out when other developers are using them like some VCSs. It does however have a pretty great conflict detection and resolution system that shows you the files in conflict and where they conflict. This allows you to make intelligent decisions and mend any conflicts.
  • Rollback – Oh shit! I can’t believe I just did that! OMG I just brought down the site! Ha. Don’t fret. Git allows you to roll back to the last commit. It’s an easy process, one command, and it is quick enough that maybe no one noticed.
  • Commit log – Git is built in with a commit log. Who was it that worked on that analytics widget on the IT splash page? Ask the git log… it will know!

Who uses git?

Several big name players use git. Check out a few that should impress:

Wanna know more?

Check out the following resources:

facebooktwittergoogle_plusredditpinterestlinkedinmail

New Sycamore Run Site

Check out my newest site (It’s actually about two months old now)! I designed this site for my kid’s early childhood center. Its nice to be able to add this site to my portfolio, but more than that this place is a great community and I am glad to be able to support it.

 

facebooktwittergoogle_plusredditpinterestlinkedinmail

New DevOrganic.com Site Launch

Devorganic.com

I finally got around to reconstructing the DevOrganic.com website. I’ve been meaning to do this for a while. Fortunately or not, an upcoming site launch and a back injury gave me lots of time to work out the kinks (coming up with a design is a kink right?).

So check it out. Take it for a spin. Notice not only the pretty paint job but the chassis as well. This site was designed to be responsive. So go to the page and resize your browser to see how the interface changes and dances around.

Hope you enjoy!

facebooktwittergoogle_plusredditpinterestlinkedinmail

CodeIgniter 2.1.0 – To Template or not to Template?

A friend of mine and I were IMing the other day when the topic of the CodeIgniter Template Parsing library came up. He had come up with a core extension that made the library a little more appealing.

OK. At this point I have to admit I have never even thought about using the Template Parsing library until this point. Even though I have been using CI for over 2 years now, there are still libraries that I helpers and now drivers that I haven’t delved into. CI is a pretty lightweight and powerful framework with great doc. There is really no good reason why I haven’t fully explored its power except to say that I am a bit lazy and haven’t really found a need to.

So anyway, on with the story.

I started exploring this library a bit. After exploring the doc, I couldn’t imagine why I would want to implement this. But I wanted to be able to discuss it intelligently so I set out to do just that.

So here are some notes I took represented as a pros/cons list:

Pros:

  • Separation: Previously I was keeping all of my template views in a subdirectory of the views folder. This allowed me to move my template views out into their own space.
  • Packaging: I have always included a “theme” config value that allowed me to change the theme on the fly. However, up until this point I have never been able to really package all theme files together. Moving the template views out allowed me to put all of my template related css, js, images, fonts, views, etc together in a theme directory.

 Cons:

  • No Pros for Actual Template Parser: The above pros aren’t actually for the Template Parsing library. They are for the extensions of the core files and hooks that I’ll talk about next.
  • Extending the Core: In order to get this to work the way we wanted it to (views outside of the main CI view directory) we had to extend the MY_Loader.php class to add view paths to the CI array. I’ll attach my version of the code below.
  • Enabling Hooks: I wanted to still be able to call a default theme from the config file. I also didn’t want to have to load it in every controller. So what I wanted to do was pull the config value and load it in the MY_Loader.php constructor. Unfortunately, the config values haven’t been loaded at the time of the class construction. So the only way to easily load the default theme was to create a load function and call if from a hook, something I’ve never had to do before.
  • Template Parsing is Stupid: Sorry. Had to say what everyone was thinking. It is slower. It is just as ugly. And it is added complexity. I can’t think of one reason to use it.

The Result

I guess it’s up to you. I actually think I’ll keep the core hack and hook to pull out the templates, but there is no way I’m using the Template Parsing library.

Code to Make it Work:

MY_Loader.php

<!--?php </p-->

class MY_Loader extends CI_Loader
{

public function set_default_theme()
{
$this-&gt;_ci_view_paths[FCPATH . 'theme/'.config_item('theme').'/'] = TRUE;
}

public function theme($strTheme)
{
$this-&gt;_ci_view_paths[FCPATH . 'theme/'.$strTheme.'/'] = TRUE;
}
}

post_controller_constructor.php

<!--?php </p-->

class post_controller_constructor
{
public function __construct()
{
log_message('debug', 'Hook \'post_controller_constructor\' Class Initialized');
}

public function set_default_theme()
{
$ci =&amp; get_instance();
$ci-&gt;load-&gt;set_default_theme();
log_message('debug', 'Default Theme \''.config_item('theme').'\' Enabled');
}
}
facebooktwittergoogle_plusredditpinterestlinkedinmail