Textmate bundle for RR test double framework

7 Jul

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

(what on earth is Git…)

  1. Run this:
  2. mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
    cd ~/Library/Application\ Support/TextMate/Bundles/
    git clone git://github.com/josephwilk/rr-tmbundle.git  rr.tmbundle
  3. Reload bundles in Textmate
  4. Enjoy!

Rspec Stories – Keeping Steps Dry

30 Apr

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'!
(more…)

JavaScript Acting as a Robotic Agent

23 Feb

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.

clientagent.JPG

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.

(more…)

Rails Admins Plugins Review

14 Feb

A brief examination of some of the major Admin plugins for rails.

  • Lipsiaadmin
  • AutoAdmin
  • ActiveScaffold
  • Hobo
  • Streamlined

(more…)

Automatic Admin Systems – Semantics with Rails & Django

18 Jan

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:

(more…)

Latent Semantic Analysis in Python

19 Dec

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:

This is an implementation of LSA in Python (2.4+). Thanks to scipy its rather simple!

(more…)

Building a Vector Space Search Engine in Python

27 Nov

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+). (more…)

Prolog ASLDICN Event Calculus Planner

23 Nov

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

(more…)

Running Prolog as CGI

23 Nov

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.

Prolog Functioning As CGI

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

23 Nov

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.

  1. class GetSetExample{
  2.  
  3. /**
  4. * Dynamic getters and setters than maintain getX and setX formati. They can be overwritten
  5. * if custom processing is needed
  6. *
  7. * @param string $method
  8. * @param array $arguments
  9. * @return mixed
  10. */
  11. function __call($method, $arguments) {
  12.  
  13. #Is this a get or a set
  14. $prefix = strtolower(substr($method, 0, 3));
  15.  
  16. #What is the get/set class attribute
  17. $property = substr($method, 3);
  18.  
  19. if (empty($prefix) || empty($property)) { #Did not match a get/set call
  20. throw New Exception("Calling a non get/set method that does not exist: $method");
  21. }
  22.  
  23. #Check if the get/set paramter exists within this class as an attribute
  24. $match=false;
  25. foreach($this as $class_var=>$class_var_value){
  26. if(strtolower($class_var) == strtolower($property)){
  27. $property=$class_var;
  28. $match=true;
  29. }
  30. }
  31.  
  32. #Get attribute
  33. if ($match && $prefix == "get" && (isset($this->$property) || is_null($this->$property)) {
  34. return $this->$property;
  35. }
  36.  
  37. #Set
  38. if ($match && $prefix == "set") {
  39. $this->$property = $arguments[0];
  40. }
  41. elseif (!$match && $prefix == "set"){
  42. throw new Exception("Setting a variable that does not exist: var:$property value: $arguments[0]");
  43. }
  44. else{
  45. throw new Exception("Calling a get/set method that does not exist: $property");
  46. }
  47. }
  48.  
  49. }