Sunday, September 21, 2008

iGoogle Sandbox for OpenSocial gadgets

#1: Register for your testing grounds http://www.google.com/ig/sandbox/

#2: Install the Developer Tools gadget and set up your optimal environment
http://tinyurl.com/5vwwaz
http://code.google.com/apis/igoogle/docs/igoogledevguide.html#dev_env

#3: Add demo friends (real people who sign up for your sandbox), if your gadget goes into the social realm and requests friends lists through API.(*)

#4: Use GGE (Google Gadget Editor) to write your experimental gadgets. Saves the trouble of uploading files to your own server, decent interface.
http://code.google.com/apis/igoogle/docs/igoogledevguide.html#gge

#5: Upload/manage gadgets through the 'My Gadgets' gadget that becomes visible after you've configured developer env (see #2)
Tip: If you're modifying and testing continuously, TURN OFF CACHING for your gadget


*: Currently, the iGoogle sandbox friends gadget is not working. It's not sending out any invitations or showing me the list of friends I've invited. I don't know what the devs get by ignoring the bug at the very entry point.

Thursday, September 11, 2008

Tag Clouds and Word Clouds

A tag cloud is something very new (considering the age of the technologies that it builds upon) but very catchy. It ought to be so, since it is simple enough to program and has great visual appeal.

Let's say you decide to display the 50 most popular tags for your pics or your articles or for what people search through your website right on your homepage.
You can do so using a long list.
You can do so using a more elaborate graph that plots the tags on their count.
You are, now, not far from being kicked by both who look for information as well as those who fall for aesthetics.

Nobody wants too much of facts. My day isn't gonna be any better looking through long lists and learning about occurence of each term and their spatial representation. Selfish me only wants to see them being of some use to myself. The tags should promote activity, not have people correlating their usage statistics to build their thesis. And that is where Tag Clouds drive home the point. They present the information in more novel ways; in ways that would catch your eye and become a navigational aid. One can find them on several websites and being used in many presentations where too much detail mean popping a sleep pill in your audience's glasses. Read the Wikipedia article for more.

They are really IMPRESSIVE to see and EXCITING to implement!

An article titled "Building Tag Clouds" by Jim Bumgardner (O' Reilly) piqued my interest into this stuff (On a personal note, I'd had a rough day and anything connecting back to my geeky days and ways was only waiting to be consumed). So I decided to implement a Word Cloud - something that takes in text, and presents the words visually weighted by their frequencies (much akin to the occurence of a tag). The method of operation was simple: Throw in any text and the rest is logic.

You get a nice word cloud. Put in random text, and its fun. Put in your emotions and its introspection. Put in your old diary entries and its retrospection.

Now only if my website server weren't down will I upload the slick file.
See and use SAoS' Word Cloud Generator. It uses regular expressions to extract individual words. The frequencies were extrapolated to font sizes using a log function, which helps to balance the graph visually otherwise some entries would be HUGE while some very small. The log function was a revealation, and its just plain maths! Spread the link around.

Friday, July 4, 2008

When users submit incomplete links, quite unknowingly so

I myself didn't notice this earlier...
If one creates a link to a page 'x.php' (e.g. <a href="x.php">), then the resolved address points to that page on the same website. To link to another website, you provide the full address, (e.g. <a href="http://www.saos.org/x.php">).
But if you provide www.saos.org or saos.org (no www) for the href attribute, the browsers don't transform it into an external link, quite logically so. It will point to yoursite.com/www.saos.org

This was something I came across while fixing up commenting on {ego}trips. If one put a sitename without http:// it would show up as a link local to our website, which is NOT welcome. There is nobody to blame, though.
Fixing this was simple, though. I just appended a http:// to those which were missing it, using PHP's parse_url() function.
Note: haven't checked, or tried to append www to the links without it.

//here is a sample list of links of varying types.
$urls = array('www.google.com', 'http://www.yahoo.com', 'microsoft.com', 'www.saos.org/x.php');

//here is where we transform, then output them
foreach($urls as $url) {
$parsed = parse_url($url);
echo '<a href="';
if(empty($parsed['scheme']))
echo 'http://';
echo $url;
echo '">'.$url.'</a><br />';
} //end of foreach loop
?>

Wednesday, July 2, 2008

exg anew

Started with exg - the 'thing' that drives {ego}trips on my website - once again, after almost an year. I was skeptical about getting a hold of the code again, but that wasn't much of a problem. I can easily understand my retard coding practices anytime.

I wished to make some changes, which I started to pen down (and simultaneously work upon a solution).
Change #1 was to put a 'latest uploaded galleries' listing on the homepage. Quite simple, isn't it? But again, generating relative rankings was a bit of a problem. There didn't seem any way that SQL would work. Ideal way to tackle it would've been through complex queries, but I chose to put PHP to use to do so.

That led me to discover some serious flaws in my earlier scripts, which notably had to do with relative ranking of image galleries (with respect to trips) and the consequent changes on enabling/disabling them. Not only did it lead to some errors but also exposed private galleries.

Then I came to realise that there was some problem in the clan page as well. Private galleries were also visible through the generated links. Fixed that as well.

By the end, my sheet was littered with headings:
Task
-Problem
--Problem
---Bigger Problem
----Added Problem
-Another Problem
--Existing Problem
-Still a Problem

Ended up jumping between code for about 3 hours. Quite a sudden change in my daily routine of idleness. Here's a small query to pull some stuff from the database. BEAT THAT!

select * from
(select @rn := @rn + 1 as rank, ptjoin.*
FROM (SELECT pm.perspective_id, pm.trip_id, t.trip_title, pm.title,pm.member_id,pm.member_name
FROM (
SELECT p.perspective_id,p.trip_id,p.title,p.member_id,p.created,m.member_name
FROM perspective p
INNER JOIN members m
ON p.member_id=m.member_id
WHERE p.trip_id = XXXX
)as pm
INNER JOIN trip t
ON pm.trip_id=t.trip_id
ORDER BY pm.created
) as ptjoin
) as rankedptjoin
where rankedptjoin.rank = XXXX;


Now I'll start with building the feature to upload docs for the trips, anything that helps.

Thursday, May 8, 2008

PHP Woes: Getting pspell to work

The pspell extension allows some language tools like spell checking and similar-word recommendations.

To get pspell working, Aspell is required. Aspell is an OpenSource spellchecker, that has become the preferred one, replacing pspell and Ispell. Only the name remains, pspell functions in PHP are waiting to be renamed to Aspell ones.

I'm listing out the following steps for a Windows-specific installation. This has nothing to do with the server you're using (IIS or Apache)


  1. Get the Windows port of Aspell from http://aspell.net/win32/ (v0.50.3 installer here)
  2. Alongside, download a language dictionary as well (English dictionary here)
  3. Install Aspell followed by the language dictionary

  4. Make aspell-15.dll and pspell-15.dll available to PHP by either
    • Adding your Aspell bin directory (C:/Program Files/Aspell/bin in my case) to system's PATH variable OR
    • Copying the files to your PHP folder (C:/PHP in my case), if your PHP folder is already listed in PATH variable OR
    • Copying the files to windows folder (C:/Windows/) or system folder (C:/Windows/System32/)

  5. Enable the pspell extension in your php.ini file
    • Open your php.ini (generally in the PHP root folder or in Windows folder)
    • Firstly, make sure you have pspell.dll in your extentions folder (configured by variable 'extension_dir' in php.ini)
    • scroll down to where your extensions are listed, and decomment (remove the semicolon) so it looks like extension=php_pspell.dll - doing so enables the extension
    • Parsing of the ini file is cranky on some systems, so make sure that the above line goes to top of other commented/disabled extentions.


  6. Restart your server. It reloads the PHP module, which in turn reads the ini file and loads respective extensions again.

  7. Test if working: Saving as little code as <?php $pspell = pspell_new('en'); ?> in a script, and executing the script should do it.