Friday, October 4, 2013

My Computer Is Holding Me Hostage

My primary machine is the Macbook Pro I purchased in early 2011, right before the new model came out, of course. I ordered it with a "regular" 5,400 RPM SATA hard drive, with the intent that I would install an SSD myself.

Soon after I received it, I bought an SSD from a friend, installed it, and was absolutely blown away by the performance. Apps loaded instantly. Startup and shutdown times were less than 20 seconds. My productivity skyrocketed, and life was green.

Then the SSD crashed.

Pretty bummed, I re-installed the 5,400 RPM hard drive, intending to replace it with a new SSD as soon as I saved up a little scratch.

That was two years ago.

Let me tell you -- I have had a  new SSD sitting in my closet for about a year and a half, just waiting to be installed.

I can't do it.

I can't bring myself to sacrifice my working machine, that has all my software installed, and spend the (hopefully only) two days it will take to get the new OSes (I dual boot Windows 7 and Mac OS, much to the derision of my colleagues) and all my software back up-to-speed.

Sacrificing the time, and the effort, has proven to be too much risk. I guess a machine that works slowly is worth far more to me than the hassle of re-creating the machine to work more quickly.

I produce music and have a deadline next Friday. I simply can't waste two days without productivity right now.

Before that, I was working on a new software startup, and simply couldn't spare even a day of lost productivity, even if it meant that my app-launch times, and re-boot times were far slower.

And on and on ad infinitum.

This hard drive is holding me hostage.

At work I have a beautiful new Macbook Pro (also dual-booted; sue me) with 500GB flash storage option, and it is a dream machine.

Waiting for my home machine to boot (when I actually turn it off) gives me 3 minutes and 37 seconds to think about how much time I could save if only I weren't trying to be so productive.

The basic premise here is that a system that is working is worth a lot to me.

Maybe I'm too superstitious. Or lazy? I have enough experience to know that sometimes it doesn't just work out like it is supposed to.

Maybe next week I'll install that new SSD... but only if I can get it done before band practice!

Sunday, August 11, 2013

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 &

Sunday, July 7, 2013

How to get real IP addresses in nginx access logs from ELB

With the default setup of nginx using AWS Elastic Load Balancer, all the IPs were being logged as being from the load balancer.

To get the real IP addresses of the requests, the nginx.conf file at /etc/nginx/nginx.conf is modified to have two additional lines:


 # /etc/nginx/nginx.conf  
 ...  
 real_ip_header X-Forwarded-For;  
 set_real_ip_from 10.0.0.0/8;  
 ...  

Friday, July 5, 2013

Setting uwsgi to run at startup

Modify the /etc/rc.local file to start uwsgi at startup

 #!/bin/sh -e
 #  
 # rc.local  
 #  
 # This script is executed at the end of each multiuser runlevel.  
 # Make sure that the script will "exit 0" on success or any other  
 # value on error.  
 #  
 # In order to enable or disable this script just change the execution  
 # bits.  
 #  
 # By default this script does nothing.  
 /usr/local/bin/uwsgi --ini /home/user/app/uwsgi.ini  
 exit 0  

Thursday, June 20, 2013

PuttyGen pem to ppk

For Amazon Web Services EC2 instances, AWS will generate a .pem file.

To use a .pem key with Putty, run PuttyGen. Select Conversions -> Import Key. Select the .pem file. Choose "Save Private Key" -- save to .ppk file.


To use with Putty, for your session, select Connection -> SSH -> Auth. Under "Private key file for authentication" browse for the .ppk file. Don't forget to save your session settings AFTER loading the key or you will have to do this every time.


Tuesday, June 18, 2013

How to change nginx root directory

Update the /etc/nginx/sites-enabled/default file -- change the document root directive in the server section

 server {  
     #listen  80; ## listen for ipv4; this line is default and implied  
     #listen  [::]:80 default ipv6only=on; ## listen for ipv6  
     root /usr/share/nginx/www;  
     index index.html index.htm;  
 ...

By default the root is installed in /usr/share/nginx/www.


How to restart nginx after updating configuration

The best way to restart nginx server after updating the configuration (/etc/nginx/sites-enabled/default or /etc/nginx/nginx.conf) is to not restart it at all. Instead, send it a kill command with the hangup (HUP) argument

# kill -HUP `cat /var/run/nginx.pid`

/HUP
...
     name. There is no default. Typing kill  does not send a sig-
     nal  to  the  current  job. If the signal being sent is TERM
     (terminate) or HUP (hangup), then the job or process is sent
     a CONT (continue) signal as well.

Code Formatter for Blogger / BlogSpot

I've been using http://codeformatter.blogspot.com/


apt-get install gives 403 Forbidden on Ubuntu 12.04 LTS EC2 Instance

I was unable to use apt-get install to install nginx on a fresh Ubuntu 12.04 LTS EC2 instance. Apt-get was returning 403 Forbidden for the ec2 ubuntu connections.

The error looked like:

 Reading package lists... Done  
 Building dependency tree  
 Reading state information... Done  
 The following extra packages will be installed:  
  libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx-common nginx-full  
 Suggested packages:  
  libgd-tools  
 The following NEW packages will be installed:  
  libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx nginx-common nginx-full  
 0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.  
 Need to get 403 kB/882 kB of archives.  
 After this operation, 2,691 kB of additional disk space will be used.  
 Do you want to continue [Y/n]? y  
 Err http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx-common all 1.1.19-1ubuntu0.1  
  403 Forbidden  
 Err http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx-full amd64 1.1.19-1ubuntu0.1  
  403 Forbidden  
 Err http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx all 1.1.19-1ubuntu0.1  
  403 Forbidden  
 Failed to fetch http://us-east-1.ec2.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx-common_1.1.19-1ubuntu0.1_all.deb 403 Forbidden  
 Failed to fetch http://us-east-1.ec2.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx-full_1.1.19-1ubuntu0.1_amd64.deb 403 Forbidden  
 Failed to fetch http://us-east-1.ec2.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx_1.1.19-1ubuntu0.1_all.deb 403 Forbidden  
 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?  

The solution was to run update on apt-get

 sudo apt-get update  

For more details, see: https://bugs.launchpad.net/ubuntu/+bug/987182