Archive

Author Archive

Breaking down the insurmountable task of writing legacy tests in Symfony

November 3rd, 2009 admin No comments

If you’ve inherited an application written with the Symfony framework that doesn’t include functional tests (or you just plain didn’t write them to being with) it can seem like an insurmountable task to create any significant level of code coverage. I found myself in this position and felt overwhelmed by the task ahead of me.

Heeding the advice of my productivity guru: “don’t bite off more than you can chew” (thanks ma!), I used the following grep sequence to generate some organic milestones. Now I know the number of actions per module

grep -c "function execute[A-Z]" apps/frontend/ -R | grep ".php:" | grep -v ":0$" | grep -v "components.class.php"

Categories: Symfony Tags:

Trac-BZR: installing on Ubuntu/Debian

September 15th, 2009 admin No comments

A project I’m working on recently switched from Subversion (SVN) to Bazaar (BZR) for its Version Control System (VCS). Of the many things we didn’t like about Subversion (merging, line-ending conflicts, etc..), there were some things we’d grown to like, primarily the mature 3rd party ecosystem and its bread-winner Trac.Thankfully there are projects to extend Trac’s reach to other VCSs.

Of interest to me was trac-bzr. Since Bazzar has the power of Canonical behind it, a cursory glance at the “universe” repository shows a package named “trac-bzr”. However a closer look reveals that this package is quite outdated:

>apt-cache show trac-bzr
Package: trac-bzr
Priority: optional
Section: universe/python
Installed-Size: 156
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Original-Maintainer: Chris Lamb <chris@chris-lamb.co.uk>
Architecture: all
Version: 0.2+bzr31-3
...

This seemed like a bad idea, seeing as the main branch was already at r69.

Here are the instructions on installing the latest version:

1. Make sure you have bzr installed

sudo apt-get install bzr

2. Get the latest version of trac

sudo apt-get install trac

3. Get the latest version of trac-bzr, and put it in a revisioned directory.

bzr export ./trac-bzr-r`bzr revno lp:trac-bzr` lp:trac-bzr

4. Install the plugin

cd trac-bzr-r*
python setup.py install

5. Configure trac to use the plugin as described in the trac-bzr README

Categories: System Admin, Ubuntu Tags:

Prevent Symfony from ‘formatting’ request parameters

September 15th, 2009 admin No comments

I’ve been using Symfony for 2 years and I always though their formatting of routes was really cool. For example, if you want to generate a link to a specific action, you’d do something like this:

<?php
echo link_to('Name of Link', '@route_to_action?param1=value1&param2=value2');

And it would generate something like this:

<a href="/module/action/param1/value1/param2/value2">Name of Link</a>

However, for the first time, I found myself NOT wanting this behavior. I wanted:

<a href="/module/action?param1=value1&param2=value2">Name of Link</a>

I looked high and low, on and off for a few days. I finally found something in the forums, with a note saying it should be in the documentation, but isn’t.

<?php
echo link_to('Name of Link', '@route_to_action', array('query_string' => 'param1=value1&param2=value2');
64670 be
Categories: Symfony Tags:

Getting keyboard volume control working in KDE

September 4th, 2009 admin No comments

I recently switched from Gnome to KDE. One thing I noticed was the my volume up / volume down keys stopped working. The on-screen volume meter showed up, and reflected changes when I hit volume up or down, but it wasn’t changing my sound.

If I had kmixer open, I could see that the keys were manipulating the PCM channel, not the Master or Front channels. A Google search later turned up a ticket on Launchpad. Turns out all you need to do is right click on the volume icon in the system tray and select “Select Master Channel…”.

For me, “PCM” was selected. I changed it to “Master” and viola

Categories: Ubuntu Tags:

svn2bzr and symlinks

August 26th, 2009 admin No comments

I used svn2bzr to import an Subversion repository (via dump file) to a Bazaar repository. My code has some places where symlinks are used. After the import, the symlinks were converted from links to files with the contents:

link ../path/to/link

I ran this snippet to find all locations of this event so I could fix them:

find . -size 1k -exec grep -E "^link" '{}' \; -print

Hope that helps.

Update: Wrote a script that will remove the old links and replace them for you.

#!/bin/bash

if [ $# -eq 1 ]
then
DIRNAME=$1
else
DIRNAME=`pwd`
fi

broken_links=`find $DIRNAME -size 1k -exec grep -Es "^link" '{}' \; -print \
| xargs -l2 echo -e "" | awk '{print $2 " " $3}'`

echo -e "$broken_links" | while read line; do
link=`echo "$line" | cut -d ' ' -f2`;
target=`echo "$line" | cut -d ' ' -f1`;
relative_dir=`dirname $link`

cd $relative_dir; rm $link; ln -s $target $link
done
Categories: System Admin Tags:

Finding Out Your External IP Address from the Shell

October 11th, 2008 admin No comments

I’m writing a script that needs to know the external IP address of the current machine (ifconfig only gives the local network address)

wget -q -O - http://checkip.dyndns.org | html2text \
| sed s/Current\ IP\ Address\:\ //

What this does is:

  1. hit http://checkip.dyndns.org, silencing wget’s output and redirecting the downloaded file to stdout
  2. parse the html page as text
  3. get rid of the cruft (I was thinking about using a complex regex here, but the IP address prefix seems less of a dependency concern than the actual dyndns service)
Categories: System Admin Tags:

Why does my keypad reset my X server?

October 6th, 2008 admin No comments

For a while I’ve had this weird bug on my Ubuntu laptop where, while using an external keyboard, if I hit any key on the numeric keypad the current X server would reset. Incredibly annoying. What’s worse, is that I never really got around to “fixing” the problem, I just trained my right hand to not stray too far to the right. But of course, accidents happen, and this last time of losing work was the final “home loan that brought down the US economy”.

The problem originates somewhere between XGL and using your numeric keypad to control the pointer (known as Mouse Keys).

If you’re sure you don’t need XGL (check your xorg.conf first!), then simply remove it:

sudo apt-get remove xserver-xgl

And disable your Mouse Keys:

  1. System -> Preferences -> Keyboard
  2. Mouse Keys (tab)
  3. Uncheck “Allow to control the pointer using the keyboard”

Now restart your machine, and Voilà

Categories: Ubuntu, Uncategorized Tags:

Subversion: undo files marked for deletion

July 21st, 2008 admin No comments

Problem: While in Eclipse, my finger and thumb lost coordination and I accidentally dragged a folder up the file tree to a another folder. Since I have Subclipse installed, it automatically maked my changes for “addition” and “deletion” from the repo. A simple svn revert on the parent directory was not enough.

Solution:  For some reason I’m used to Subversion commands being recursive by default (guess I’m used to doing a lot of updating?). This is apparently not the case with revert. You need to explicitly indicate the -R [ --recursive ]  option

To revert an entire directory:
svn revert --recursive <directory>

Categories: Uncategorized Tags:

OpenSolaris: Getting WPA ‘to work’

May 11th, 2008 admin No comments

I was eager to try out the new release of OpenSolaris (release Indiana I think). Popped in the LiveCD, got a nice boot menu, was greeted by a HUGE license agreement dialog, and the next think I knew I was up and running in a nice Gnome 2.2 Desktop (laptop?) environment.

There was even a convenient and deceivingly helpful little WiFi network prompt that showed me all of my local networks. I found mine, and clicked connect. The screen went away, I assumed I was connected, but alas to not avail, I was not.

For some reason, the little WiFi tool (that shall remain nameless) could identify that my network used WPA security, but couldn’t connect to it. Helpful, but only in a deceiving way. At first I didn’t think much of it. Even Ubuntu has its WPA woes a few releases ago.

So then I embarked on the “chicken-egg-chicken-egg” scenario of downloading drivers from the internet that enable my computer to connect to the internet. One Ethernet cable and a Google search later, I found the OpenSolaris laptop support page with a mini tutorial on how to install the wpa_supplicant (again, very reminiscent of the Ubuntu olden days).

Got everything downloaded and installed, but when I tried to start the wpa_supplicant daemon, I got this nasty, brutish error:

ld.so.1: wpa_supplicant: fatal : libssl.so.0.9.7: open failed: No such file or directory

“Okay” me thought to myself, “I need libssl”. But when I went to check, I sure enough had OpenSSL already and its version was 0.9.8a

At this point I was crying and screaming on the floor. My new toy wasn’t going to work. Why does this always happen to “me”?!? The last thing I wanted to do was start symlinking “shit” around in an OS I wasn’t familiar with.

What happened next is what highlights a fundamental difference b/w men and women (note: I am man). A woman by the name of Karen Tung simply asked how to fix this problem on an OpenSolaris forum. I guess its like the proverbial “let’s stop and ask for directions”…”go to hell, I’m not lost” scenario.

Here is the solution, reposted in its infinite glory:

# from the terminal...
# change to the root account.
# the root pw on the livecd is 'opensolaris'
su root
dladm create-secobj -c wpa mykey
# enter your psk twice
dladm connect-wifi -e "<essid>" -k mykey <interface>

If you don’t get any “shitty” feedback like a segmentation fault, you should get that overly persistent, initially deceiving WiFi dialog popup (within a few minutes, hang tight). Find your ESSID you entered above, enter your psk ONE MORE TIME and you should be cool. You should receive a dialog confirmation saying something like

Brought interface interface up, got address xxx.xxx.xxx.xxx

Now you can post on your blog from the liveCD…like someone I know…

Categories: Uncategorized Tags: , ,

OpenSolaris: Not so fast

May 7th, 2008 admin No comments

Long story short:

  1. Sun says: “OpenSolaris is desktop ready”
  2. Out-of-the-box: no decent (WPA, etc) WiFi support
  3. Manageable until: you realize OpenSolaris needs an internet connection to “function properly”.

Just upgraded to Ubuntu 8.04. Leave “desktop readiness” to the experts.

Categories: Uncategorized Tags: