Archive for Programming

Making sure your reader sees what you saw on Wikipedia

Dave Winer writes:

It’s valuable, it really is, I point to Wikipedia articles regularly, but always with an implicit caveat. I can’t be sure that the article I point to today, that I believe is accurate today, will be accurate tomorrow.

Ah, but you can.

Click on the history tab, then click on the most recent date. It gives you a URL of the version that is current, so if it changes in the future, you will still see the version that you were looking at today.

It even shows a set of links to navigate revisions.

For example, the current, as of May 25, Diffie Hellman key exchange.

But this is actually a problem for the Internet as a whole. For example, how do I find out what a Google search would have shown me a year ago vs today. Do they keep that kind of data?

Comments

Building KDevelop 3.3 on Suse 10

Since the search for the error message didn’t come up with anything useful (cannot find -lqassistantclient – Google Search), the solution is to install the qt3-devel-doc rpm. This is unintuitive because libraries and headers are usually in an rpm that ends in -devel, but that’s life in Linux.

Comments (3)

Hacking Seagull for Ajax support (with Rico)

Seagull is a PHP framework that is gaining popularity. One thing that it is lacking is AJAX support, but you can hack something together by going through the source files. Note that this should be fixed in the future because Seagull is being made more flexible, and will be able to support different output formats automatically.

I used the Rico (or OpenRico) AJAX Javascript library to handle all of the hard work, but the backend was lacking XML (or whatever arbitrary format) output. I wanted to stay within the framework for the output, because Seagull is handling things like user login, sessions, and permissions. If you don’t need this, just write a PHP script that outputs XML. :)

Normally when you make a custom class for Seagull, you extend the SGL_Manager class. We don’t want to this, because the data would then be passed to the Flexy template which is expecting HTML, and it’s a big mess.

Instead, we want to create functions that simulate how the SGL_Manager class works, in our own custom class.

So the functions we need are:

  • Constructor
  • validate($req, &$input)
  • _action((&$input, &$output)
  • process(&$input, &$output)
  • display($input, $output)

The constructor sets up the variables in the class. The _aActionsMapping variable must be set up here to dispatch the action to the correct page. If this doesn’t make sense, read up on creating custom Seagull modules.

Validate is required to process the page. It also sets up any variables that were POSTed as form values, or in the URL.

Your _action function is where things get done. Make sure you set the content type: header(’Content-type: text/xml’);. The data is output here with an ‘echo’ statement. Remember to format your XML properly. Firefox is great for debugging at this point because it will barf on bad XML.

The process function is copied from the SGL_Manager class but modified so that it doesn’t go through flexy:


function process(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);

$conf = & $GLOBALS['_SGL']['CONF'];
$className = get_class($this);

// don't perform checks if authentication is disabled in debug
if ($conf['debug']['authenticationEnabled']) {

// setup classwide perm
$classPerm = @constant('SGL_PERMS_' . strtoupper($className));

// if user has no class perms check for each action
if (! SGL_HTTP_Session::hasPerms($classPerm)) {

// ...and if linked methods to be called are allowed
foreach ($this->_aActionsMapping[$input->action] as $methodName) {

// allow redirects without perms
if ($methodName == 'redirectToDefault') {
continue;
}
$methodName = '_' . $methodName;

// build relevant perms constant
$perm = @constant('SGL_PERMS_' . strtoupper($className . $methodName));

// redirect if user doesn't have method specific or classwide perms
if (! SGL_HTTP_Session::hasPerms($perm)) {
SGL::raiseMsg('you do not have perms');
SGL::logMessage('You do not have the required perms for ' .
$className . '::' .$methodName, PEAR_LOG_NOTICE);

// make sure no infinite redirections
$lastRedirected = SGL_HTTP_Session::get('redirected');
$now = time();
SGL_HTTP_Session::set('redirected', $now);
if ($now - $lastRedirected < 2) {
PEAR::raiseError('infinite loop detected, clear cookies and check perms',
SGL_ERROR_RECURSION, PEAR_ERROR_DIE);
}
// get default params for logout page
$aParams = $this->getDefaultPageParams();
SGL_HTTP::redirect($aParams);
}
}
}
}

// all tests passed, execute relevant method
foreach ($this->_aActionsMapping[$input->action] as $methodName) {
$methodName = '_'.$methodName;
$this->$methodName($input, $output);
}
}

display is an empty function since we already did the displaying though the action function.

At this point, you will be able to point your browser to your custom module’s URL and get an XML page. After that, make sure your Rico code is pointing to this URL and you should see it show up in your page!

Comments (8)

Googlemapping the Election

With all of the Google Map trickery going on, I took some time out on the long weekend to see if I could combine Google Maps with Election data.

The first step was to get the GIS data for the ridings. I used wget to recursively download the data from this page, which are self-extracting zip files. Linux’s unzip utility easily took care of extracting the files. Apparently they are in a file format called ShapeView.

Then I had to figure out how to deal with the GIS data. There is an open source tool called ShapeTools that can extract data.

Now the problem is how to deal with the coordinate systems. I’m still working on this. Basically what I need to do is make a reprojection of the GIS maps from whatever coordinate system that they used, to decimal latitude/longitude coordinates. It’s in BC Albers format which is a BC specific format, so I’ll need to figure out how to use proj.4 to convert them.

I did get a working version of the BC Election GIS maps. Port 81 seems to be working now, so the public can see it.

My next step is to write a Python script to parse the data and generate an XML file that GMaps can understand.

Comments

Wikipedized version of the BBC

Yes, yes, YES! Another example about how your website can be infinitely more useful when you open the API:

Have a look at this example: BBC NEWS | Business | Glazer wins control of Man United

I don’t know exactly how it works, but basically the proxy inserts links to Wikipedia into BBC articles.

How is this different from Google’s Autolink which caused quite a stir in the blogosphere? The BBC is encouraging you to do this.

Comments

Why I like Linux

You’ll never see this in an MS document:

From Rusty’s Unreliable Guide To Locking:

Deadlocks are problematic, but not as bad as data corruption. Code which grabs a read lock, searches a list, fails to find what it wants, drops the read lock, grabs a write lock and inserts the object has a race condition.

If you don’t see why, please stay the fuck away from my code.

Comments

Robots with WRT54G

I was thinking last night, it would be pretty cool to make a mesh network with Linksys WRT54G running OpenWRT, where the routers are all mounted on some kind of robot, where they would repel each other to the point where signal strength started dropping off slightly.

Any new nodes that came online as users would cause the robots to move farther away from each other, making the network bigger as a result.

It would be a good Burning Man type of project.

Comments (2)

Colorization Using Optimization

Wow! This process is amazing: Colorization Using Optimization

Comments

SCCS, RCS, and CVS

For future reference, if anyone is still using SCCS and wants to convert, don’t use the sccs2cvs script that is floating around. For me at least, it did not preserve the revision history when it imported the files into CVS.

What I did was use the script from ESR’s website, sccs2rcs.

After adding the sccs path to the script (it couldn’t find prs, get, unget) it successfully converted the files to RCS, which shares the same repository format as CVS.

Then I used this rcs to cvs script to get the right tree format to put in the CVSROOT. There were a few more trivial instructions, but it all worked properly, with version information and everything!

Comments

The Fundamentals of Mapping Objects to Relational Databases

This may be useful when I try database programming.

Comments

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »