Posts Tagged ‘updates’

New features to akrish

Wednesday, September 12th, 2007

As I’ve been perusing other blogger’s sites, I’ve picked up some general trends that blogs seem to follow. I’ve been working on adding some of these features to akrish, which is partially why I haven’t been writing that much recently. Very briefly, here they are:

Archives: This is my third month of blogging, and I have a decent amount of articles on the site. The archives allow me, and other readers to browse articles by month. I really see this as a way for users to find my most recent articles.

Tagging: A work in progress (it’s running decently on my local server). I’m trying to enable tagging of articles so that users can browse articles based on tags. It’ll let users find the stuff that they’re really interested in. Hopefully I’ll finish this up this weekend and deploy it on the production server.

Comments improvements: A lot of blogs allow users to link to their website in their comments, so I jumped on the boat and did the same thing. there’s a weird behavior if a user doesn’t include a URL that I need to get around to fixing, but for the most part it works.

I also want to implement a more general search engine on the site, but I probably won’t get around to it for awhile (now that school’s really started I’m very busy). Are these features useful? Do they work as you want them to? Do they contribute to the blog? Any criticisms? Thanks.

August Music Recap

Wednesday, September 5th, 2007

A quick summary of my musical interests in August

What I’m Listening to (Albums):

Paramore – Riot

Mae – The Everglow

Lorene Drive – Romantic Wealth

Saetia – A Retrospective

Bring Me the Horizon – Count Your Blessings

Circle Takes the Square – As the Roots Undo

Daphne Loves Derby

Dashboard Confessional – A Mark, A Mission, A Brand, A Scar

What I’m playing (Acoustic):

Jimmy Eat World – Hear You Me

Taking Back Sunday – New American Classic

Dashboard Confessional – Standard Lines, This Old Wound

Daphne Loves Derby – Hopeless Love, Come Winter, Midnight Highway

Three Doors Down – Here Without You, Away From the Sun

What I’m playing (Electric):

John Petrucci – Glasgow Kiss (some of it), Wishful Thinking

Joe Satriani – Love Thing

As I Lay Dying – Confined

I’ve been playing a lot more acoustic guitar recently. I think it’s because my acoustic is on a stand right next to my desk, while my electric is in it’s case hidden away in the corner. At any rate, I’ve started playing and singing a lot more; it doesn’t sound that great but I’ve noticed improvement.

I just got the new Chiodos album today; September looks like it’ll be another good month for music!

Perl XML Parsing

Friday, August 31st, 2007

Originally, I built the framework for this blog entirely on PHP, using XML to store my articles, comments, and all other data (see this and this for a detailed explanation of the original structure). Unfortunately, this design didn’t lend itself to scalability or adding functionality in terms of XML parsing. In contrast, perl has a DOM-based parser that makes parsing xml nice and easy. I decided to have a go at writing an xml parser in perl that has identical functionality to the php one I’m using currently thinking that I’d be a lot easier to enhance my blog.

I’ll start off by briefly explaining both parsers. PHP’s is handle based, meaning that the parser object starts at the top of the document, and whenever it gets to a tag, it calls either a start tag handler, or an end tag handler. When the parser gets to text between tags, it calls a data handler. The parser is good for crawling a file top down, but it’s not that easy to use if you’re looking for specific tags scattered throughout the file. You have to have dummy handlers that don’t do anything and keep switching the handlers when you come across the tag that you’re looking for. It’s also not very good for counting the instances of a specific tag because you may have to use global variables (generally a bad practice that should be avoided if possible) as counters. What’s more, each handler function is essentially just an if/elseif ladder that does something depending on what tag it’s analyzing. What’s more, adding functionality meant changing every handler to recognize a certain tag, or to change behavior when at a certain tag. In my case, I had about 12 different handlers, things were really redundant, and adding functionality was enough of a pain that I just decided not to do it (not the right solution). Using the PHP parser lead to really sloppy code and made it hard to add features to the parser.

In contrast, the perl module XML::DOM is a DOM-based parser, it works a lot like javascript parsing of HTML pages. You can call methods like “getElementsByTagName”, “getAttributes”, and “getChildren” on any node to extract information from that node. It’s pretty simple, easy to use, and the online documentation at CPAN is very useful.

So why switch over from PHP to Perl when it involves hours of reprogramming already working code? For one, I want to add functionality. If I kept the parser in PHP, this would take a lot of time and cause me plenty of frustration. Now that things are in perl, adding a feature is a straightforward as writing a simple subroutine. What’s more, the perl parser eliminates all redundancies, I’ve modularized everything into subroutines so that I never have repeated code in my parser. My perl code is also a lot cleaner, I don’t have long if ladders, instead I have a hash that maps tag names to subroutines. Everything in the perl parser just seems a lot cleaner than that PHP one, and I don’t regret spending a couple of hours to fix up my code.

One of the cooler aspects of the perl XML Parser that I’ve written is that I’m using mutual recursion very liberally. I have a couple of main functions: one for generating the html for multiple stories, one for generating html for just one story, one for getting all the titles of the stories in a given feed, and one for retrieving the latest story it. The first two functions call a private parse_story method, which goes into the mutual recursion. Each tag name in the story is a key in a hash that maps tags to subroutines. I iterate through all the child tags, and execute that subroutine. Each of these subroutines spits out some html and then tries to parse all the children again, recursively. With this recursion, I only need one subroutine per valid tag name, and the XML is parsed similarly to performing recursive algorithms on a tree structure. To add support for a tag, I just have to add it to the hash table, and build it’s subroutine. With this mutual recursion, the parsing code is much simpler and a lot easier to build upon.

If you notice, all of my served pages are still in PHP, so how am I calling this perl parser from php? I’m using PHP’s shell_exec function, which executes a shell command and returns a string of all the output from that shell command. The perl parser returns a string of html that my web pages echo out to the client. I don’t think this is optimal in terms of performance because I have both php and perl running simultaneously, but I didn’t want to build my entire framework in perl, so it’s a hacked solution.

So perl’s the way to go for XML parsing. It’s relatively easy, and allows for maintainable code (unlike PHP’s parser). Unfortunately, perl’s not nearly as popular for web scripting as PHP is, so if I wanted to distribute this, I’d probably have to use a PHP parser. Anyway, I’ve had the perl parser running on the site for about two weeks now, and I haven’t received complaints or seen any bugs, so things seem to be working well.

A look ahead: Upcoming articles

Tuesday, August 14th, 2007

I’ve got a lot of ideas for articles that I want to write, and not enough time to write them all, so here’s a list of some of those ideas. Hopefully I’ll enough time to get around to all of them in the next couple of weeks.

1. Summer – a brief recap of my incredibly uneventful summer.

2. What I learned at Tellme – my first work-experience and what I took away from that (this will probably be a list). Naturally, I’ll only write this one when I finish my internship on Friday.

3. I’ve got another idea brewing that I’ll start working on soon. I can’t give away any other information because it’s a secret

4. Moving in and running a house – I’ll be moving off-campus this year, so I may end up writing about how my house-mates and I are coping with bills, chores, and everything else that comes with a house.

5. Running club – I intend to join the running club at school, so I’ll probably write something about joining, meeting everyone there, and the runs they go on.

There may also be some more album reviews and book reviews (if I find good albums and read books). The finance thread will probably be pretty stagnant for awhile saying I don’t know enough about the field and don’t have time to learn about it right now.

On top of all of this, I intend to make the design a little more intricate (maybe AJAXy, but definitely more dynamic). I don’t really like this new layout, but I’ll keep it for a bit, mostly because I don’t have the time or patience to make a new one.

New Layout

Saturday, August 11th, 2007

I finished a new layout/design for this site and uploaded all the images and style-sheet last night. It’s nothing too original, just like a banner image and left navigation images but the rest of the styling is done entirely in css. I wanted to make something a little more original, but I also wanted to change the older layout because it was pretty lame. I think this layout will change pretty soon, but it seems like a step up from the older layout.

I showed it to my dad this morning and he said that the fonts are hard to read. I think part of this is because I was designing on a mac, but it looks a little different on Windows. Well, let me know what you think. Does this layout make things hard to read? Is it a good layout?