Monthly Archives: October 2008

fact.tv

FACT in Liverpool is more than just a cinema and today they’re launching a new website to showcase some of the work they produce, commission or display. fact.tv already has dozens of videos online so take a look at what’s on offer. Here’s a trailer to whet your appetite:

Browser security

My web browser of choice is Firefox. One of the appeals is the pile of add-ons that you can use to personalise the way you view the web. If I were recommending a browser, that’s the one I’d go for.

Opera Stay SecureAs a web developer, I also need to test how pages look in other browsers so I tend to have the most up-to-date versions of the common ones, IE, Safari, Chrome and Opera.

Yesterday I was looking at Opera’s widgets and noticed “Stay Secure”. Useful for very quickly displaying the current vulnerabilities of Internet Explorer, Firefox, Opera, Safari and Konqueror in an unobtrusive graphic on your desktop.

The information is provided by Secunia and by clicking on any of the browser icons on the the graphic the detailed report from Secunia is accessed.

So now, if you were to ask me to recommend a browser, I’d say Firefox, but use Opera (and the Stay Secure widget) for your secure transactions (if the site works in Opera ).

The Last Lecture

So I’m on holiday at the moment in some far flung country and I’ve been taking some time to read a few books.  Of course I asked my Twitter followers for some advice and Andrew Frayling from Cardiff University pointed me to The Last Lecture by Randy Pausch.  The book accompanies a lecture given by Randy at Carnegie Mellon University.  Many universities do these lectures where professors are asked to give a talk as if it was there last one – for Randy, dying of pancreatic cancer, it really would be.

If this sounds a little morbid, it’s not.  Go watch the video, read the book if you can.  You won’t regret it.

Aptana Outline Auto-Expansion Monkeyed!

You may have seen my last post Monkeying with my outline! where I apparently managed to get Aptana automatically expanding my outline whenever I viewed a new file in the editor. Well… it didn’t quite go to plan. Long story short, the script only executed properly when it was loaded after editing in the script editor, not when Aptana loaded up at the start. Details here in the Aptana scripting forum. I was rescued by Kevin Lindsey. Above and beyond the run of the mill support, he even emailed me to let me know he’d snuck the fix into 1.2. It’s working brilliantly! So now here’s my code with the updated bits from Kevin, I’ve commented out all the println’s cause I like a clean console.

/*
 *
 * Menu: EHU > HandlerService (Auto expand outline)
 * Kudos: Ingo Muschenetz & Kevin Lindsey & Steve Daniels
 * License: EPL 1.0
 * Listener: getPartService().addPartListener(this);
 * DOM: http://localhost/com.aptana.ide.scripting
 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
 *
 *
*/
 
function getPartService()
{
    var workbench = Packages.org.eclipse.ui.PlatformUI.getWorkbench();
    var result = null;
 
    if (workbench)
    {
        var window = null;
 
        runOnUIThread(function() {
            window = workbench.getActiveWorkbenchWindow();
 
            if (window != null)
            {
                result = window.getPartService();
                //out.println("result set to " + result);
            }
            else
            {
                //out.println("window is not defined");
            }
        });
    }
    else
    {
        //out.println("workbench is not defined");
    }
 
    //out.println("getPartService() is returning " + result);
 
    return result;
}
 
function partBroughtToTop(part)
{
  //out.println("part*()\n");
}  
 
function partClosed(part)
{
  //out.println("part*()\n");
}
 
function partDeactivated(part)
{
  //out.println("part*()\n");
}  
 
function partOpened(part)
{
  //out.println("part*()\n");
}
 
function partActivated(part)
{
  if (part.getEditorInput)
  {
    expandOutline();
  }
}
 
function partVisible(part)
{
  //out.println("part*()\n");
}
 
function partHidden(part)
{
  //out.println("part*()\n");
}
 
function expandOutline()
{
  //out.println("expandOutline()\n");
  try
  {
    //out.println("try\n");
    var editor = editors.activeEditor.textEditor;
 
    editor.getOutlinePage().getTreeViewer().expandAll();
  }
  catch (e)
  {
    //out.println("catch\n");
  }
}

Enjoy 🙂

Steve Daniels

Rose tinted json

Lately, we have been looking at providing a little automation to parts of the site which are less dynamic, by using some of the data serialisations that we create, with a sprinkling of javaScript magic.  Specifically we’ve looked at pulling Edge Hill event data, tagged with “rose theatre” into the Rose Theatre site.

This week I will be mostly using jsonCurrently events are added to the events Edge Hill events data, which can be duplicated. Our data serialisations come in four flavours, XML, JSON, PHP and YAML.

This week I have been mostly using JSON.

JSON is javaScript, and doesn’t need a server.  It runs on the site visitor’s browser (if enabled) and provides a way for us to access dynamic data and publish it on static web pages.

The first stage was to create the JSON feed.  Since Edge Hill already has data serialisations for Events and News, all I needed to do was to tweak it a bit and add a new function to the database to return events tagged with “rose theatre” and add a new URL to access the results which look something like this:

[{
	"title":"Alternative Stand Up",
	"slug":"alternative-stand-up",
	"summary":"Comedy at the Rose Theatre.",
	"content":"<p>Tickets \u00a35.50 \/ \u00a33.50 concessions<p><strong>Jamie Sutherland<p>One of the freshest and most natural talents to emerge in the last few years, Jamie has truly established himself on the comedy circuit, and is now very much in demand all over the UK.\u00a0 Liverpool born Jamie will keep you amused with gags, tall tales, and true stories garnered from everyday observational topics.<p><strong>Danny McLoughlin<p>Danny is a complete natural and destined for the top.\u00a0 Think Peter Kay for the confidence factor.<p><strong>Rosie Wilby<p>Rosie Wilby has been performing as a singer songwriter for many years and turned to comedy in 2004, storming through to the semi finals of So You Think You're Funny, on only her second ever stand up gig.\u00a0 In August 2006, Rosie unveiled her debut full length show \u2018Olympic Swingball Champion 2012' at Edinburgh Fringe.<p>Compere.....<p><strong>Ste Porter<p>A top class act who will be a regular comedy circuit favourite before long.\u00a0 See him in Ormskirk first!<p>For further information or to book, call 01695 584480 or email <a>rose@edgehill.ac.uk.",
	"start_date":"2008-10-07",
	"start_time":"20:00:00",
	"end_date":"2008-10-07",
	"end_time":"22:00:00",
	"location":7,
	"created_at":"2008-08-13 14:04:28",
	"updated_at":"2008-08-14 13:46:40",
	"building":"",
	"url":"http:\/\/www.edgehill.ac.uk\/events\/2008\/10\/07\/alternative-stand-up\/json",
	"tags":{
		"Stand Up":"Stand Up",
		"comedy":"comedy",
		"rose theatre":"rose theatre"
	}
}]

Next, add the following code to the html document into which you want to add the data feed:

<div id="rtevents">
  <h3>Next up</h3>
  <p>
    The Rose Theatre's <a href="/events/tag/rose theatre" title="List of events for the rose Theate">upcoming events</a>
  </p>
</div>

The div with the id of “rtevents” acts as a placeholder for the code which will be inserted. At this point, a level 3 heading has been applied with a link to the events page. This gives visitors without javascript capabilities a way of viewing the events (in this case a link to events for the rose theatre page).

In addition to the tags, the jQuery library was added. jQuery has a ready-made method for “getting” a JSON feed and the documentation is detailed, yet simple enough to get you started with a working example.  Using that example, I wrote:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  $(document).ready(function(){
    $.getJSON(/events/tag/rose+theatre/json”, function(data){
      $(‘#rtevents’).html(<h3>Next up</h3>);
      $(‘#rtevents’).append(<table id="”eventrow”"></table>);
      $(‘#eventrow’).append(<tr><th>Date</th><th>Event</th><th>Time</th></tr>)
      $.each(data, function(i,data){
        urldate = data.start_date.substr(0, 4)+/+data.start_date.substr(5, 2)+/+data.start_date.substr(8, 2);
        date =<td>+data.start_date.substr(8, 2)+/+data.start_date.substr(5, 2)+</td>;
        time =<td>+data.start_time.substr(0, 5)+</td>;
        time = time ==<td>00:00</td>?<td>TBA</td>: time;
        oddeven = i % 2 == 0 ? ‘even’ : ‘odd’;
        $(“#eventrow”).append(<tr class="”‘+oddeven+‘”">+date+<td><a href="”/events/’+urldate+‘/’+data.slug+‘”">+data.title+</a></td>+time+</tr>);
        if (i == 5) {// sets the maximum number of records returned
          return false;
        }
      });
    });
  });

Let’s try to explain what’s going on here (row by row). The whole thing won’t work unless javascript is enabled in your browser.

  1. Line 1: A jQuery function which runs the javascript that follows it after the html page has loaded.
  2. Line 2: A jQuery call to the JSON feed and a function call to to tell the browser what to do with the data.
  3. Line 3: Find the element with the id “rtevents” and replace it’s contents with our <h3> element.
  4. Line 4-5: Append the table (named; “eventrow”) and table headers to the “rtevents” element (following the h3).
  5. Line 6: For each event returned in the JSON feed, do the following:
  6. Line 7-11: Format JSON data for output.
  7. Line 12: Append the table row to the table (named “eventrow”) with all the formatted data.
  8. Line 13-15: restrict the number of table rows returned if necessary.

Knowing this, you can parse any JSON feeds using jQuery, and there are plenty to choose from these days. A few examples:

Fancy yourself as a javaScript developer? Then add JSON to your bow strings.

BathCamp – a BarCamp in Bath

September has been ridiculously busy both at work and in Real Life™ and now it’s time to play catchup and tell you, dear readers, what I’ve been up to.

First of all, skip back a few weeks and I went down to Bath for another BarCamp.

BarCamp is an ad-hoc gathering born from the desire for people to share and learn in an open environment. It is an intense event with discussions, demos and interaction from participants.

I’d already been to BarCamps in Leeds and Newcastle (BarCamp North East) but BathCamp seemed set to be a little different.  The idea of running a BarCamp in Bath was originally thought up by a bunch of Museums type people but after the initial idea, the event diversified a lot to include the wider geek community.  There were still a lot of museums and Higher Education people there, which was great – at other BarCamps I’ve been pretty much the only person from HE – but not so many to disturb the balance.

An early start on Saturday morning to drive down to Bath got me to Invention Studios before most people had arrived.  There was the usual scramble to get a slot – I bravely went for the after lunch session.

A brief summary of some of the sessions (thanks to Tim Beadle via Jack Martin Leith for the names):

  • Giles Turnbull: Why Web Advertising Sucks.  Great talk about how web advertising is different to print and a lot of people haven’t worked out how it works yet.
  • Brian Kelly: Time to start thinking.  Slides with a black background and no UKOLN logo – what’s going on here!
  • Tim Beadle: Techies are from Mars, Marketers are from Venus.  Interesting to hear a bunch of geeks talk about how marketing don’t understand but quite a lot of willingness to enagage, which is good.
  • Laura Dewis: Disrupting the University: Social Learning.  Intersting to see what’s going on at the OU.  I’m not always sure the cool stuff they’re doing makes it to the front line all that quickly (based on what I’ve heard a few students saying) but they really push the boundaries.
  • Mike Nolan: Learn to juggle/drop balls.  Not sure the people downstairs appreciated the constant thuds of people dropping balls but I enjoyed leading the session.  Some people picked it up really well, others could do with practicing a little longer!
  • Rick Hurst: The Gurgitator.  Crazy way of scaffolding a web application using any framework from a standardised configuration.  Not sure I’d use it but interesting to see!
  • Ian Ibbotson: Opening up academic publishing
  • Drew Jones / Stuart Lowes: sfImageTransform: an image-manipulation
    plugin for Symfony
    . sfThumbnailPlugin on steroids.  A bit like WideImage but more extendible and more symfony-like.  Release is due soon so worth keeping an eye out for.
  • Mark Ng: Delicious Pecha Kucha. 20 seconds to talk about each of your last 10 delicious bookmarks.

In the evening there was a pub tub quiz before decamping to a bar in a former railway station.  Sunday had a few more sessions.  Overall there was a really friendly atmosphere at BathCamp making it my favourite BarCamp so far.  Many thanks to the organisers and sponsors for making a great weekend.

Monkeying with my outline!

After having been here about 6 months I have finally succumbed to the pressure from my boss to make a blog post. Normally my ideas for such posts would be large and grand, take too long to type out, and slip into the infinite chasm that is otherwise known as a draft…

I like Aptana, I like the Outline view. What I don’t like is that you always have to expand it. So thus, I never used it, I’m simple and lazy, and not afraid to admit it. Andy Davies reignited my interest in the Outline view earlier today in a round about way. Andy pointed out the lesser noticed Scripts menu in Aptana. Specifically Experimental -> Colorize as HTML. A nice quick and neat tool. Not that I’d use it much mind. But then below its entry I saw “Expand outline”. Bingo!

What followed is my discovery of Monkey Script. I figured getting expand outline on a keyboard shorcut would be good, and perhaps renew my interest in it. But then I noticed the mention of listeners… Queue  a bit of creative Googlin and this post by Ingo on the PartService event handler.

Hacking the existing expand outline script into this proved painless so here we have it:

/*
 *
 * Menu: EHU &gt; HandlerService (Auto expand outline)
 * Kudos: Ingo Muschenetz &amp; Kevin Lindsey &amp; Steve Daniels
 * License: EPL 1.0
 * Listener: getPartService().addPartListener(this);
 * DOM: http://localhost/com.aptana.ide.scripting
 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
 *
*/
 
function getPartService(){
  window = Packages.org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
  if (window != null) {
    return window.getPartService();
  }
}
 
function partBroughtToTop(part)
{
 
}  
 
function partClosed(part)
{
 
}
 
function partDeactivated(part)
{
 
}  
 
function partOpened(part)
{
 
}
 
function partActivated(part)
{
  if (part.getEditorInput)
  {
    expandOutline();
  }
}
 
function partVisible(part)
{
 
}
 
function partHidden(part)
{
 
}
 
function expandOutline()
{
  try
  {
    var editor = editors.activeEditor.textEditor;
 
    editor.getOutlinePage().getTreeViewer().expandAll();
  }
  catch (e)
  {
    out.println("Failed to expand outline.\n");
  }
}

You’ll notice I hooked the Activated event rather than the Opened one this was because on opening expandOutline executed before the active editor had switched to the new file so the outline was expended on an already opened file. This way has a slight caveat that if you collapse the outline and then go back to the file it’ll expand it again, but that doesn’t bother me at all.

To use the above script simply drop it in a file with a .js suffix and place it in a folder called “scripts” in a project that is currently open on your workspace. I created a new project just for this purpose.

I hope someone found this useful 🙂

Steve Daniels