OneWheeledBicycle

Random mutterings of Alastair James

Getting started with Neo4J REST API and PHP

leave a comment »

Hurrah! The excellent graph database Neo4J has made early steps towards escaping its embedded Java roots and behaving more like the client/server model most of us LAMP developers understand. Previous attempts to integrate Neo into PHP applications relied on complex PHP/Java bindings that meant that Java had to run on the same machine, or you had to write your own glue in between PHP and Java using some kind network protocol.

Now however, they have released an initial version of an official HTTP REST API. No more magic and glue. Just good old HTTP.

In order to simplify interacting with the Neo REST server from PHP, I knocked up a little PHP client library for it. Its early days for the Neo REST server and its even earlier days for the PHP client, so use with care!

Firstly, head over to the Neo wiki for information on how to get the Neo REST server installed and running. This will guide you through the basics of interacting with the REST API via HTTP using your web browser and command line tools (e.g. CURL).

Once you have it running and have poked it and prodded it using your webbrowser and / or the command line, its time to get going with PHP!

Getting started with Neo REST server and PHP

Head over to the github page for the PHP client and download it. If you are familiar with git, you may as well grab the latest version, otherwise I have zipped up a version here.

Make sure you have the Neo REST server running (its best to start the demo with a empty server so all the node numbers match my examples) and navigate into the directory where you downloaded the PHP client. Type ‘php demo.php’ to run the  demo file.

If all has gone well, 3 nodes will be added with relationships between then, and you will be presented with a textual diagram representation in the shell window.

To confirm it works, you can view the nodes in your browser (http://localhost:9999/node/1, http://localhost:9999/node/2, http://localhost:9999/node/3).

So, if it worked, I suggest you open the ‘demo.php’ script and see how it works!


Written by aljames

June 1, 2010 at 11:57 pm

Posted in Neo4J, PHP

HTML layouts. Ideal solution, idea 1.

with 3 comments

Following on from the CSS v tables for layout debate that is raging (continuously). As detailed in my previous post I feel that a HTML page is the combination of the content and layout. I.e. layout elements (multiple unnecessary divs in the case of CSS, tables in the case of table layouts) should be separate from the content. However that does not actually help with how to get your HTML laid out.

So I am going to mind dump a few possible ways layout could be done. These are not serious suggestions, just ideas.

The first approach is by far the most unlikely. Why? Well it requires extensions to CSS which, as we know, could take a decade to reach our IE6 using friends.

So the basic problem of layouts is that we want to divide our page into distinct areas. A typical layout might look like this (image from java2s.com):

This is called a ‘Border Layout’ (in java terminology at least). For example, you might want to have the header in the ‘North’ section, a sidebar in the ‘East’ section, your footer in the ‘South’ section and your content in the ‘Center’ section. You might not use all sections (i.e. we might not put anything in the West section) at which point it is not rendered. So this is a very flexible layout, able to do two and three columns, and can probably account for 95% of all web layouts out there. There are other basic layout types, and I think that with a few pre-defined layouts you could cover the vast majority of layouts with ease.

Imagine if we had a new CSS attribute in the body element:

body{
layout-manager: border-layout;
}

Ok, so we have said to the browser, we would like to render this page using the border layout model as detailed about. How do we add content to each section?


div#navigation{
position: layout;
layout-position: east;
}

Hmmm, easy hey? Using the CSS file we can assign page elements to the different layout sections. Of course the problem with this is that it limits you to a pre-defined set of layouts. You could probably use the CSS3 layouts module to define your own.

Written by aljames

February 5, 2009 at 11:09 am

Posted in CSS, Design

Page = Document + Layout

with 4 comments

The old debate of CSS v tables has flared up once again (see here and here). Its the same old arguments over and over. However, the very fact that this keeps coming around is evidence that both tools have problems. 

Generally, I think CSS is great at styling content. It was designed to style text based documents, you can see that from the DTP inspired terminology. For example, floats are designed to float paragraphs of text around images, not for making left and right columns on your page. In short, I think layout in CSS is a hack, using CSS for something it was not designed to do, exactly as using tables for layout is also a hack.

So we have to choose between two wrongs right? What would be the ideal situation?

Look at the average website. Most pages have common layout and header elements. Looking at the source code, often only a small fragment of the HTML is actually for content. The rest are ‘layout’ elements that are constant across most pages in the site. So I think, in essence a HTML page is the union of two components, the content (the document in my mind) and the layout (the navigation, header, the search bar thats on every page). Look at this site. Only one small area corresponds to content (the blog post area) and the rest is my overly large sidebar, header and flickr photo stream. Not to mention all the divs or whatever to float the sidebar to the right etc…  

Why is this a problem? Many non-standard uses of HTML (screen readers, search engine crawlers) have great problems separating the ‘content’ of the page from other secondary elements. SEO teaches us that we should have our ‘content’ as near to the top of the HTML as possible, and we have great fun trying to hack our CSS layouts so that order is unimportant in the HTML. Search engines also tend to devalue links in ‘layout’ elements (i.e. sidebars) compared to ‘in-content’ links. Why? Because a link in a layout element tends to occur on all pages in the site, where as a in-text link means that I am actually talking about that page there and then.

To me, this suggests that the most semantic solution would be to somehow separate the content from the layout elements. Therefore, each URI on the site corresponds to a small semantically relevant HTML document that is just the content for that URI. Layout elements could either be ‘included’ from external files in a similar way to the CSS @import directive, or marked as being ‘secondary’ content. 

You can achieve similar results on the server side by including document fragments in whatever server side programming language you wish. This is not quite the same though as the full document (including layout elements) is sent to the client. I want to be able to do it sending just the content. Interesting, good old fashioned frames actually allowed us to this. I.e. in a frameset I could have one HTML docuument for the content and one for the layout elements. However, frames are awful and have a bunch of usability issues.

Obviously this is a pie-in-the-sky idea as it would require a standard to be defined and incorporated in the browsers. That could take years, even decades in IE’s case. The debate on tables v CSS is centred around which tool is best to use today, not in the distant future. 

That said, I am looking at an approach to do this ‘layout functionality’  in javascript on the client before the page is rendered. Watch this space…

UPDATE: I realise I did not actually talk about HOW the layout might be achieved. Here is an idea (and just and idea).

Written by aljames

February 5, 2009 at 10:19 am

Posted in CSS, Design

Why I am digging the Malo CSS framework

leave a comment »

I recently found out about malo, a ultra small CSS grid layout library. When I say ultra small, I mean ultra small, 0.25k compressed! It supports various numbers of columns and page widths, and most impressively, nested columns. So if you need a CSS column library that works in all browsers, check it out. Its not as complete as Blueprint, but then, I think Blueprint has lost its way and tries to do far too much.

Written by aljames

November 18, 2008 at 7:49 pm

Posted in CSS

Please Google, can we have Google Maps API for iPhone?

with 13 comments

I have recently been experimenting with writing travel related web apps for the iphone. Its all great. Some of the HTML5 stuff in the new version of iPhone Safari is great (local databases etc..). However, one thing has been bothering me. I cant use Google Maps as I would like to. Ok, I can include links to the google maps site that open in the native google maps application, but this is not optimal because:

  • It takes the user out of my web application
  • Does not allow me to integrate the maps with my application. I.e. add many markers. Do something when a marker is clicked.

So this got me thinking, would it be possible to do a ‘lite’ version of the javascript maps API for the iPhone? Before the newest version of mobile Safari, this would not have been possible. Fundamentally you cant drag the map! However, with the new version Apple introduced a javascript API for sensing single and double finger drag events. 

So, I went about knocking up a very basic test version (try it on your iphone, tinyurl: http://tinyurl.com/3g5tg4). Is buggy, basic and sub-optimal, but proves it could work nicely. Try zooming with the double finger pinch action! 

I also tried the new webkit CSS transforms to allow free zooming and rotation, however they are buggy and slow on the iphone! Oh well! Anyway, maybe we can have google maps lite on the iphone?

Written by aljames

September 25, 2008 at 10:03 am

Posted in Coding, Google maps

Dropping pins in google maps!

with 5 comments

I am a big fan of the google maps on the iphone. I particularly like the way that the little pins drop from above and bounce. I wanted to find a way to do this in the standard google maps, and after a little hacking, I have found a way. Sadly though, the technique detailed here works only with the current version of maps. This is because it interfaces directly with the compressed google code, where the function and variable names are randomised (obscured) with each version increase. Thus, to make this work you need to specify the current version number (2.123) in the map file include.

Anyway, to cut a long story short, I figured, that as you can make markers bounce after you drag them, it should be possible to make them bounce in other situations. I was looking for an function named ‘bounce’ or similar, but it was a bit harder than that! After tracing the flow through the obscured maps code (!) I found that you can drop a marker from above using the following code:

// Make bouncable
if (!marker.Xa)
{
marker.Xa = true;
marker.qo(false);
}
marker.Pa = height; // Current height
marker.ri = height; // Max height
marker.av = 1; // Direction (+ = down)
marker.tc(); // Go baby!

Here is a demo. The markers also ‘hop’ when you move the mouse over them. In the source code there are three functions,  dropMarker, hilightMarker and dehilightMarker. Check them out!

Please, please, please google can we make a publicly available ‘bounce’ function?

Update: Sorry, the demo (http://www.worldreviewer.com/junk/iphone-map.html) seems to have stopped working. I think the API version that this worked on is too old and not supported anymore!

Written by aljames

August 21, 2008 at 9:40 am

Posted in Coding, Google maps

Only in Brighton…

leave a comment »

Written by aljames

May 20, 2008 at 5:19 pm

Posted in Uncategorized

Follow

Get every new post delivered to your Inbox.