November 2010

archive

git-aware ps1 Nov
19
1
0

http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without

You'll need git-completion.bash working, but put the following line into your .bashrc or .bash_profile to display the current branch in your terminal.

PS1='$(__git_ps1 "(%s)")$ '

Which you can combine with whatever you already have setup. It can be something similar to one of the following:

PS1='\h:\W$(__git_ps1 "(%s)") \u\$ '
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\ $(__git_ps1 "(%s)")$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] $(__git_ps1 "(%s)")$ '

comments

installing a lamp stack on ubuntu Nov
17
1
0

If you're ever in the unfortunate position where you need to install a LAMP stack (Linux, Apache, MySQL, PHP) on an Ubuntu server, you can install the following modules to quickly get yourself up and running.

apache2 php5-mysql libapache2-mod-php5 mysql-server

sudo apt-get install apache2
sudo apt-get install php5-mysql
sudo apt-get install libapache2-mod-php5
sudo apt-get install mysql-server

Or, for the super lazy use tasksel:

sudo tasksel install lamp-server

Good luck and godspeed.

comments

random string and digit generation in python Nov
17
1
0

This snippet generates a random string with digits with a defined LENGTH in Python. Useful for things like generating random passwords.

import os
import string


LENGTH = 6

password = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(LENGTH))

comments

using the for loop counter in python Nov
17
1
0

Even with all the powerful tools Python loops do for you, sometimes you need to grab the good ol' loop counter.

There are a couple of different ways you can do this. The cleanest method that I found so far is to use the enumerate function. You can do something like this:

test = ['a', 'b', 'c']

for counter, value in enumerate(test):
    print counter, value

comments