Bash aliases: create your own bash shortcuts!

When I’m building websites especially, I have to work with a lot of deeply nested files. But typing cd ~/public_html/websitename/wp-content/themes/themename/ in the terminal every time is giving me carpal tunnel, so I found a better way:

First open ~/.barshrc in a text editor and uncomment lines 73 through 75 so they look like this:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

Then create a file called .bash_aliases in your home directory (if it doesn’t already exist). Edit that file like so:

alias themename="cd ~/public_html/websitename/wp-content/themes/themename/"

Restart terminal, type in themename and press enter. Voila! Your are cd’ed all the way into that deeply nested file without having to type the whole thing. This works great for lots of other common commands that are a little too verbose:

alias ins="sudo apt-get install"

Once those lines are added to your .bash_aliases file and you restart terminal, you will be able to install new packages like so:

ins packagename

Handy eh? (That last suggestion is courtesy of the always useful Lifehacker)

Posted in Linux, Solutions, Ubuntu | Leave a comment

How to configure Apache virtual hosting in Ubuntu Karmic 9.10

Before you do anything, back up your original config files. I used to just create a copy of the files with the suffix “.bak” (sudo cp example.conf example.conf.bak), which works, but creates a lot of clutter. Now I use a great little utility called etckeeper which automatically places all files in /etc under version control using Bazaar. It also automatically performs a commit each day if you forget to. You can get etckeeper by typing this in the terminal: sudo apt-get install etckeeper.

Now on to virtual hosts. The first thing you need to do is edit /etc/hosts so your computer knows where to look for your website:

  1. In the terminal, enter: $ sudo gedit /etc/hosts
  2. In gedit, add the following line to the hosts file: 127.0.0.1 mysite.dev
    • Note: you can use whatever name you want for your virtual hosted site. I like to use the suffix .dev because it won’t conflict with sites on the actual internet.
    • Note: 127.0.0.1 is the same ip address that is assigned to localhost in that file. If yours is different, use that one.

Next add your site to /etc/apache2/sites-available/ and then link to that file in /etc/apache2/sites-enabled/:

  1. In the terminal, cd to /etc/apache2/sites-available/
  2. Create a new file with: $ sudo touch mysite.dev
  3. Open that file in gedit: $ sudo gedit mysite.dev
  4. Add following to that file:
    <VirtualHost *:80>
    ServerName mysite.dev
    ServerAlias mysite.dev
    ServerAdmin myaddress@email.com
    DocumentRoot /home/yourusername/public_html/mysite/
    </VirtualHost>

Add a pseudo link to that file in /etc/apache2/sites-enabled/:

  1. cd over to /etc/apache2/sites-enabled/
  2. In the terminal, enter: $ sudo ln -s /etc/apache2/sites-enabled/mysite.dev mysite.dev
    • Note: $ ln -s target linkname

Finally, restart Apache:

  1. $ sudo service apache2 restart
  2. You’re done!

See! Not so bad…

Posted in Apache, Solutions, Ubuntu, Virtual Hosts | Leave a comment

Add Mootools to a Wordpress child theme

The following code, when included in the functions.php file in your Wordpress child theme, will correctly load Mootools and a custom script. This is the only way I am able make custom scripts work, but you hear a lot of stuff out there on the interweb…


<?php
function add_js() {
$stylesheet_dir = get_bloginfo('stylesheet_directory');
$myscript = $stylesheet_dir . '/js/myscript.js';
$mootools = $stylesheet_dir . '/js/mootools.js';
wp_enqueue_script('mootools', $mootools, '', '1.2.4', false);
wp_enqueue_script('myscript', $myscript, array('mootools'), '1.0', false);
}
add_js();
?>

Notice how every parameter is used in the < ?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?> function even though all but the first one is supposed to be optional. Maybe its a PHP thing. Whatever.

Posted in Solutions, Wordpress | Leave a comment

I’m switching to Chrome (on a trail basis)

I thought I would be a Firefox user till I died, but holy crap Chrome is fast! I can launch Firefox, go make a sandwich, launch Chrome and be browsing before Firefox loads. This is particularly nice on our crappy Windows machines at work. JavaScript is noticeably faster. Chrome seems more stable and doesn’t do that occasional temporary freeze thing on slow computers. As much. Well, at least the whole thing doesn’t freeze, just the one tab that is having trouble.

Extensions

The Dev and Beta version of Chrome work with extensions (like LastPass, worlds greatest password manager). The dev version has been very stable for me:

http://dev.chromium.org/getting-involved/dev-channel

Developer Tools! Eeeee!

The thing that sealed the deal is the built-in developer tools. Seems they’ve shipped Chrome with a built-in Firebug-like JavaScript debugger and inspector (press ctrl-shift-j). Its not installed automatically on Linux machines, so apt-get it:

sudo apt-get install chromium-browser-inspector

I haven’t used it enough to form an opinion yet, but it looks great. I’m going to finish out the current site I’m developing with Firefox and Firebug, but I’ve got another one in the pipe that is going to be all Chrome.

Fantastic UI

Best user interface of any browser I’ve used.

The teeny tiny branding means I get at least a quarter inch of screen real estate that would normally be full of dialog. Page loading info is shown in a tiny pop-up at the bottom, so I get more space there too. Its overlaid on top of the horizontal scroll bar, taking up no room at all. The combo address/search bar means the horizontal space is more usable too. I can usually see the whole url even when I’m using Chrome in a small window.

I love love love the tabs at the very top. It reinforces the idea that each tab is its own process doing its own thing (dialogs like preferences are also displayed in a tab, just like web pages). Tabs are arguably the most important feature of the browser dialog, they tell you where you are, and I definitely click on them more than anything else. Making them a big target right at the top where they are the most obvious thing in the whole interface is genius.

Way to go Google! Can’t wait for Chrome OS!

Update, 2/25/2010

Well, I tried.  Turns out that the Chrome developer tools has some usability issues that make it very hard to use effectively.  The number one problem is that the font is too small.  I get a headache just glancing at it.  I’m also annoyed by the checkboxes that pop up when you mouse over a css property.  I’m sure that one sounded really great on paper, but in practice its horrible.  The major thing it lacks is the “Larger Command Line” option that Firebug has, which allows you to put multi-line indented code in the console and run it.  It’s really nice and I use it all the time.

I still really like Chrome and I use it more and more (even though it doesn’t work with Netflix) for my non-development browsing pleasure.  Its still a young project and I’m hopeful that Google will improve the developer tools soon.

Posted in Musings, Software I use | Leave a comment

Wordpress Error: Unable to create directory / Is its parent directory writable by the server?

If you get this error when you try to upload an image to your WordPress blog, there are two things you can do:

  1. Go to Settings > Miscellaneous in your Wordpress admin area and make sure that ‘Store uploads in this folder’ is set to the default: wp-content/uploads (notice there is no ‘/’ before wp-content/uploads).  Try to upload again and see if it works.
  2. If that didn’t work, open up a terminal and navigate to the wp-content directory.  If wp-content does not contain sub-directory called ‘uploads’, create one and then change its permissions to wide open (sudo chmod 777 uploads/). Try to upload the image again.  If this works, navigate to the wp-content/uploads/ directory and check the owner of the image you just uploaded (ls -l). It will probably be something weird you’ve never seen before (mine was ‘www-data’). Navigate up a directory and change the owner of the uploads folder to the one WordPress want to use: sudo chown www-data:www:data. Then revert the permissions back to something a little safer: sudo chmod 755 uploads/ and you’re done.
Posted in Musings | Leave a comment

Use your user’s public_html directory to serve webpages

Using a public_html file in your home directory is much more convenient than /var/www for a local website development environment. The following commands create a file called public_html in your home directory and enable the UserDir module in Apache.

From the command line, enter:

  • $ mkdir ~/public_html
  • $ cd /etc/apache2/mods-enabled
  • $ sudo ln -s ../mods-available/userdir.conf userdir.conf
  • $ sudo ln -s ../mods-available/userdir.load userdir.load
  • $ sudo /etc/init.d/apache2 restart
  • $ sudo service apache2 restart
Posted in Musings | Leave a comment

Ubuntu Karmic LAMP stack installation

In the terminal, type:

  • $ sudo apt-get install apache2
  • $ sudo apt-get install php5 libapache2-mod-php5 php5-mysql
  • $ sudo apt-get install mysql-server
  • $ sudo apt-get install phpmyadmin

Just agree when it asks you stuff.

Posted in Solutions, Ubuntu | Leave a comment

Use ’service’ to start, stop and restart Apache in Ubuntu Karmic

The service service_name command command can be used to start, stop, or restart anything in your /etc/init.d directory. From the command line, use it like this:


$ sudo service apache2 start
$ sudo service apache2 stop
$ sudo service apache2 restart

Posted in Solutions, Ubuntu | Leave a comment

The difference between a working tree, repository, branch, and checkout in the Bazaar version control system

I wish this was in huge type on the front page of the Bazaar web site because it is essential to understanding just what the heck is going on when you place you files under version control.

I’m going to use an example to explain this. These events are listed in the order that they usually occur, at least when I use Bazaar. If you want to understand this at all, you better read the Bazaar in five minutes tutorial first.

Working Tree

When I start a new project I usually create a folder named after my project, say ‘foo/’, and in folder ‘foo/’ I might put my first file I’ll be working on called, say, ‘bar.py’, and a file to hold some data called ‘data.py’.  So as soon as I initialise Bazaar, ‘bar.py’ and ‘data.py’ will make up my working tree – the files I actually edit.

Branch

The next thing I do is initialise Bazaar by typing the command ‘bzr init’ in the terminal, which creates a hidden folder in the ‘foo/’ directory called ‘.bzr/’. This hidden folder and its contents is a branch – the state of a project including all its history.

A branch usually includes a working tree too, but it doesn’t have to. If you get a branch and it doesn’t have a working tree, you can run ‘bzr update’ to make one.

Repository

Among other things, ‘.bzr/’ contains a folder called ‘repository’. This, not surprisingly, is your repository – the place where all commited changes to your working tree are stored.

There isn’t much to a repository until you run ‘bzr add’, which adds all the files and folders in your project to the branch, and ‘bzr commit’ which records all the changes to your working tree in your repository.

Your repository works like a database. Each file you put under version control gets a unique identifier and each commit is numbered so you can go back to any revision and see what you did. A common thing to do if you have more than one person working on your project is to use the same repository for everyone. The command ‘bzr init-repo’ (as opposed to just plain old ‘bzr init’) creates a shared repository.

Checkout

So I created a folder and put some files in it, then initialised Bazaar which made my project a branch. Then I ran ‘bzr add’ and ‘bzr commit’ to add the files in my working tree and revisions therein to my branch. Now suppose someone else wanted to add code to my project? That is where checkout comes in.

If the hobo living behind the Safeway wants a stand-alone version of my branch that he can stare at or create a competing project that has nothing to do with mine, he can run ‘bzr branch [BRANCH_LOCATION] [TO_LOCATION]‘. This will create a copy of my branch on his computer, but his commits will not effect my branch.

But if Sally Smartypants and I are friends and she wants to contribute to my project, she would run ‘bzr checkout [BRANCH_LOCATION] [TO_LOCATION]‘, which would create a copy of my branch on her computer just like the hobo, with the major difference that Sally and my branches share the same repository. So when Sally runs ‘bzr commit’, the changes that she made would be reflected in the branch I have. I won’t see them right away though. If I want Sally’s changes to show up in my working tree, I have to run ‘bzr update’ to sync my working tree with our shared repository.

But what if a storm hits and Sally’s Internet goes down? No prob, her commits will just go on her local repository (since she has a full branch that works all by itself) until she’s back online and runs ‘bzr merge’ to sync up her local repository with the main branch.

Hope that clears things up. I know I’ve learned a lot.

Posted in Musings | Leave a comment

Fixed my site

LastPass, my fave password manager, was doing funny things with WordPress, reposting and deleting my blog posts. Weird. Fixed now.

Posted in Musings | Leave a comment