September 2012
1 post
June 2012
1 post
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 ]
March 2012
1 post
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
January 2012
1 post
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. :)
July 2011
2 posts
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:
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
May 2011
3 posts
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()
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
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!";
April 2011
3 posts
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. :)
I’ve been stuffing a MySQL database with JSON and I wanted to output it to a file. One way is to write a script that makes a connection and saves it to a file, but that seems a bit excessive. The default format MySQL outputs a selection from the console is with headers and some cruft around it, with the -sN options you get it all of and get the raw output, then just pipe it into a file:
mysql -sN -uroot -e "select json from my_table;" my database >> myjson.json
With node.js 0.4.5 out it’s well over due to get aptitude to keep up with the updates:
sudo add-apt-repository ppa:jerome-etienne/neoip
sudo apt-get update
sudo apt-get install nodejs
March 2011
2 posts
Usually when I need to copy a database from one spot to the other I log into the server that has the original database and then SSH the data to the server that is supposed to have it:
mysqldump source_database source_table | ssh user@host mysql target_databases
However in this case I couldn’t get the server to connect to another server via SSH, so the command changes slightly. Instead we log into the receiving server and change our command to pull the data to us from the original database.
ssh user@host "mysqldump source_database source_table" | mysql target_database
I wrote a client that was sending emails over SMTP server and needed to debug it, but didn’t want muddle my way through setting up an actual SMTP server. Instead I found two convenient options. The first is to use python where you can starts a dummy SMTP service that prints to stdout with:
sudo python -m smtpd -n -c DebuggingServer localhost:25
Another option is to sign up for http://dummysmtp.com that offers a free dummy SMTP server, showing the emails on the web interface.
February 2011
1 post
Since I’ve been fiddling around with OpenCart lately and needed to run WordPress as well for another project I wanted to run WordPress on a different port than 80.
Step 1 - Download WordPress from WordPress.org.Go to http://wordpress.org/ and download the latest version. Unpack it wherever you need it. I unpacked mine to /home/celc/Dropbox/www/wordpress.
Step 2 - Make the apache user the owner of the wordpress folderThis always seems to be a bit of trouble when I run WordPress in Ubuntu thats caused by apache not having enough privileges to create files and do other things it needs. I’ve blogged about this before in relation to installing plugins.
Step 3 - Create a databaseWe need to create a database for WordPress. In Ubuntu we can just run.
Step 4 - Change apache2 settingsWe need a new config file in /etc/apache2/sites-available which will handle the connection on 8080.
Then we need to change /etc/apache2/ports.conf and make apache listen to 8080 by adding the following two lines.
Step 5 - Enable the site and restart apacheWe need to enable the site and restart the server before it’ll run properly.
DoneNavigate to your site at http://localhost:8080 and WordPress will step you through the installation process. Just follow the instructions on the screen and your site will be enabled on http://localhost:8080.
December 2010
7 posts
During installation of OpenCart you are required to have certain PHP extensions active one of them is cURL, if it’s not then install it like so:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Then we need to restart apache
apache2ctrl restart
Refresh the page if you are still on it and it should be working. I think OpenCart could offer up a more pleasant installation process by offering suggestions in the installation process itself on how to go about fixing minor issues like this.
If you’ve ever attempted to install WordPress on your own you might find that it’s asking for your FTP/SFTP credentials. A seemingly absurd prospect since it’s running on the server, and should be perfectly capable. What is happening is that the apache user doesn’t have write access to wordpress/wp-content, and WordPress is trying to get around that problem by using the FTP. So we need to find the user that is running apache:
Which gives: Now lets set the owner to the apache user Now you should be able to install plugins without having to set up an FTP.I wrote a chrome extension uploaded it to the Google extension gallery earlier today, and after installation it refused to work. Investigating showed an Unexpected Token ILLEGAL message, which if I trusted chrome occurred right after the DOCTYPE in the background page (yeah right).
What in reality is happening is that whenever JSON.parse encounters something which it can’t parse it throws that rather perplexing message (hey Google, at least tell me it’s the native JSON causing the error and not my own code). In my case I was using localStorage to store JSON strings and when there wasn’t a key (like when I uploaded my extension to the gallery for the first time and forgot to set default values) JSON.parse() will receive undefined and fail.
Though curiously it’s implemented so that it returns null on JSON.parse( null ), because the ECMA-262 Edition 5 standard says so, but JSON.parse( undefined ) throws. This also means that JSON.parse() fails in the same way with both getting a bad string like JSON.parse( “BADSTRING” ) as it does on JSON.parse( undefined ).
Doing a try..catch seems like the only reasonable way to avoid shooting yourself in the foot on bad/undefined data. I really don’t think it’s a good idea for a language that blows the stack every other second to use exceptions.
Google has a new policy for the chrome extension gallery where screenshots need to be 400x275 (or some larger multiple of that). I soon found out that ImageMagick -came to the rescue again with the extent command which when scaling a picture to a larger size will add padding to the image (you can use -gravity to decide where). So I ended up with this for producing the screenshot of an appropriate size:
There’s a bug (#20773) in chromium that causes content scripts to be unable to access frames. If you run the following snippet and the initial condition is true.
Then we get the output:
This was a bit of a bother since I was trying to find what the activeElement on a page was and that property sits on the document. So to be able to get the activeElement on pages with iframes I needed to do:
Instead I had to inject my script in all frames, which if you are using executeScript can be done like this:
So I changed the code to only check the current document and tell me when the bug is fixed: