TiddlyBlogger - publishing blogs created in TiddlyWiki to online blog

October 1, 2007 by boycook

Continuing on from my RSS reader TiddlyWiki frame of mind, I thought that it would be cool to be able to something similar with writing blogs.

My idea stems from the fact that TiddlyWiki is perfect for offline working.

So to set the scenario you you’re working offline, but you want to write your blog: you may be on the train to work, you may on a bus, you may be in the office where you cannot connect to the internet etc. There are hundreds of different circumstances.

What I want to create is a plugin that will enable you to write your blog into a tiddler, and then when you’re online do something like ‘click to publish’ and then this will post your blog into your blogging account (e.g. WordPress, blogger etc).

So I’m currently trawling the internet looking for any web services that allow you to publish blogs. This way I can create a direct interface in TiddlyWiki and will have no need to create any middleware (or server side code). I’ve found a few API’s (WordPress for example has one), but I’d like to avoid having to write any server side code.

If anyone has any ideas/resources that they think will help please let me know.

I’ll keep you all updated with my progress.

RSSWiki or TiddlyBlog - pulling RSS feeds into your TiddlyWiki

September 26, 2007 by boycook

When I first looked at TiddlyWiki I thought that this would be really cool to use for blogging.

So recently I’ve started to fiddle with creating macros/plugins for TiddlyWiki and I came up with the idea of an RSS reader macro. What it does is pulls in blogs via RSS, and creates a tiddler for each blog, and then tags the tiddler to link it to a specific blog feed (e.g. ‘craigCookBlog’).

The macro I’ve created can either accept two direct parameters (RSSFeedURL, tagName), or if you pass in none it will look to a specific tiddler (RSSFeedList) which contains a comma separated list of RSS feeds and their tagNames.

At the moment it only works if the TiddyWiki is stored locally, I’m working on a solution for when it is stored remotely (i.e. on a server). I’m also working on a better way of adding RSS feeds to the list, but for the moment you get the principle.

You can check it out at:

http://www.craigcook.co.uk/samples/RSSWiki.html

P.s. Please tell me if you have any issues with this URL.

How do I see users presence on a website? (or How do I detect when a user closes the browser?)

September 24, 2007 by boycook

This applies to a website with the client/server relationship. The short answer to this is that you can’t (that I’m aware of anyway). Not properly using any web browser/server components anyway. You can however make a good attempt at it. The problem is this situation is that the client and the server are not in permanent communication with each other, they are disconnected. I would also like to point out that there may be better ways of doing this, this is just a way that has worked for me in the past.

Let’s first set the scene. You have a website where users come and go. They log in and out. Now you want to be able to tell at any one time how many, and specifically which, users are logged in. There are many reasons for wanting to do this, the reason I first did was to create a messaging plug-in for one of my websites.

The easiest way of doing this is every time a user logs in you create an audit record (you could use application variables or write to a DB, it doesn’t really matter), and then when they log out you create another audit record. Then you can compare the records to tell if a user is still logged in.

This is fine if all of your users are nice people that actually bother to click ‘log out’ 99% of users will just close the browser or tab when they are finished, resulting in the users session remaining until it expires (usually about 20 minutes or so later). This is where the problem lies, and what we need to solve.

The solution lies in three areas:

  • An audit log (DB, application variables) to store who is currently logged in. Managed by having records for log in and out.
  • Capturing session start and end.
  • Calling the server to log the session end from the client.

The easiest way to work through this is backwards:

  • The last thing that needs to happen is the function that writes the ‘log out’ audit record is called.
  • This will be called by a function when the user session expired. This can go somewhere like the global.asax file (assuming .Net).

The next problem is that the session will still be alive until it reaches its expiry time. We need to force the session to expire early. This can be done by using the following code at the server level:

HttpContext.Current.Session.Abandon();

We now need to call this from the client at the appropriate time i.e. when the user closes the browser. Unfortunately there is no client-side (JavaScript) event that is fired when the browser closes. There is a:

window.close;

event, but don’t let this fool you. This only works for pop-ups, it doesn’t work for the main browser window. The closest events that do work are:

window.unload;

window.beforeunload;

So you could do something like:

Client JavaScript:

window.unload = funManageUnload;

var closeMe = true;

function funManageUnload()
{
if (closeMe)
{
//Make Ajax call to server

}
}

function navigateWebSite(url)
{
closeMe = false;
window.location.href = url;
}

Server C#

private void killSession()
{
HttpContext.Current.Session.Abandon();
}

void Session_End(object sender, EventArgs e)
{
//Logout code
}

private void logIn(string uName, string pWord)
{
//Login code
}

private void logOut(string uName)
{
//Logout code
}

public bool isUserLoggedIn(string uName)
{
//Compare audit records
}

Both those JavaScript events fire when a form unloads, which does happen when the browser closes. So you can set your code to call specific JS functions when these events fire. You now have to tackle working out when the form is unloading because the browser has been closed, or because of just normal website navigation. There are a couple of ways of doing this:

  • You can use frames in your website. By running the main site through a single frame within a parent frame and then change the child frame URL to different pages as you navigate your website. That way the parent frame will always be loaded and will only unload (or fire the window.unload event) when the browser is closed. The problem with this solution is that it makes searching your website hard. It also means that you cannot have direct URL’s to specific pages of your website (unless you pass in the page name via a querystring), which will mean that search engines (i.e. Google) will not be able to trawl your site. This isn’t really a problem if your site is for personal or company use.
  • Run ALL form submitting through one JavaScript function. You can use a variable to determine if the page is just navigating through the website normally, if set to true (as in the example above) you can make an Ajax call to the server to end the session. If it is set to false then do nothing because this is just normal website navigation. The problem with this way is that if you are using any additional form elements other than plain HTML (e.g. ASP.Net form controls) then there may be form submissions that you cannot trap with JavaScript (e.g. if you allow sorting on an asp:DataGrid)
  • You can use the ASP.Net pagemethods functionality. This allows you to call a function on the server from your JavaScript code. This can be used in the funManageUnload() function, and then the server side function called can kill the session etc. For more information on this see the website http://www.asp.net/ajax/

I’ve not aimed to give a definite solution to this problem, but I’ve hoped to give some pointers in directions that you can take. If anyone finds any better solutions I’d love to hear them.

Shaka, when the walls fell

September 21, 2007 by boycook

One of the fundamentally best ways of learning in life is by example. It’s interesting then to consider a race (the Tamarians in TNG 5×02 ‘Darmok’) that communicates entirely by example, or by metaphor.

‘Shaka, when the walls fell’ is an example of failure (presumeably a battle that went wrong). We can all do well to consider out failures and see what we learn from them. Although we can and do make mistakes the first time round, this is not reason to give up or feel disheartened, but we should view these times as an opportunity to do better. The best way to learn is by example, and if that example is our own we are only human, and although that means we can fail, it also means that we can do better.

‘Darmok and Jalad at Tanagra’ is further example of lessons learned in the pass (two men defeating a common enemy together). People working together will almost always be more benificial than people working alone, and the lessons learned together will again be more benificial than those just learned by oneself. This is an interesting double metaphor, because it suggests that example can be used to go forward in the future, and it itself is an example of this, but also understanding this will be a benfit to those learning it.

Proud to be geeks

September 21, 2007 by boycook

I’m going to keep this brief.

Several years ago Bill Gates said something like ‘be careful how you treat geeks, you may end up working for one’ (my girlfriend added ‘or married to one’).

How true this is. It seems that even without realising, more and more people are becoming ‘geeks’. Not necessarily in the classic sense of the word, but let me put it to you this way: how may people do you know that DON’T have a computer, how many people do you know that DON’T have an email address or mobile phone.

More and more people are finding technology interesting and fun. You get people reading such magazines as stuff and SFX, taking an interest in the later mobile phone and the latest TV series. Who would have thought that ‘Lost’ a Sci-Fi would have the attention of so many ‘normal’ people.

It really excites me that people seem to be finally embracing the advantages of science and technology, and that they are slowly becoming part of everyday life (blog is now almost an everyday term). I look forward to the advances we can make in the future.