Monday, September 12, 2011

Alternative install script for concrete5

I've recently started moving the panto society's website over to concrete5 (the idea being to set up a nice easy to use CMS so that people who aren't me can maintain the website in the future). Overall, I've been pretty pleased with the software; it's certainly the easiest to use php based CMS I've ever used.

So far, I only have one gripe with it: concrete5 insists on being installed into an empty database. This was somewhat problematic for us, as our hosting provider only gives us one database, and I wanted to integrate the forums, etc, from the old site into the new one. I found a thread detailing a few kludgy hacks that could be used to get concrete to install into a non-empty database, and they seemed to work fine; I got everything up and running.

However, it would have been nice if the install script could have taken care of these issues by itself. So, in the spirit of open-source software, I've modified the installer to do just that. My modified script will allow concrete5 to be installed into a non-empty database. If the user attempts to do this, it first checks the names of the tables that are already in the database to ensure that no naming conflicts occur. If a naming conflict is found, it warns the user and refuses to install. Otherwise, it happily installs concrete5 alongside anything else that happens to be living in the database.

To use the modified installer, simply replace concrete/controllers/install.php with the version linked below, and then follow the standard concrete5 installation instructions.

http://dl.dropbox.com/u/1614464/concrete/install.php

Saturday, September 10, 2011

Poll Mod v0.1.2

Another minor release of my poll mod for punBB

Contains a few bugfixes:
  • Poll Admin panel now generates standards compliant html. The old admin panel displays fine in firefox, but not on chrome (I'd only tested on firefox). The new admin panel should display fine on all browsers
  • Improved installation script and instructions. Installation script will now perform the upgrade cleanly if version 0.1.0 or 0.1.1 is already installed.
  • Tested on punBB 1.2.23. Definitely works on all versions between 1.2.16 and 1.2.23 (previously had only been tested on 1.2.16)

http://dl.dropbox.com/u/1614464/robs_poll_mod/robs_poll_mod_0.1.2.tar.gz

Wednesday, September 7, 2011

Small script for fixing mp4box installation

Every time Xulrunner gets updated on my ubuntu box, my mp4box installation breaks. The reason for this is that installing mp4box from source (the only real option, since it's not available in the repositories, at least not on 10.04) requires updating /etc/ld.so.conf by adding a line like
"/usr/lib/xulrunner-1.9.2.22/"
So that mp4box can find and load mozilla's javascript libraries. The problem is that every time Xulrunner gets upgraded, the version number changes, and ld.so.conf needs to be updated again with the new version number. While this isn't actually hard, it is tedious, plus I always have to look up which config file to edit, find out the new version of Xulrunner I've just installed, etc.
It's just slightly irritating.

So I made a script. I saved the following in /usr/bin/mp4boxupdate

#!/bin/bash
sed -i.bak -e "s/\/usr\/lib\/xulrunner-[0-9.]*/\/usr\/lib\/xulrunner-`xulrunner --gre-version`/" /etc/ld.so.conf
ldconfig

Now updating /etc/ld/so.conf is just a simple matter of running "sudo mp4boxupdate"

Of course, the ideal solution would be if mp4box were available in the repositories - then the package manager could do all these updates for us. Until then, I'll just use this workaround.

Wednesday, August 17, 2011

A program for performing the Routh-Hurwitz stability test symbolically

Last week's tutorial for a control systems unit I'm taking at the moment consisted almost entirely of practising the Routh-Hurwitz method for determining polynomial stability. For anyone who's ever had to spend time constructing Routh tables, you'll know just how tedious it is. Which is why during that tute I spent my time much more profitably writing this small python program for calculating Routh tables.

Of course, there are already plenty of scripts/programs on the internets that can do this (eg this one, for Matlab/Octave). So why bother writing another one?

Well, firstly for my own education and entertainment. But also because the script linked above has many deficiencies. It is completely unable to deal with the case of symetrically distributed roots or marginal stability. Its method for handling the case of a zero in the first column is extremely kludgy. The correct way to do this is to replace the zero with a small quantity, epsilon, and then consider the limit as epsilon -> 0. The above script simply replaces the zero with the fixed quantity 0.01 - which is fine if your polynomial coefficients are on the order of 1 or higher, but not so fine if you have coefficients on the order of 0.001 or smaller. This is not just me being pedantic, either - these situations occur quite regularly.

Thus I decided to write my own python script. In order to handle all the arithmetic exactly (ie to avoid problems with floating point round-off) I decided to use the sympy library for python. You will need to have this library installed to run my script (on debian et al, it's just a matter of sudo apt-get install python-sympy). Using sympy has a further advantage - it allows symbolic variables to be entered as polynomial coefficients.

There are several classes of (useful) problem which are best solved through this approach. Eg this one
Q. A control system has an open loop transfer function of k/(s^3 + 3s^2 + s). For what range of gains is the unity feedback system stable?

You can solve this with my script easily enough. First deduce the closed loop transfer function (ie k/(s^2 + 3s^2 + s + k)). Enter the coefficients of the denominator polynomial when prompted (ie 1, 3, 1, k). This produces the output
1 1
3 k
1-k/3
k

For stability, all the numbers in the first column must be positive. Thus from the Routh table, we can conclude k>0 and 1-k/3 > 0 => 0 < k < 3

My script also works in the case where a polynomial has roots distributed symmetrically in the complex plane. This condition is indicated by a row in the Routh table consisting entirely of zeros. In these cases, the auxiliary polynomial is calculated, and the row of zeros is replaced with the derivative of the auxiliary polynomial. The program displays the auxiliary polynomial on-screen, allowing the user to check for the case of marginal stability (ie purely imaginary roots).

Here is the script:
http://dl.dropbox.com/u/1614464/routhHurwitz/routhHurwitz.py

Tuesday, May 10, 2011

A Youtube Uploader - the UNIX Way!

My university's pantomime society has recently started putting a whole lot of clips of its past shows up on youTube. And since I'm the resident "computer guy", I've been given the job of transcoding/uploading them all.

Transcoding was easy enough - just install ffmpeg, write a quick bash script, and we're done. On the other hand, there didn't seem to be an obvious way to automate the upload process.

What I really wanted was a program I could use from the terminal, something I could script. Ideally, I should also be able to schedule the uploads so that they ran during the middle of the night (when I'm not using the computer and my ISP doesn't monitor bandwidth usage). Googling didn't turn up any suitable candidates - there were a few youtube upload applications, but they were all windows only. And while I do still have a windows installation on my laptop, I didn't really feel like booting a different OS just to upload a few videos. I wanted something that worked on Linux.

So I did what any good hacker would do - I've written up a quick python script to do the job. I've tried to follow the UNIX design philosophy in writing the program. Thus it doesn't transcode video. It doesn't have a gui. The scheduling is handled using at. In summary, it does just one thing (uploads videos to youtube) and tries to do it well. But the end result is a program which can be combined with others to offer a lot of flexibility, and is easy to automate using scripting.

You can get the script here. You will need to download and install Google's gdata library for python, which you can get here. You can either elect to install the library as per the installation instructions, or else you can simply extract the contents of the archive into the same directory as the uploader script. To run the script, you will need python 2.6. The reason for this is that I'm starting to get into the habit of using the print function (instead of print statement) in python 2.6 to get ready for eventually moving to python 3. However, as far as I'm aware, the gdata library only supports python 2.x. Thus the only python version capable of running the script is python 2.6. If this is a problem, the print functions could be replaced with print statements, allowing the script to run on python 2.x (with x < 6). This is left as an exercise for the reader (which is of course code for "I'm too lazy to do it, if it's a problem do it yourself" :P ).

Finally, you will also need a YouTube API key. You can generate a key here. You will need to add this key to the uploader script. Open the file "youtubeUploader.py", and replace the text "YOUR API KEY HERE" (near the top of the file) with your newly generated API key.

There's still plenty of room for improvement - for instance it would be nice to have some indication of the upload progress while files are uploading. I might add this feature at some point, although I couldn't work out how to do it from the gdata documentation. Anyway, hope someone finds the script useful (if only as a demo of how to use the gdata api).

Monday, May 9, 2011

Poll Mod v0.1.1

This is a minor update to the 0.1.0 version of my poll mod for punBB 1.2. It contains a single bugfix. Previously, if anyone had a user name containing the character "@", they were allowed to vote multiple times, but not allowed to see the poll results. This bug has now been closed.Link

robs_poll_mod_0.1.1

Saturday, May 7, 2011

A quick script for concatenating MTS files

A small script I wrote to fix some problematic video files. In this case the problems were due to the design of the video camera I was using. Basically after recording 2GB of data, the camera was dumping whatever data it had recorded into an mts file, and then starting a new recording. While all the camera data ended up being recorded, problems arose with the second file, as the keyframe information was in the wrong place, etc. Basically, whoever designed the camera (some team at Sony) were morons.

Here's a simple script I wrote to fix their incompetence. Usage is mtscat -o output_file file1.mts file2.mts ...
Essentially does the same thing as "cat file1 file2 file3... > output_file" except that for the second and subsequent files it skips over the first 192 bytes (the header for the MTS stream)

Script is linked below:
mtscat.py

Saturday, January 1, 2011

Poll Mod for PunBB 1.2.x - updated version




An update to the punBB poll mod I hacked together a year or so ago - frankly, something that should have been done a long time ago. This update is a major redesign, although it recycles much of the code from the 0.0.3 release. Looking back at the old code is a little embarrassing, to be honest, and it's clear that I hadn't spent any time thinking about its design. This release introduces many new features, but more importantly doesn't feel like it was programmed by a moron.

Changes include
  • Code refactoring, more modular design, greater separation of mod code from punBB code
  • Support for php4 removed - php5 is now a requirement
  • Simplified installation procedure
  • Ability to restore database if uninstalled
  • Existing topics can be turned into polls
  • Ability to edit, close and delete existing polls
  • Poll permissions and colour scheme can be edited via the newly introduced admin console
  • Ability to restrict which classes of user have permission to create polls
  • n-1 polls now show approval ratings (ie percentages do not add up to 100, but results are more meaningful)
  • multi-lingual support
  • licence is now GPLv3, instead of LGPLv3
  • Various performance improvements and bug fixes
The database schema in this release has changed from that of the 0.0.3 release. The current release, and all future releases will write the poll mod version into the database, so that the installation script will be able to update existing polls if the database schema is ever changed again. Sadly, I wasn't so foresighted when I released 0.0.3, so if upgrading from 0.0.3, the database schema will need to be updated by hand. This is not too difficult, though - just create a boolean column "closed" which defaults to 0, and a varchar(200) column named "creator" in the polls table. The following (conf_name, conf_value) pairs then need to be added to the punBB config table:

  • ('rob_poll_version' , "0.1.0")
  • ( 'rob_poll_permission_level' , '1')
  • ( 'rob_poll_bg_colour' , '#FFFFFF')
  • ('rob_poll_bar_colour' , "#190A8F")
  • ( 'rob_poll_text_colour' , "#A0A0A0")
  • ('rob_poll_text_size' , "14")
Optionally, the data type of the following columns in the polls table can be changed as follows
  • question: change Text to varchar(200)
  • options: change Text to varchar(2010)
  • votes: change Text to varchar(110)
In future releases, I'll pay more attention to breaking the database schema. The version numbering convention will help in this regard - whenever I change the database schema in a backwards incompatible way, I'll update the minor version number (eg from 0.0.3 to 0.1.0)

The mod code and installation instructions are linked below. Thanks and acknowledgements go to Jan Odvarko, author of the jscolor script. This script is a javascript colour picker, which I have incorporated into the admin console - it is used to adjust the mod's colour scheme.

robs_poll_mod_0.1.0.tar.gz