Rubyist OS X Dev setup
Posted: May 30, 2010 Filed under: Uncategorized | Tags: os_x, ruby, software development 1 Comment »I just bought a shiny new MacBook Pro with a 2.4 GHz Core i5, 8 GB Memory, on OS X 10.63 and thought I would share my setup.
TextMate
Head over to http://macromates.com/ and download TextMate. Once we have installed TextMate we are going to configure it. From the TextMate menu go to:
TextMate >> Preferences >> Fonts & Colors. Then select the “Twilight” theme.
For smaller projects where we do the markup ourselves we are going to use Haml, which we will install shortly, TextMate does not include this bundle by default, so we need to add it. Open up terminal and enter the following:
cd /Applications/TextMate.app/Contents/SharedSupport/Bundles svn co "http://svn.textmate.org/trunk/Bundles/Ruby%20Haml.tmbundle/"
Back in TextMate go to Bundles >> Bundle Editor >> Reload Bundles.
Terminal
Next on our list is to configure Terminal.
The first thing we want to do is setup the bash prompt for Git. This cool trick will show our checked out topic branch right at the prompt:
Open a Terminal session and type the follow:
sudo mate ~/.bash_login
To configure we will copy the following into our .bash_login file:
RED="\[33[0;31m\]"
YELLOW="\[33[0;33m\]"
GREEN="\[33[0;32m\]"
BLUE="\[33[0;34m\]"
LIGHT_RED="\[33[1;31m\]"
LIGHT_GREEN="\[33[1;32m\]"
WHITE="\[33[1;37m\]"
LIGHT_GRAY="\[33[0;37m\]"
COLOR_NONE="\[\e[0m\]"
function parse_git_branch {
git rev-parse --git-dir &> /dev/null
git_status="$(git status 2> /dev/null)"
branch_pattern="^# On branch ([^${IFS}]*)"
remote_pattern="# Your branch is (.*) of"
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="${RED}⚡"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="${YELLOW}↑"
else
remote="${YELLOW}↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="${YELLOW}↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo " (${branch})${remote}${state}"
fi
}
function prompt_func() {
previous_return_value=$?;
# prompt="${TITLEBAR}$BLUE[$RED\w$GREEN$(__git_ps1)$YELLOW$(git_dirty_flag)$BLUE]$COLOR_NONE "
prompt="${TITLEBAR}${BLUE}[${RED}\w${GREEN}$(parse_git_branch)${BLUE}]${COLOR_NONE} "
if test $previous_return_value -eq 0
then
PS1="${prompt}➔ "
else
PS1="${prompt}${RED}➔${COLOR_NONE} "
fi
}
PROMPT_COMMAND=prompt_func
Next let’s make terminal a little prettier. From the Terminal menu:
Terminal >> Preferences >> Startup; New window settings: "Homebrew". Terminal >> Preferences >> Settings; Font select "Andale Mono 18pt".
Now that we have TextMate and Terminal configured we are going to setup our development tools.
Development Tools
XCode Tools
Go to http://developer.apple.com/mac/ and download the latest version of XCode. Once it is downloaded simply run the installer.
Git
Next we will download the git-osx-installer, then run it.
RubyGems
From terminal we need to update our RubyGems:
sudo gem install rubygems-update sudo update_rubygems
SSH
Still at terminal we will run:
ssh-keygen -t rsa -C "cgabaldon@gmail.com" cat ~/.ssh/id_rsa.pub | pbcopy
GitHub
Then we will navigate over to GitHub.com >> Account Settings to add our RSA key that we copied to the clipboard.
MySQL
We are next heading over to download mysql-5.1.47-osx10.6-x86_64.dmg, and then once downloaded run the installer.
After MySQL is installed we will install the MySQL preference pane which gets added to the OS X System Preferences. To install we simply double clicking on the MySQL.prefPane contained within the MySQL install package. This gives us a convenient way to start and stop our MySQL server from the System Preferences.
Back to terminal to add our newly installed MySQL server to our path:
cd sudo mate .bash_login # add: export PATH=/usr/local/mysql/bin:$PATH
Then last, but not least we need to install our ruby mysql gem:
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Sinatra
sudo gem install sinatra
Rails
sudo gem install rails
Other Gems
sudo gem install sequel sudo gem install haml sudo gem install do_sqlite3 sudo gem install cheat sudo gem install cucumber sudo gem install dancroak-twitter-search sudo gem install faker sudo gem install geokit sudo gem install giraffesoft-timeline_fu sudo gem install github sudo gem install heroku sudo gem install json sudo gem install mislav-hanna sudo gem install nokogiri sudo gem install passenger sudo gem install rack sudo gem install railsmachine sudo gem install RedCloth sudo gem install redgreen sudo gem install reek sudo gem install rest-client sudo gem install right_aws sudo gem install right_http_connection sudo gem install rr sudo gem install rspec sudo gem install technicalpickles-le-git sudo gem install thoughtbot-factory_girl sudo gem install thoughtbot-paperclip sudo gem install thoughtbot-shoulda sudo gem install webmat-git_remote_branch sudo gem install webrat sudo gem install wirble
Capistrano
To simplify deployment we need to install Capistrano:
sudo gem install capistrano sudo gem install capistrano-ext
FireFox
We of course need to install FireFox, by downloading and installing.
FireBug
Then Firebug and YSlow to help us on our front end engineering work.
Quicksilver
To help us keep our hands off the mouse we will install Quicksliver so we can exercise our keyboard foo. To install simply extract the tarball and drag to Applications.
Update the mappings to be Apple+Space for Quicksilver and Option+Space for Spotlight.
Fluid
Finally, we will install Fluid to help us turn our commonly visited sites into apps. Once downloaded drag to Applications.
Virtual Box
All production applications get deployed to a LAMP server, so we need a place to test out various configurations locally. Say hello to virtualization! We are going to use VirtualBox; download and install.
Evernote
Never forget anything; install Evernote and sign up.
Concentrate
Multitasking does not work when trying program, distractions will kill you. We are going to install Concentrate to apply the Pomodoro technique to keep focused and productive.
Things
We have a lot of Things to get done, so we need a great task management tool.
Growl
Most of the cooler OSX applications support notifications, Growl is the system for doing that.
Pencil
Pencil is one of the coolest UI prototyping tools I have used since a Sharpie.
Hack
We are now ready to do some serious hacking..
Django LAMP
Posted: May 12, 2010 Filed under: Uncategorized | Tags: apache, django, python, software development 4 Comments »Over the past year and a half I have been using WordPress to publish my web site & blog. Prior to WordPress I was using Calabro which is build with Python on TurboGears. WordPress is great, but does not give me all the control I need. I have recently decided to move back into the world of freelance web development and therefore want to do more with my main web site carlosgabaldon.com. I wanted to build something that showcases my specialties which are Python, Django, JavaScript, semantic markup, and jQuery so this new web site will be built with all of these great tools. I also thought it would be a good opportunity to document the process that I follow when starting a new project.
I like to get integration and deployment tasks figured out early since these tasks contain the most risk. Here is where I usually start:
- Setup the the code repository.
- Create the initial project structure; so we have something to deploy and iterate over.
- Deploy the initial project to the production web server; Apache on a Linode VPS.
- Script the the subsequent deployment process for continuous deployment.
Today I am going to go over step number 3; deploying a LAMP server.
Server
The first thing you are going to need is to get a virtual private server (VPS) or dedicated server account at a hosting company such as Linode or SliceHost. I am using Linode running Ubuntu 10.04 LTS (Lucid Lynx).
SSH
Once you have your server you will need to open a console and SSH into your new server:
$ ssh root@{your.ip.address}
Prerequisites
Now that we are logged in we need to install the prerequisites:
$ apt-get update $ apt-get upgrade $ apt-get install libapache2-mod-python python-mysqldb $ apt-get install python-setuptools $ apt-get install mysql-server $ apt-get install subversion
Django
We want to be on the bleeding edge so we are going to install the trunk version of Django. First we checkout django-trunk to /usr/local/lib:
$ cd /usr/local/lib/ $ svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
Then create our symbolic links to point to our new trunk version of Django:
$ ln -s `pwd`/django-trunk/django /usr/lib/python2.6/dist-packages/django $ ln -s `pwd`/django-trunk/django/bin/django-admin.py /usr/local/bin
Also, while we are in this directory we will create a symbolic link to the Django admin media:
$ ln -s `pwd`/django-trunk/django/contrib/admin/media /var/www/media $ cd
Git
We need to install Git and then clone the project repository. To keep things simple for this tutorial we are going to put the web site under the Apache root.
$ apt-get install git-core
$ cd /var/www
$ git clone git://github.com/{YourGitHubAccout/your_django_project}.git
Apache
Next we need to configure Apache. I will be using modpython as the python host for Django. Since Django has support for WSGI we could use modwsgi, but I am going to stick with modpython for this tutorial since it has a proven track record in large scale production environments. The only draw back to using modpython over modwsgi is that an Apache restart is required after each deployment. Also, to keep this tutorial simple we are going have Django sever up the static meda files. This is not an optimal setup for a high traffic web site, but for the initial setup it works fine.
To configure Apache will open the default vhost and edit it to look like below:
$ nano /etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerName {your.domain}.com
DocumentRoot /var/www
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE {your_django_project}.settings
PythonOption django.root /{your_top_level_folder_name
PythonDebug On
PythonPath "['/var/www/'] + sys.path"
</Location>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
</VirtualHost>
For the changes to take effect we need to restart Apache
$ /etc/init.d/apache2 restart
MySQL
We need configure the database. Connect to the mysql server using your mysql user name and password.
$ mysql -u root -pXXXX
$ create database {your_db_name};
$ nano /var/www/{your_django_project}/settings.py # update database connection info
Finally, we have Django create the tables.
$ cd /var/www/{your_django_project}
$ ./manage.py syncdb
If everything was done right we can open a browser and point it to http://{your.ip.address}/home/ and we should be running. The final step would be to open your DSN manager (i.e. godaddy) where your domain is registered and point the @ record to {your.ip.address}










