Currently Browsing: My Coding

BloggerBuddy: Update to v0.5.1

The last couple of days my friend Sire brought to my attention a small problem on BloggerBuddy. There was a conversation on the update post here about it. What was happening is that on the individual feed view, i.e. when clicking on a specific feed to view posts from that blog only, the posts would be randomly ordered rather than ordered by date, as they should be. I also noticed that the same thing happened when you would do a search. Thanks to him i took another look at my code and i found out that i had a small problem. I fixed it and decided it is worth releasing a small update. This is now on version 0.5.1. All you need to do is visit BloggerBuddy’s site and download the latest .air file. Run it and it will update the program. Beware though! Make sure you keep a copy of the data.db file because the installation will inject an empty one! After updating then just put it back replacing the blank one. More on the update process here.

Thanks Sire! Oh, and sorry for doubting on the beggining. Also, stay tuned for more on BloggerBuddy, since i am planing a small “hack it” post.

Quick URL parsing using Perl

Have you ever stumbled on a page that you would like to copy-paste all the links from and, darn, they were many? For instance when you get that directory listing and you want to download all the files? Well, i faced the problem these days. I wanted to copy more than 30 consequtive links from a directory listing and i thought that it’s plain stupid doing it by hand. Now, the first thing that popped into my mind was a FireFox plugin. I started looking here and there and every one of those had something i didn’t like. So, then it came to me. I would copy the page source and then use a little Perl script to extract those links. Sounds hard? Well it’s not since Perl is the right thing for this job. So, a little tinkering here and there and this is what i came up with.

  1. #!/usr/local/bin/perl
  2. package MyParser;
  3. use base qw(HTML::Parser);
  4. $prefix = "http://a_site_do_use.com";
  5. sub start {
  6.         my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
  7.         if ($tagname eq ‘a’) {
  8.                 print $prefix.$attr->{ href }."\n";
  9.         }
  10. }
  11. package main;
  12. $file = "urls.txt";
  13. open(URLS, $file);
  14. @lines = ;
  15. close(URLS);
  16. $html = "";
  17. foreach $line (@lines){
  18.         $html .= $line;
  19. }
  20. $parser = MyParser->new;
  21. $parser->parse( $html );

A quick explanation of it is this. We use the HTML parser that Perl brings in. It’s a pretty nifty tool. If you want to use this as is you need to check out two things. One is that the contents of the page to extract the links should be on a file “urls.txt” and the second is that if the URL’s are relative (just like the ones that apache produces on a directory listing) you need to add the full prefix on the “$prefix” variable. If you want to tweak it be my guest. It’s draftly written anyway. If you don’t feel comfortable with code then go for those plugins. They are pretty good. Just not for me.

So, i hope this helps out for you guys as it surely did for me!

PS: I know it can be written more effectively but it works so i’m done tweaking :)

BloggerBuddy: My approach to RSS readers

bannerI’ve been upsent for quite some time now. This is because i was onto something. I was learning the framework of Adobe AIR. It’s a quite nice tool for rapid desktop development with Web standards. You actually use Javascript and HTML to code desktop applications. In order to find my way around this new technology i needed a project. Some people find it convenient to learn by buying a book. What i do is i throw my self into some serious coding. That is my way of learning. So, i decided to go on with a project. It is called “BloggerBuddy” and it is an approach of mine on an RSS reader.  I have tried many readers before and they all organize feeds in a certain way which does not suit me. The one i liked the most is Google Reader but i wanted something to integrate on my desktop. Besides that, BloggerBuddy has another advantage. It is designed from a blogger (yup that’s me) for bloggers (and that is you!). It has a nice feature where when a post is marked as a “commented on”, next time it tries to fetch the latest comment. This way you will be able to easily track the activity on posts you want to see how the discussion goes. So, go on and check it out. If you find any bugs or you have any suggestions take a look at the “Feedback” button on the left of the homepage.

Other than that, i have about three posts in a draft state for quite some time and i want to post them soon. So, keep on visiting!

Delete post revisions without any plugin

You know i’m all for “If you can do it yourself then don’t use a plugin”. That goes, without saying, to my plugins too. So, i saw a plugin recently doing a very useful thing, cleaning up post revisions. But what is a post revision? Well, it’s a safety measure the WordPress team took since version 2.6.X to protect your writing from unfortunate circumstances that may occur. Moreover, it’s a way to have different versions of your posts. When you write you tend to delete and start over. At some point you might want to go back and see what your post looked like back then. Pretty much this is what post revision is.

But, when you are done with a post, you most probably will not use that ever again. So, think about having ten versions of a certain post, or even worse, ten versions of many posts. That’s a lot of unnecessary info and clutter for your database. To give you the whole picture, post revisions rest in the table that your actual published posts are. This is bad in two ways. One, it’s making it harder to index and make a query on the table. Even worse, when a query joins this table with another one then the result of the join will have a lot of junk lines, therefore, alot of no needed info. Two, imagine a post replicated ten times on your database. It could be like 60Kb or even, much more. Now that is alot of fragmented space. For this reason it’s a very good idea to remove post revisions.

The plugin can do the job for you but, as i already said, this is a trivial job and you can easily do it by hand. All you need to do is run a simple SQL query on your database and you will be done. Before going any further please make sure you keep a backup of your database for the scary moment that something goes wrong. Open your sql manager (either console or phpmyadmin or whatever you use to access your database). Run this query:

  1. DELETE FROM wp_posts WHERE post_type="revision";

You are done! Please make sure you type exactly this and nothing less or you might be in serious trouble. Now, just to improve things for you, you might want to delete all revisions that are older than a month. This is what you are looking for:

  1. DELETE FROM wp_posts WHERE post_type="revision" AND post_date="2008-11-18 00:00:00";

This deletes all revisions that are older than a week today. So, go ahead and get rid of all the clutter. When i did so, i reduced my database’s size by 1.2Mb! I know, impressive huh? Keep one thing in mind though, backups, backups and more backups. The more the better ;)

Search comments with “Search Reloaded”

This post will be a conclusion on the requests for plugins and tweaks requested over at Kim’s blog. Both her and a reader of her’s, SDK, requested on a small tweak on the plugin called “Search Reloaded”. The plugin does a very good job on serching posts for you. It actually enhances the search feature alot by sorting not by date but by relevance. To be exact it sorts with these criteria (and in this order):

  1. The posts having the keyword in the title.
  2. Then, if the keyword is in the content of the post.
  3. Finally by date.

It’s actually a pretty good approach, surely much better than the plain “sort by date” that WordPress has by default. The tweak that was requested was this. The plugin should search in the comments of a post too. That’s rather reasonable. Now, i can’t modify the plugin and let you have it from here, since the license is non-GPL. But i can post the tweak and you can do it yourself. So here it is…

(more…)

« Previous Entries Next Entries »