Skip navigation

Category Archives: Computer Tweaks

A colleague of mine just sent me a couple links that were great tips if you work with git often. lifeon.biggerplanet.com talks about how to take advantage of customizing the prompt and using git-completion.bash script to auto-complete things like git branches and also display the branches in the prompt.

Points of interest…

git-completion.bash

export PATH="$HOME/bin:$PATH"
source ~/bin/git-completion.bash
PS1='[\u@\h \w$(__git_ps1 " (%s)")]\$ '

HEADS UP: This is going to be cleaned up sometime soon… just too tired… Mainly, at the end, I kind of slap on the NAT network thing and the note on how to add users to the vboxsf group to properlly use the VirtualBox Shared File auto mount on system boot.

Use VirtualBox to host Ubuntu Server (64 bit) use as a web server. To ease daily / local development, we will need to make sure the files are saved to the host machine (in this case my Macbook) so that there is no need to share files through the network. The idea is that it’s not at all ideal to use a text editor like an IDE over something like AFP or SMB.

So… this is what we’ll be doing.

  1. Install VirtualBox (if not already.)
  2. Create a new Ubuntu virtual machine.
  3. Setup Ubuntu to be a very basic web server with Apache, MySQL and PHP.
  4. Setup the Ubuntu guest to have access to a shared folder on the host machine.

Stuff you’ll need, so download it all first…

VirtualBox (version 4.0.8 r71778 is used for this walk-through)
http://www.virtualbox.org

Ubuntu (ubuntu-11.04-server-amd64.iso is the version used for this walk-through)
http://www.ubuntu.com/download/server/download

Make sure you have VirtualBox installed

Just download it and follow the instructions.

After you install, it’s a good time to locate an ISO file you’ll need ONLY if your using the server edition (e.g. no GUI.)

- Under your /Applications folder locate the VirtualBox app
- Right-click the app, and select Show Package Contents
- Copy the file Contents/MacOS/VBoxGuestAdditions.iso somewhere (say next to the Ubuntu iso file.)

Later we’ll need this file, so just remember where it is.

Setup Ubuntu (Ubuntu Server 11.04)

I’m going to use the server edition. It’s a smaller download being that the GUI is not used and it’s not needed for development lots of times. This will however increase the complexity being that later when we go to setup the shared drive (step 4) we need to jump some hurdles a bit to install the VirtualBox Guest tools. BUT… go big or go home!.

Note: If you want the full desktop version of Ubuntu, go ahead and download the desktop version instead, the rest of the steps should be the same, but you will probably be able to figure out how to setup the VirtualBox Guest Tools yourself.

Now, create the virtual machine (this may vary per your hard drive requirements)

- open up VirtualBox and click New, you should be directed to a wizard
- name your vm something like "UbuntuServer - 64bit"
- make sure Linux and Ubuntu 64bit is selected under "os type"
- select maybe 512 or 1024 mb for ram
- create a new hard drive (vdi) image for your system, when you click next you'll get a sub-wizard
- name your hard drive image (vdi) whatever, I named it to be the same as my vm
- eventually you'll get a summary / confirmation page. make sure it's what you want and click Done

Now you could start your new VM, but first make sure you tell virtual box to mount the Ubuntu iso you just downloaded so you can install it. (Just like you would make sure a bootable CD was available to boot when installing an OS.)

To make the ISO available to the cd…

- Select the Ubuntu VM in VirtualBox
- Click "Settings" then go to "Storage"
- Click "Empty" under the IDE controller
- Next to CD/DVD Drive, click the little CD icon next to the drop-down
- Select "Choose a virtual CD/DVD disk file"
- Locate the Ubuntu ISO file you downloaded.
- Click OK

Oh, and it would be good to double-check that in Settings/System the CD/DVD-ROM is above the Hard Disk in the Boot Order!

In the menu under Devices/Network, I’m using NAT. Make sure you tweak your settings so your VM has network access also.

Thats it, the VM is setup, now we install Ubuntu. Double-click / start the UbuntuServer Virtual Machine and read on.

First Boot to install Ubuntu Server

When you first start the VM, you should be prompted to install Ubuntu. I’m going to skim through this for the most part, noting a few things that were important to the process.

IMPORTANT: Note the key you need to use to get out of the guest machine. After you click into Ubuntu, you’ll need to use left cmd button by default to get out of the VM!

- Language: English
- Install Ubuntu Server
- ...
- Hostname: ubuntuserver
- Partion disks: Guided - use entire + LVM (use whole disk...)
- Full Name of a user: Web Dev
- User/Pass: webdev / webdev (or change to a stronger / different password / username)
- Did not encrypt the drive
- No proxy
- No Automatic Updates
- Software Selection: I selected [OpenSSH, LAMP server, Mail server]
- MySQL pass: root
- Postfix Config: Local only, System mail name "ubuntuserver.mail"
- Installed Grub Boot Loader

Finally, after that, when prompted to remove the CD and reboot, click the CD icon in the lower right to eject the ISO. Then click “Continue”.

Configure the Guest Tools to get a Share working

After you reboot, you should be prompted to login. You need to shut down, so just close out / power down the vm.

Go back into the settings of the VM…

- Under Shared Folders click the green "plus/folder" icon to create a new share
- I'm using a folder in my Sites directory (/Users/chris/Sites/ubuntuserver), but you can use any folder.
- Name the folder and click OK, then OK (get back to the VM list)

IMPORTANT: The web server or other programs will probably need to write to that folder, so be careful to make sure you don’t select your whole drive or something. If something goes wrong on the guest machine, your host machine files could be lost! Just sayin.

Install / make sure some extra stuff is ready. This is so that VirtualBox can take more control over the linux kernal thus allowing for things like seemless shared drives form host to guest and vise-versa. (See the http://www.virtualbox.org/manual/ch04.html#idp5848336 page under Ubuntu)

In order to fully update your guest system, open a terminal and run

- Now, boot up your UbuntuServer and login
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install dkms
- sudo reboot

Boot up again then load the tools iso file (originally located at /Applications/VirtualBox/Contents/MacOS/VBoxGuestAdditions.iso via Show Package Contents on the VirtualBox app)

- Click Devices / CD/DVD Devices / Choose a virtual CD/DVD disk file and locate the VBoxGuestAdditions.iso file

Run a few more commands… you WILL get an error about not installing stuff with X Windows… thats fine.

- sudo apt-get install hwinfo
- sudo mount /dev/cdrom /media/cdrom
- cd /media/cdrom
- sudo ./VBoxLinuxAdditions.run
- sudo reboot

Finally…

- sudo mkdir /media/ubuntuserver
- sudo mount -t vboxsf ubuntuserver /media/ubuntuserver
- cd /media/ubuntuserver

BAM! You should be able to “ls” and list your files

Well, there is one last thing that may be very different for each of your dev environments. Network access to your VM.

For now, I can show you how to use NAT to access your server. I’m NOT a network guy… so there may be a better way. However, I believe that using NAT will keep you padded from the outside network (e.g. at home or at a coffee shot wifi, NAT should work the same in this case.)

- (sometime after NAT has been selected) with your vm running type 'ifconfig' and get the ip address for the the eth0 device
- shut down your vm if it's currently running (sudo shutdown -P now)
- in your VM's Settings, choose  Network
- select NAT, and under Advanced click the Port forwarding
- setup a new forward from 127.0.0.1 port 8080 (or 80 to replace your main webserver or any other port you want thats free)
- set the port forward to the ip address of the eth0 device in your vm port 80

When you boot up you should be able to go (on your Mac host) to http://localhost:8080 or 127.0.0.1:8080 and see the file served from /var/www/index.html on your Ubuntu guest.

Final Note: You can use VirtualBox to auto mount your share. That saves you the need to manually mount the shared drive every time you boot. HOWEVER, you need to add your avarage user to the vboxsf group so they have permission to that share. The perms on the automounted share are root / vboxsf, so this will fix your users… “sudo usermod -aG vboxsf “… e.g.

- sudo usermod -aG vboxsf webdev
- sudo usermod -aG vboxsf www-data

The www-data user is the default user apache runs as per your /etc/apache2/envvars file.

References:

I’m always using the Mac OSX Terminal app for things. I was jealous of linux machines though, their terminals were much nicer. Things like the Delete key worked among other things.

I found this to help. (From http://hints.macworld.com/article.php?story=20050525040921189) (Originally it was from http://koorb.co.uk/scrapbook/ I guess, but that page errors out for me.)

Add this to ~/.inputrc (or ~/.bash_profile works too I guess) (it has to go in your .inputrc file.

# this makes the "delete" key work rather than
# just entering a ~
"\e[3~": delete-char

# these allow you to use ctrl+left/right arrow keys
# to jump the cursor over words
"\e[5C": forward-word
"\e[5D": backward-word

# these allow you to start typing a command and
# use the up/down arrow to auto complete from
# commands in your history
"\e[B": history-search-forward
"\e[A": history-search-backward

# this lets you hit tab to auto-complete a file or
# directory name ignoring case
set completion-ignore-case On

# I'm not sure what keys these are!
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[2~": quoted-insert

Thats it, open a new Terminal window and you’ll be able to Delete away.

Google Chrome nailed it in my opinion with the address bar. It’s a typical address bar, but if you type something there that is not an URL, it guesses that you want to search it. Perfect! I find myself frustrated with Firefox, Safari and other browsers when I get errors after typing my search in the address bar.

In Firefox at least, it’s easy to get the search bar to work that way. I found this page offers a great walk through. It’s a quick 1 or 2 min tweak, and it uses Google as the fall back search.

After yo apply the tweak, you can totally remove the search bar from the Firefox interface in the top right.

A while back I wrote this post describing my efforts in looking for a way to rate iTunes shortcuts anytime with a quick shortcut on Mac. After upgrading to Snow Leopard, I found the steps to enable this site wide was a bit different, thus this post was created.

First, use Automator to create the Services needed. Services will be available no matter what app is in the foreground.

  1. Open Automator
  2. Create a new “Service”
  3. Under “Utilities” under the Library, add “Run AppleScript” as the first and only step in the Automation
  4. Paste the following code in place of “(* Your script goes here *)”

    tell application "iTunes"
    set the rating of current track to 20
    end tell
  5. Save under the name “Rate as 1 star”
  6. Change “20″ to “40″ then Save As “Rate as 2 stars”
  7. Change “40″ to “60″ then Save As “Rate as 3 stars”
  8. Change “60″ to “80″ then Save As “Rate as 4 stars”
  9. Change “80″ to “100″ then Save As “Rate as 5 stars”
  10. That finishes up the Automator work. Just be sure you used “Save As” and not “Save”, you don’t want to overwrite your services, but create 5 different services.

    Now, go to System Preferences, Keyboard, Keyboard Shortcuts. Select “Services” on the left window, and in the right window you should see (at the bottom) the 5 services you created.

    You can click in the white space to the right of the services (not intuitive really, but there is a little spot on the right you can double click to edit the short cuts for all the items in that list.)

    Once you add a shortcut there you should be able to use the short cut from anywhere!

    Be warned, I found it very tricky to find a short cut that worked for me in all apps, since some apps or services (mainly iTunes) had shortcuts similar to them. (Snapshot utility for example is Cmd-shift-4, which may be a shortcut you wanted to use.)

    I found that the Cmd-Option-Shift worked for me best.

    UPDATE: Add Growl Notifications to show that the song was indeed rated!

    This is a screen shot from Automator showing the Service for Rate as 1 Star

    Well, this is an easy and quick addition to the Automator services. I constently found myself switching to iTunes to see if the song was rated… kind of defeted the purpose of adding the shortcuts!

    I realized (in somewhat of a “duh” moment) that I could just use Growl to add a little note for each of the ratings. I already had Growl installed (it’s a standard install for any Mac of mine.) And best of all Growl is very Automator friendly, so it just took a few seconds to add a pop-up Growl notification for each Rate as ? Service!

So I had just sat down at my computer and for the first time ever I was asked to restart my mac due to a crash!

It was bound to happen someday, I’m suprised it took 3 years to see my first OS crash on a mac though.

When I switched from PC to Mac, the single hardest thing I had adjusting to was the new keyboard shortcuts. At the top of the list was the Home/End keys, they never worked quite right.

I quickly adjusted to using Command-Left or Command-Right, and it even became natural, and since I was on a 15 inch Powerbook, it seemed even better anyway since I didn’t have a dedicated cluster of keys with the Home/End.

If your on a full sized keyboard and just don’t like how the keys are setup, there’s an easy solution. DoubleCommand.

This freeware will add a Preference Pane to the System Preferences and will allow you to easily set some keyboard bindings.

The preference pane of DoubleCommand

The preference pane of DoubleCommand

Though I don’t think you can create your own keyboard bindings, it does offer the ability to quickly ‘fix’ the Home/End keys.

Ok, this is probably something that has been known for some time now… but since when did Windows offer the ability to scroll sidewas by holding Ctrl + Alt while using the mouse scroll wheel?

I wish I knew that a while ago. Apple has been doing that for a while, and I was glad to find that you could do so while holding Shift while scrolling rather than relying on the stupid fragile Mighty Mouse side scroll.

I’m using Vista, but i wonder if It’s possible in XP or other older versions…

I asked myself the question today, is there a way to rate a song in iTunes with a keyboard shortcut? Yes, there is.

I found a walk-through on how to do this at www.macgeekery.com
describing how, but it’s a walk through that’s better suited for those looking to learn how to write more scripts.

If you just want to get it working, here’s how…

  1. Open the System Preferences, open Keyboard & Mouse, click on the Keyboard Shortcuts
  2. Create 5 new short cuts, name them Rate as 1, Rate as 2, … Rate as 5. (Remember how they are named exactly) Make each of the 5 short cuts react to the short cut you want to, e.g. I set Rate as 1 to apple-alt-1, rate as 2 to apple-alt-2 and so on
  3. Create the folders if they don’t exist, but you’ll be saving 5 files in /Library/iTunes/Scripts (or ~/Library/iTunes/Scripts in you only want the short cuts in one users iTunes)
  4. Open the application Script Editor (Applications/AppleScript/Script Editor) and enter the following into the script window…

    tell application "iTunes"
    set the rating of current track to 20
    end tell

    (thanks for the error fix Andy)

  5. Save As “Rate as 1″ exactly as the short cut that was created is named, in the folder you created in the last step. (File format should be script)
  6. Do this four more times, but before you save change the 20 from above to match the following (20 = 1 star)(40 = 2 star)(60 = 3 star)(80 = 4 star)(100 = 5 star)
  7. Almost set, now you just need to restart something called SystemUIServer. Open the Activity Monitor (Applications/Utilities/Activity Monitor), then find the Process Name (SystemUIServer) and Quit Process. Like the Finder, if you Force Quit it will just re-start almost instantly. (Alternatively, you could reboot the computer)

You should be all set now, in iTunes you can rate the selected song with the keyboard short cuts. If you don’t like apple-option-number you can use whatever you want, just tweak the keyboard short cuts menu.

Update 1: Here’s a couple links that may help. One is X-Tunes, an app that might replace what your looking at this script for.

http://www.pol-online.net/x-tunes
http://proxi.griffintechnology.com/blog/2007/09/06/trigger-chains-with-applescript/

After upgrading to Snow Leopard, there is a different process to this. Not much but enough to warrant a different post. It does result in editing the stars for the current track in from in any app. Follow this walk through for Snow Leopard

It’s becoming easier and easier to take advantage of a mobile device’s ability to pinpoint your current location. Here’s a list of starting points where you’ll find Firefox add-ons, Blackberry’s, iPhone apps or other items of location based interests.

  • fire eagle: if you have access to it (its in beta stages while i write this) fireeagle will help you manage your location based data from one place. You tell it where you are, and other sites or networks will know where you are.
  • google mobile maps: get google maps on to a handful of mobile devices, get functionality similar to the iPhone’s copy of google maps.
  • loki: tools like a firefox add-on to allow websites access to your current location using javascript. (fireeagle for example can update your location if you have this firefox addon without you manually typing it.)
  • bright kite: a social network that uses your location to narrow down who you communicate with. a great example of how to use a visitors location in a site. also offers a mobile and iphone version of the site for on-the-go use.