Synook

New name - Aspektas is born

As most people would probably have realised, this site has been experiencing extended downtime over the last month or so, which we sincerely apologise for, and which shouldn’t happen again. During that time we were able to contemplate a bit, and decided that our old name was rather long and clumsy. Therefore, we have created a new name for ourselves – Aspektas (“dimension” in Lithuanian). All services will proceed as normal, however.

And – do tell us what you think.

A concise Facebook API / PHP interface

Facebook has a client library for PHP to interact with its API, but I found it very bloated and inefficient with many redundancies. So I set out to make my own. My primary aim was to keep it very simple – with just a few functions to retrieve any data made available by the API in a simple format.

In the end, I came up with a small class. The constructor takes two arguments, the Facebook application’s public API key, and the private key (just like the original library). However, there are only two other functions – facebook::login(), which is similar to the original library’s FacebookRestClient::require_login(), but takes no parameters, and facebook::call().

Read more...

The Validator isn't the end

I’ve been very busy recently, so just to pass the time here is something interesting I found on the internet that shows the importance of human error-checking for HTML markup, instead of just relying on a DTD-based validator such as the W3C’s to validate the document.

http://www.webdevout.net/testcases/valid-but-wrong/html.php

Well, I suppose some of you may remember the days when the whole department only had one compiler, with the queue many hours long, and if there was something wrong with your code, you had to forfeit your place and manually debug – letting the machine do it just wasn’t a viable option.

The Mandelbrot set in Flash

I haven’t been writing things for a while, partly because I have been taking a break from web development to work on a renderer for the Mandelbrot set (more information on the actual set can be found at the Wikipedia article on the topic).

The algorithms used to generate the set are not complex, and can be found on the Wikipedia page. The method I used was the simple one – the escape time algorithm.

First, I attempted to write a simple JavaScript script that used the canvas HTML 5 element to draw the set. However, due to limitations in the computational power of browsers, the resulting application was rather slow. It works, though!

So, I had to look around for another programming environment. In the end, I chose Flash, because it has a ready-made interface for graphics through its Display object, it is fairly fast, and it is alot like JavaScript, meaning that my original JS code didn’t have to be changed much.

The final product can be viewed in the lab (requires Flash Player 9). The source can be downloaded from here. The program is not very complex – you can zoom in and out, and change the quality at the expense of efficiency, but you can’t pan. In my opinion, however, it is quite good, considering I have never used Flash or ActionScript before, and, well, it serves its purpose. Enjoy.

mail(), not mailto:

The mailto: pseudo-protocol seems to be a very popular method of mailing form data. May I point out it is not very efficient? The main problem is that the user is forced to open up their email client just to send the mail. Also, the format isn’t very good, and the to address is revealed.

Instead, you can use a simple server-side command in your preferred server-side language to send mail smoothly, and silently. The client doesn’t even know the data they submitted is being mailed, unless you tell them. You can even format the data any way you like, plain-text or HTML, and send it to anyone you want. Sound better than mailto:?

The PHP function is mail(). It takes three to five arguments – the to address, the subject, the message body, and optional headers (such as content-type), and optional parameters for the mailer program. If you want to send HTML mail, just set the content-type (and MIME) headers, Windows newline delimited.

The chaos game in <canvas>

This is just a small and very simple chaos game written in JavaScript for the <canvas> element. It works in Firefox and Safari. Just an experiment – I have been reading “Introducing Fractal Geometry” (Icon Books 2000 / Totem Books 2001), which looks like it is written for 12-year olds – with big illustrations and short, simple phrases – but can only be fully understood by university mathematics students (i.e. not me). At least I got the bit on the chaos game!

Good values are attractors: 3 and attraction: 1/2 (Serpinski Gasket) and attractors: 6 and attraction: 2/3 (Serpinski hexagon).

Using the location hash with AJAX

This technique describes how to use the location hash (the bit after the # in the address) to simulate different URLs within an AJAX-based navigation framework. The good thing about the location hash is that it can be changed without the page being reloaded, and having unique page names allows people to bookmark and directly access different parts of your site.

I will write generically in this article, as everyone probably has a differently coded navigation system. Anyway, the addition needed is very simple.

In the function that loads each page, you can store the argument that defines what content to load to the hash (available in the window.location.hash property).

function load(page) {
  window.location.hash = page;
}

This will make every page appear as a different URL in the address bar. Then, when you load the document, you check the hash and if there is something you call the relevant load() function.

window.onload = function() {
  if (window.location.hash.length > 1) {
    page = window.location.hash.split("#")[1];
    load(page);
  }
}

That was easier than even I thought.

Redirecting - status codes and client-side methods

There are many ways to redirect visitors to different pages, such as through redirection status codes, as well as throught client-side metas or JavaScript. But there is a place for each method! Too often I see metas used in cases (such as “we have moved”) where redirection codes should have been used, a 302 Permantently Moved in the previous case.

The client-side methods of redirection should only be used when the page being redirected away from has content that you want shown, for example, a landing page before redirecting to a file, such as Sourceforge does.

The main problem with redirecting on the client-side (besides users having to wait for an extra response body) is that search engines won’t follow the redirection, and therefore will continue to list the useless page, and user agents will also be unaware of the change. Sending a status code tells search engines and user agents exactly what the redirect is about, and therefore what it should do, that time as well as in the future.

Read more...

An interesting multi-selector in JS

I made this for selecting categories when writing articles in this blog. The same could be achieved using checkboxes or a select with multiple enables, but what’s the fun in that? Also, this fits on one line and can handle lots of options without tabking up too much space.

Read more...

Obtaining a Digg count independently

Digg (http://digg.com) provides you with many ways to integrate your content with it. The simple methods, however, are very inflexible, and it is necessary to look further in order to create a completely customisable method of counting Diggs, independant of the JavaScript code that the site provides.

Nevertheless, Digg has been very good in providing a very simple but useful API that allows us to in theory extract any Digg information that you find on their site for your own purposes. While not a web service in the traditional sense of the word, it is still easy to use with PHP.

Read more...