Textmate bundle for RR test double framework
July 7th, 2008
A simple Textmate bundle for RR the Ruby test double framework. You can read about RR at http://github.com/btakita/rr/tree/master and look through the latest rdocs at Rubypub
Install with Git
- Run this:
- Reload bundles in Textmate
- Enjoy!
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles/
git clone git://github.com/josephwilk/rr-tmbundle.git rr.tmbundle
Rspec Stories – Keeping Steps Dry
April 30th, 2008
When using Rspec stories you have plain text stories which we call the ’story’ file and the ’story steps’ file that maps the plain text story to programmatic code. Generally you end up with your story files not being DRY. This is not a worry, your stories are the domain specific languages detailing your acceptance/integration tests. Its like saying that your Rails Models are not DRY because they repeat lots of 'has_one'!
Read the rest of this entry »
JavaScript Acting as a Robotic Agent
February 23rd, 2008
We can think of JavaScript running within a clients browser as a robotic agent. It has an environment in which it can sense things. The ability to look at the environment and make decisions based on plans.
So whys that useful, well why is a robot useful? You can produce many different complex plans and give them to the robot and forget about it while it does the work potentially over and over again. If we are really lucky the robot can demonstrate some intelligence and deal with uncertainty.
Well I tried out a small part of this idea to build a server side service which delivered plans in JavaScript to the client. The JavaScript planning agent followed the plans. Its not a intelligent robot but this is just a prototype. The plans where focused on validation conditions that a user needed to get through to post a form.
Rails Admins Plugins Review
February 14th, 2008
A brief examination of some of the major Admin plugins for rails.
- Lipsiaadmin
- AutoAdmin
- ActiveScaffold
- Hobo
- Streamlined
Automatic Admin Systems – Semantics with Rails & Django
January 18th, 2008
The Magically Appearing Admin
Web developers using an MVC framework produce their websites playing with their models, views and controllers. Then by adding a few lines of magic an admin system appears which allows users to add/edit/delete/view/search their models.
Examples:
Django’s Magic Admin (Also NewFormsAdmin – a branch of Django focused on making it easier to customise auto-admin)
Ruby on rails Plugins:
- Streamlined framework – http://streamlinedframework.org/
- Admin magic/config – outside of the models
- Auto-Admin – http://code.trebex.net/auto-admin
- Admin magic/config – inside the models
Latent Semantic Analysis in Python
December 19th, 2007
Latent Semantic Analysis (LSA) is a mathematical method that tries to bring out latent relationships within a collection of documents. Rather than looking at each document isolated from the others it looks at all the documents as a whole and the terms within them to identify relationships.
An example of LSA:
Using a search engine search for “sand“.
Documents are returned which do not contain the search term “sand” but contains terms like “beach”.
LSA has identified a latent relationship, “sand” is semantically close to “beach”.
There are some very good papers which describing LSA in detail:
- An introduction to LSA: http://lsa.colorado.edu/papers/dp1.LSAintro.pdf
- Creating your own LSA space: http://www.andrew.cmu.edu/user/jquesada/pdf/bookSpacesRev1.pdf
- Latent Semantic analysis: http://en.wikipedia.org/wiki/Latent_semantic_indexing
This is an implementation of LSA in Python (2.4+). Thanks to scipy its rather simple!
Building a Vector Space Search Engine in Python
November 27th, 2007
A vector space search involves converting documents into vectors. Each dimension within the vectors represents a term. If a document contains that term then the value within the vector is greater than zero.
Here is an implementation of Vector space searching using python (2.4+). Read the rest of this entry »
Prolog ASLDICN Event Calculus Planner
November 23rd, 2007
The event calculus planner used within my thesis was based on Dr. Murray Shanahan’s ASLDICN (Abductive SLD with Integrity constraints and proof by Negation) planner with compound action support. This planner is an adaptation from one published in one of Dr. Shanahan’s research papers
http://casbah.ee.ic.ac.uk/%7Empsha/planners.html
The original planner only supports the generation of a single plan. I needed to support conditional planning. I wanted the planner to generate multiple plans representing the different ways of reaching the goal. The problem was how to convert the planner to generate all possible plans. Importantly ensuring that this does not cause infinite looping and no redundant plan solutions are generated.
My version of the planner add the following features:
- Conditional Planning
- Impossible Predicate
- Occured And NotOccured predicates
Running Prolog as CGI
November 23rd, 2007
Prolog can be run as CGI by using a PHP wrapper script which invokes the Prolog engine from within PHP. Prolog can be invoked indicating Prolog files to load and goals to initially achieve once loaded.

Executing the following in PHP can spawn a process which runs Prolog.
$cgiOutput = `sicstus --goal $goal. -l "$cgiPrologScriptToLoad"`;
This specific example is for Sicstus but most Prolog command lines have a similar format. Another possiblity is to setup Prolog as CGI, since any langauge can be CGI. I was running my code on a windows box and found it impossible for Prolog to direct the content to the command line and capture it for returning. If you’re going the unix route you may want to look at
PiLLoWs guide.
For form postings you can catch the post in PHP or a scripting language and create a prolog formated file which is passed to the prolog script when invoked.
You may want to have Prolog maintain state. This can be achieved through using a database. The database that I have used is
Berkeley DB which SICStus has built in support for.
Dynamic Getter/Setters for PHP
November 23rd, 2007
We use the magic __call method in PHP which is called on an object when a declared function is called on it but it does not exist. This behaviour allows us to have default getters/setters but if we want specific behaviour for a get/set we just have to add the function to the class and __call will no longer be used for that class attribute.
class GetSetExample{/*** Dynamic getters and setters than maintain getX and setX formati. They can be overwritten* if custom processing is needed** @param string $method* @param array $arguments* @return mixed*/function __call($method, $arguments) {#Is this a get or a set$prefix = strtolower(substr($method, 0, 3));#What is the get/set class attribute$property = substr($method, 3);if (empty($prefix) || empty($property)) { #Did not match a get/set callthrow New Exception("Calling a non get/set method that does not exist: $method");}#Check if the get/set paramter exists within this class as an attribute$match=false;foreach($this as $class_var=>$class_var_value){if(strtolower($class_var) == strtolower($property)){$property=$class_var;$match=true;}}#Get attributeif ($match && $prefix == "get" && isset($this->$property)) {return $this->$property;}#Setif ($match && $prefix == "set") {$thisi->$property = $arguments[0];}elseif (!$match && $prefix == "set"){throw new Exception("Setting a variable that does not exist: var:$property value: $arguments[0]");}else{throw new Exception("Calling a get/set method that does not exist: $property");}}}



