Category Archives: Quick Fixes

Testing a website at its new IP address

How do you check that your new website is working without updating the DNS for the domain?

Well, if you know the new IP address, you can “trick” your home computer/browser to show the site you want, rather than the old site.

1) For Windows 7, click on the Start Menu, choose “All Programs” >> Accessories.
Next right-click on Notepad, and choose “Run as administrator”

2) Choose File, then Open…
In the File name: type in c:\windows\system32\drivers\etc\*.*
Find the “hosts” file, click on it, then click on the “Open” button.

3) Scroll down to the very bottom of the file, and add in a new line in this format, IP Address (whitespace) domain name:


111.222.33.44     www.example.com
44.55.66.77       new.example.com

Once you save the file, you’ll instantly be able to type in the domain name that you want to test. With the above example, that means typing in http://new.example.com will take you to the server at the IP address of 44.55.66.77. And if instead you typed in http://www.example.com, you would hit the server located at 111.222.33.44.

Have your bash prompt tell you git information

While you can obviously type in “git status” to see what’s happening (git-wise) in a directory, wouldn’t it be nice if you could automagically see that info?

Well, you can. Just add this snippet to your ~/.bash_profile file:

if [ -f /etc/bash_completion.d/git ]; then
    . /etc/bash_completion.d/git
    PS1='\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ '
fi

Or, if that file doesn’t exist, you can create it with all of this code:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
if [ -f /etc/bash_completion.d/git ]; then
    . /etc/bash_completion.d/git
    PS1='\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ '
fi

####
#   Stash away examples of other possibilities for the prompt
#####
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$'
# PS1='[\u@\h \W$(__git_ps1 " (%s)")] \[\e[33m\]\w\[\e[0m\]\n\$'

Update!

I tried this on an older server that didn’t have /etc/bash_completion.d on it, and here’s how I got it to work.

1) Downloaded the latest stable version of https://github.com/telemachus/bash_completion.d and copied that directory into /etc/bash_completion.d

2) Created a symbolic link:

ln -s /etc/bash_completion.d/git-completion.bash /etc/bash_completion.d/git

3) If you get this error:

-bash: __git_ps1: command not found

then you will need to add this

if [ -f /etc/bash_completion.d/git-prompt.bash ]; then
   . /etc/bash_completion.d/git-prompt.bash
fi

before the call to . /etc/bash_completion.d/git

Make vim “more readable” on black backgrounds

I pretty much live inside of putty/ssh. My defaults are a black background with white/light lettering. However, when I first get to a new system, I find that this is one of the first things that I need to change. Makes reading comments in code sooo much easier.

vim-before-background-dark

So, go ahead and modify /etc/vim/vimrc

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

and remove the ” (double quote) from in front of set background=dark. This uncomments it, and makes that set vcommand visible to vi.

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

vim-after-background-dark