This is the technical scribble pad of Kit Sunde, a freelance software developer doing web things. I'm for hire: kitsunde@gmail.com

Text

thisadvertisinglife:

Source: thisadvertisinglife

Text

I wanted to get all the addresses registered to the ELB so I could work with fabric on the servers based on them being in the LoadBalancer. It’s a bit cumbersome. I ended up with this:

    import boto
    from boto import regioninfo
    from boto import ec2

    ACCESS_KEY_ID = '*****************'
    SECRET_ACCESS_KEY = '*************'

    elb_region = boto.regioninfo.RegionInfo(
        name='ap-southeast-1', 
        endpoint='elasticloadbalancing.ap-southeast-1.amazonaws.com')

    elb_connection = boto.connect_elb(
        aws_access_key_id=ACCESS_KEY_ID, 
        aws_secret_access_key=SECRET_ACCESS_KEY, 
        region=elb_region)

    ec2_region = ec2.get_region(aws_access_key_id=ACCESS_KEY_ID,
        aws_secret_access_key=SECRET_ACCESS_KEY, 
        region_name='ap-southeast-1')

    ec2_connection = boto.ec2.connection.EC2Connection(
        aws_access_key_id=ACCESS_KEY_ID, 
        aws_secret_access_key=SECRET_ACCESS_KEY,
        region=ec2_region)

    load_balancer = elb_connection.get_all_load_balancers(load_balancer_names=['MediaPopClients'])[0]
    instance_ids = [ instance.id for instance in load_balancer.instances ]
    reservations = ec2_connection.get_all_instances(instance_ids)
    instance_addresses = [ i.public_dns_name for r in reservations for i in r.instances ]

Text

Like last time another issue was a bz2 not being available even though on the system it was.

yum bzip2-devel
wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -zxvf Python-2.7.2.tgz
cd Python-2.7.2/

Then configure python to be built absolute path of the virtualenv:

./configure --prefix=/var/lib/jenkins/.virtualenvs/clients/
make
make install

Text

We’ve set up a new build server at work and for some perplexing reasons the virtualenv python was missing support for sqlite3, even though the system python had it. Although the system python still had sqlite3. We need to make sure the dev package of sqlite3 is installed before compiling.

yum sqlite3-devel
wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -zxvf Python-2.7.2.tgz
cd Python-2.7.2/

Then configure python to be built absolute path of the virtualenv:

./configure --prefix=/var/lib/jenkins/.virtualenvs/clients/
make
make install

Done. :)

Text

The chrome API lets you manipulate the size of a window through the chrome.windows.update method, however there’s a bug (#50138) where if a window is maximized then it won’t resize and there doesn’t appear to be a way to unmaximize a window.

The only solution I can think of is to create a new window which start unmaximized with the desired dimensions and then moving the tabs over to the new window. Here’s some example code I threw together which should maintain the state from one window to the new one:

Text

I previously wrote how to do this under Maverick. Another Ubuntu release is out with OpenJDK, here’s how to replace it with Oracles JDK:

sudo add-apt-repository "deb http://archive.canonical.com/ natty partner"
sudo apt-get update

sudo apt-get install sun-java6-bin sun-java6-jdk sun-java6-jre sun-java6-plugin

sudo update-java-alternatives -s java-6-sun

Text

The configuration example both on the Django website and on the mod_wsgi site itself shows a configuration where you set up the wsgi script to refer to an absolute path. That seemed like unnecessary configuration to be done every time I’m going to setup a Django site. Instead I created one where the path names are relative to the file instead. In my case the file resides under /etc/myproject/mydjangoproject/apache/django.wsgi, so I ended up with this:

import os
import sys

""" For safetys sake we don't want to import just 'settings' so we add the
parent dir for safer a safer import."""

paths = [
    os.path.normpath( os.path.join( os.path.dirname(__file__), "../" ) ), 
    os.path.normpath( os.path.join( os.path.dirname(__file__), "../../" ) )
]

sys.path.extend( paths )

os.environ['DJANGO_SETTINGS_MODULE'] = 'deals.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Text

Every once in a while I run into an issue where the remote host server identification has changed because of a re-install or other reasons. This comes with an error like:

$ ssh root@127.0.0.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
2c:af:ca:27:89:36:c0:03:c6:9f:43:74:1e:8e:3a:0d.
Please contact your system administrator.
Add correct host key in /home/kit/.ssh/known_hosts to get rid of this message.
Offending key in /home/kit/.ssh/known_hosts:44
RSA host key for 127.0.0.1 has changed and you have requested strict checking.
Host key verification failed.

In Ubuntu you can fix this by running ssh-keygen with the -R flag, removing the key causing the problem.

$ ssh-keygen -R 127.0.0.1

Text

I had an issue where I was building fade transitions between pages for a client, so I needed to update the title. I was using jQuery for a bunch of things so naturally I would do something like:

$("title").text("Wooo. New title!");

This works great in Chrome, Firefox and IE9, but not in IE7 or 8. Thankfully IE9 has a debugger so it was easy switch the browser into compatibility mode and trace the exception.

Turns out in older versions of IE the title element is magical and wasn’t letting jQuery appendChild (I’m also a bit surprised they aren’t checking this condition.) Instead old DOM0 comes to the rescue, which lets you set a title like so:

document.title = "Woo. New title!";

Text

I’m a bit frustrated that Canonical decided to use OpenJDK, even though OpenJDK still seem to have issues with some software. In my case I was trying to run PyCharm a popular Python IDE, but it wasn’t rendering properly. Lets tell Ubuntu to use Sun JDK instead:

sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
sudo apt-get update

sudo apt-get install sun-java6-bin sun-java6-jdk sun-java6-jre

sudo update-java-alternatives -s java-6-sun

Until the next Ubuntu upgrade. :)