Sunday, August 11, 2013

git revert all changes

To revert all your local changes using git:

 $ git checkout .  

Friday, August 9, 2013

git commit deleted files

http://stackoverflow.com/questions/1402776/how-do-i-commit-all-deleted-files-in-git/1402793#1402793

To make git to automatically stage tracked files - including deleting the previously tracked files that were deleted without using git rm:

 $ git add -u  

Thursday, August 8, 2013

Using Amazon RDS MySQL with Heroku

https://devcenter.heroku.com/articles/amazon_rds

Install Java JRE

$ sudo apt-get install openjdk-6-jre  

Make sure JAVA_HOME is set

 $ export JAVA_HOME=/usr  
 $ echo $JAVA_HOME  
 $ export JAVA_HOME=/usr   
 $ echo $JAVA_HOME   
 $ $JAVA_HOME/bin/java -version   
 java version "1.6.0_27"   
 OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.2)   
 OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)   

Setup Amazon RDS Heroku CLI tools

http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/StartCLI.html

Download RDS CLI tools:

http://aws.amazon.com/developertools/2928

Unzip tools to /usr/local

$ export AWS_RDS_HOME=/usr/local/RDSCli-1.14.001/  
$ export PATH=$PATH:$AWS_RDS_HOME/bin
$ export AWS_CREDENTIAL_FILE=/usr/local/RDSCli-1.14.001/credential-file-path.template

Grant Heroku access to RDS using CLI tools:
(NOTE: 098166147350 is Heroku's secret number)

 $ rds-authorize-db-security-group-ingress \  
  --db-security-group-name default \  
  --ec2-security-group-name default \  
  --ec2-security-group-owner-id 098166147350 \  
  --aws-credential-file $AWS_CREDENTIAL_FILE  
 SECGROUP default default  
    EC2-SECGROUP default    sg-2**3 098166147350 authorizing  
    EC2-SECGROUP quicklaunch-1 sg-4**0 3***9 authorized  

Set DATABASE_URL in Heroku config


 heroku config:set DATABASE_URL=mysql2://username:password@rds-db-name.csisdr4twbmz.us-east-1.rds.amazonaws.com/database-name


Wednesday, August 7, 2013

Using Heroku - Common Usage

Show dynos / processes
heroku ps

Scale the number of web dynos to 1
heroku ps:scale web=1

Show heroku logs
heroku logs

Show environment variables for the app
heroku config

Add the SSL endpoint add-on
heroku addons:add ssl:endpoint

Add the SSL endpoint add-on (note, this is paid, $20/month)
heroku addons:add ssl:endpoint

Using virtualenv

$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
Install pip and virtualenv (on Ubuntu)

virtualenv ~/env
Creates a virtual environment at this location

source ~/env/bin/activate
Activates the virtual environment

deactivate
Deactivates the virtual environment

Monday, August 5, 2013

export LANG=en_GB

Add

export LANG=en_GB

to .bashrc

git push heroku remote end hung up unexpectedly

I had a public key established with Heroku, but git push kept failing.
The solution was to modify the ~/.ssh/config file

This problem was messing with me for a few days.
This this might help.
1) Find out what keys you have in Heroku now.
$ heroku keys
=== 1 key for joe@example.com
ssh-dss AAAAB8NzaC...DVj3R4Ww== joe@workstation.local
2) Build a ~/.ssh/config file:
$ sudo vim ~/.ssh/config
Edit with this info
Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes 
User joe@workstation.local

Django run server in background

To run the django debug server in the background in linux:

./manage.py runserver > /dev/null 2>&1 &