Archive for September, 2009

Planning to surf the Wave?

Wednesday, September 30th, 2009

Any self-respecting online crawler would know that Google Wave has started their private invitation-only beta. No, I don’t (yet) have an invitation. This does remind me of way back when GMail went through this phase. I obviously secured myself an invite early on (where early is relative) and switched over from Microsoft’s Hotmail to turn GMail into my mail provider and client of choice. However for quite a while now I’ve switched over from GMail and have been slowly erasing my Google identity. With this switch I have gained both flexibility, control, and more importantly – insight into my workflow.

The question I’ve been asking myself is: will I use Google Wave? Initially, I would say “sure why not? It’s revolutionary” – but truth be told, I’ve overestimated the hype.

Wave is a pimped web application. The question is not whether the web was built for this technology, because advances like this never are. The question is neither if I’d enjoy integrating Wave’s API into my blog and related websites. The question is if I can realistically see myself using Wave in my workflow?

Wave is a way to communicate and collaborate. At the moment I do all my communication through my blog, instant messaging, and my phone. I collaborate through version control, mailing lists, and Google Docs. Wave will not replace any single one of those, except perhaps mailing lists. Personally, and I’m sure this applies to others too, Wave is not something I will use to replace another in my workflow – instead it will add a completely new, unrelated workflow.

But what is this workflow? I see it in document collaboration for businesses. But honestly, I don’t see it in much else. I don’t see it in social networking (if I even used it). I don’t see it replacing any form of instant messaging. And I especially don’t see it invading the web with its API. The web is changing, yes, and changing fast. A website is a blank canvas that the user will accept anything and everything they see on it. This is very different from desktop applications – where a single out of place UI widget will provoke suspicion from the user. However despite the unlimited number of things you can do to a webpage – you simply can’t bond two of them together. You can’t make the user feel like its an integrated environment. Heck, sometimes it’s hard to make a single website look integrated. This is what I believe is the biggest setback, and the biggest weakness of what Wave is trying to achieve. This isn’t said from a selfish web-developer point of view, it’s coming from a person who uses the web just as much as the desktop.

What do you see Wave in? Will you surf the Wave?

Setting up FreeNX (nxserver-freenx) on Gentoo

Monday, September 28th, 2009

NX is, in laymans’ terms, some fancy technology that allows you to remote desktop control your computer. If you’ve used VNC before, where VNC simply works by sending screenshots over the internet, NX does cool stuff in between like compression that makes NX much faster and better.

NX is a pain to set up. Maybe it’s just my bad luck that something goes wrong every time I try to set it up, or perhaps I’m just plain stupid but I find it a pain and it normally makes me feel like chewing my ethernet cable after a while. A long while back I managed to get nxserver-freeedition working fine, but recently it stopped and in the process I decided to switch over to using FreeNX – an open-source implementation of NX. Here is how I got it up finally, mainly for archival purposes.

Before starting, you may want to clean your system. unmerge nxclient nxnode nxserver-freeedition nxserver-freenx, etc, rm -r /usr/NX (if freeedition), rm -r /etc/nxserver (if FreeNX), remove the nx user and the nx group, rm -r ~/.nx/ for all users.

  1. emerge nxclient
  2. emerge nxserver-freenx
  3. nxsetup --install --setup-nomachine-key --clean --purge (the –setup-no-machine key option means that you just need to use the default key that the nxclient comes with)
  4. Try to connect via nxclient, tail -f /var/log/messages, if it complains about the user being locked, do usermod -p foo nx, where foo is a password you’ll use.
  5. Start debugging why it doesn’t work.

When debugging I normally:

  • Make sure SSH works first. Refer to my sshd_config (obviously this is specific to my setup, but notice that PasswordAuthentication is set to yes, as that’s how you’ll authenticate with NX with nxclient)
  • Make sure you own your own authorized_keys(2) file, after a while of mucking about you might’ve screwed the permissions (600).
  • Check that you’re pointing at the right authorized_keys(2) file, though I didn’t need to bother about this with FreeNX, I know that this is a common mistake with nxserver-freeedition
  • I like to run SSH on port 443, so change to port 443 in /etc/nxserver/node.conf for FreeNX, and if using freeedition in /usr/NX/etc/server.cfg, node.cfg, whatever is specific to your setup.

As for my experience switching over to FreeNX from freeedition, honestly in terms of usability it’s no different at all, but personally in terms of installation procedure FreeNX wins by a mile. But for the moment I’m just happy I won’t be restricted by my school’s web filtering system and glitchy, laggy, virus-filled OS. Perhaps when NeatX stabilises a little I might check it out.

4 new models added to the BMR

Monday, September 28th, 2009

http://e2-productions.com/repository/

Yes, I do think those are penises.

Saturday, September 26th, 2009

I’ve talked about bad food before, as well as trying my hands at cooking, but recently as I visited a friends house I knew something had come along to trump even my best of egg-poaching abilities. I was ushered into a room with a thin pot sitting on a table, cover closed, and his mum grinning widely at me. We all sat down to eat, and my friend took off the lid.

pasta1

Yes, I do think those are penises. Multicoloured pasta-shaped penises penis-shaped pasta. You know when you’re younger you enjoy playing with your food more than eating it? I think I relived a bit of that again. Needless to say it was time to analyse the anatomical correctness of the dish. Here’s a mind-blowing structure we assembled:

pasta2

… and because we’re much, much dirtier than penis pasta can justify, my friend opened up a second pot on the table – home to generous dollops of what seemed like thicker carbonara sauce. Needed to complete the picture, we immediately started reconstructing an operational model using naught but the tip of our forks and the pressure from our spoons. We also took the opportunity to redecorate our previous structure:

pasta3

I wonder what exactly is stopping the local minimart down the street from stocking products like these – or do they belong is specialised niche shops, “Erotic Pasta”? Obviously I don’t know enough about food to give you an answer, but I can tell you that despite whatever shape they turn pasta into, such as in the example above, it still tastes almost just like normal pasta if you close your eyes. Well, I did say almost.

Make a category not considered as a post in WordPress

Thursday, September 24th, 2009

In other words, how do you make posts that are in a certain category not count towards total page post count in WordPress?

A while back I set up Asides on this blog. The problem was that previously I was displaying 5 posts per page. Now with asides it still displayed 5 posts per page, but as asides are probably one sentence long at most I personally don’t consider them to be blog posts. This meant that it didn’t display 5 “real” posts per page. So, how do I fix this?

Disclaimer: I’m not experienced in the under-the-hood of WordPress and as a result some of this solution might be hackery. However it works for me, and that’s what counts.

Problem 1: displaying 5 real posts per page regardless of how many asides there are.

WordPress loops through a series of posts per page and displays them one by one. Initially I thought they would increment a counter, of which I could easily change so that if the post category was in “asides”, it will not increment the counter. However there were a couple flaws: 1) There was no counter, or I completely missed one, 2) The database queries sets the LIMITs from the administrator settings right at the very beginning, and 3) pagination will be completely messed up.

The solution was pretty simple, firstly we set the database query LIMIT to an obscenely large amount – more posts than we ever think we’ll need on a page. This can be done in the administrator panel. Change “display posts per page” to a random large value. I chose 15 because it seems pretty realistic that real posts + aside posts < 15 for 99.9% of the time.

The second step is to manually change the criteria for when the loop terminates. This way it will not actually show 15 posts, but instead up to 15 posts. What we’ll do is create a new counter, where ever time we display a post that isn’t an “aside”, we increment the counter, until it hits 5 posts (if I wanted 5 real posts per page) – at which time it’ll terminate the loop.

This can be done in the wp-includes/query.php page. To begin with we’ll need a new variable in the class for our counter. So below class WP_Query { we should add:

var $counting_up = 0;

Just to make sure that $counting_up resets itself as it should, we’ll add this to the init() function:

$this->counting_up = 0;

Now the next step is to modify the the_post() function. When the loop has started and the category is not an aside, we’ll increment our counter. In this example my aside category ID is category 429. This will be different for you, so you change it. So simply add this to the the_post() function:

if ( !in_category(429) && $this->current_post != -1 ) {
 $this->counting_up++;
 }

Now we’ve got our counter, we’ll set up the loop to terminate correctly. This can be done in the have_posts() function. Notice this is the have_posts() function inside the WP_Query class, not outside. We can modify our if statement to terminate when our counter hits 4 posts (as the first isn’t counted – therefore in effect we’ll display 5 real posts), and also when we don’t have a do_not_terminate variable set to the WP_Query. Why this do_not_terminate variable is important is if we ever need to override this, as well as later I’ll explain when we look at pagination issues. Here is my completed modified if statement:

if ($this->counting_up == 4 && !$this->query_vars['do_not_terminate']) {
 $this->in_the_loop = false;
 do_action_ref_array('loop_end', array(&$this));
 $this->rewind_posts();
 return false;
 } elseif ($this->current_post + 1 < $this->post_count) {
 return true;
 } elseif ($this->current_post + 1 == $this->post_count && $this->post_count > 0) {
 do_action_ref_array('loop_end', array(&$this));
 $this->rewind_posts();
 }

Now we’ve solved problem 1, and 5 real posts are displaying on our front page, let’s move on to problem 2.

Problem 2: previous page, or going to older posts will no longer work.

Since pages are pretty obsolete at this point, we’ll switch to using offsets. This is because each page will no longer display a fixed number of posts, each may display a variable amount of posts, minimum being 5 (that we set just now), and maximum being 15 (that we set at the very beginning). So to start we’ll hop over to our index.php in our theme file, and simply get the offset from the URL and pass it through to our post loop. Here goes:

<?php if ($_GET['offset'] && is_numeric($_GET['offset'])) {
 query_posts('offset='. $_GET['offset']); $offsetting = $_GET['offset'];
 } else { $offsetting = 0; } ?>

So with that code in index.php, we can now visit myblogsite.com/?offset=20 and offset our posts by 20. To determine how many posts to offset by in previous pages, we simply take how much we’re currently offset by, and add all the posts we’ve displayed on the page, regardless of whether or not it is an aside or a real post. To do this we need another counter. So we’ll initialise our counter, perhaps near the beginning of index.php:

<?php $on_page = 0; ?>

… then within our while (have_posts()) { loop, (or whatever equivalent loop your theme uses), we’ll just increment it:

<?php $on_page++; ?>

So then we recode our “previous posts” link to go to:

<a href="http://yourblog.com/?offset=<?php echo $offsetting + $on_page; ?>" >Previous posts</a>

That was simple, eh? This brings us to problem 3.

Problem 3: newer posts don’t work, for obvious reasons.

Going forward in time is a little bit more complex. We want to calculate how much less we should offset by. To do this we’ll create a function to calculate this. The function will need to know how much we’re currently offset by. Based on that, it’ll query 15 posts into the future, then loop through those posts in reverse order. If it can’t go 15 posts into the future (eg: on the first page, and perhaps the second), it’ll go as far into the future as it can. When looping through, it’ll record the category of each of the posts. Whenever it hits a post, it’ll increment the count we want to offset less by. When we hit a post that category isn’t an aside (category 429 in my example), it’ll increment a counter that determines how many real posts we’ve hit so far. So therefore we have two counters. When the real counter hits 6 posts, it’ll terminate the offset counter. This is because I want 5 real posts per page, and based on how we coded problem 1, we know that the last post of any page must be a real post, not an aside.

We can place this function in the functions.php file of our theme. Here is the function, of which lazy people can copy and paste:

function back_to_the_future($offset = 0) {
 $new_offset = $offset-15;
 if ($new_offset < 0) {
 $new_offset = 0;
 }
 $diff_offset = $offset - $new_offset;
 $future_query = new WP_Query(array(
 'showposts' => $diff_offset,
 'order' => 'DESC',
 'offset' => $new_offset,
 'do_not_terminate' => TRUE
 ));

 $post_data = array();

 while ($future_query->have_posts()) {
 if ($diff_offset == 0) {
 break;
 } else {
 $diff_offset--;
 }
 $future_query->the_post();
 $cat_id = get_the_category();
 $cat_id = $cat_id[0]->cat_ID;
 $post_data[] = $cat_id;
 }

 $post_data = array_reverse($post_data);
 $count_posts = 0;
 $count_total = 0;

 foreach ($post_data as $post_cat) {
 if ($post_cat != 429) {
 $count_posts++;
 }
 if ($count_posts == 6) {
 break;
 } else {
 $count_total++;
 }
 }

 return $offset - $count_total;
}

People who looked through the code will realise that we passed the do_not_terminate variable to WP_Query that we set up when addressing Problem 1. This is required because if we didn’t, we won’t get 15 posts into the future, instead we’ll just get however many posts starting from 15 posts into the future that include 5 real posts – which is totally useless.

To finish off nicely we’ll edit our “newer posts” link to use this calculated offset in our index.php file, but only display when we have a proper offset to show and we’re not on the first page.

<?php if ($future_offset != 0 || !empty($offsetting)) { ?>
 <a href="http://yourblog.com/?offset=<?php echo $future_offset; ?>">Newer Posts</a>
 <?php } ?>

Tada – all done! I hope that helped somebody out there, but if not at least I have it for archival purposes. If you’re using it, let me know how it goes!

By complete coincidence I own the domain Failnation.com of Failblog’s upcoming book.

Tuesday, September 22nd, 2009

WIPUP: (E2-Productions) Finished the site design.

Tuesday, September 22nd, 2009

http://wipup.org/updates/view/11

FrogCMS: a simple, clean CMS.

Tuesday, September 22nd, 2009

The other day I was looking for a CMS to run E2-Productions on. People who exclaim “what? You’re not going to engineer your own solution?” clearly have their priorities in the wrong places. If there’s one thing I learned in programming, it’s never, ever to reinvent the wheel. (unless you don’t know how wheels work yet)

I wanted to make E2 easy to maintain, easy to update, and most of all easy to switch between different ideas of what the site should contain. A CMS was a clear solution to this problem. E2 is the site I plan to use to showcase my portfolio in greater detail. Wipup is free to host my works-in-progresses, and thinkMoult is and always should be just a blog.

Being such a simple site with mainly static pages (perhaps a contact form) it was clear that the big poisons like Joomla, Mambo, Drupal etc were clearly out of the picture. Wordpress is a CMS but a pain when you look at the source, and is mainly targeted at blogs. Some poking around led me to discover FrogCMS.

I downloaded the tarball, and had it up and running on my localhost within seconds. A quick tour around the administrator backend was enough to tell me this had all my needs covered. It supported markdown, templating, page hierarchies, and I think I glimpsed at some out-of-the-box SEO. Browsing their website also unearthed some useful plugins, although I think I will code for my needs manually.

The next step is to come up with a design. However, that’s not stopping me from using WIPUP to start tracking the upcoming upgrades on E2-Productions!

WIPUP: (thinkMoult) Added some links and fixed layout glitches.

Monday, September 21st, 2009

http://wipup.org/updates/view/7

WIPUP: (E2-Productions) I’ve chosen FrogCMS to manage the site.

Monday, September 21st, 2009

http://wipup.org/updates/view/6/

Implemented a new “Asides” feature.

Sunday, September 20th, 2009

As you might’ve guessed, the thinkMoult blog is not the fanciest WordPress implementation in the neighbourhood. Heck, our sidebar disappeared a while back. The site currently uses three plugins: a related posts feature, one that allows you to subscribe to comments, and finally good ol’ Akismet which likes to delete any comments that mention the word viagra.

WIPUP is gaining momentum and will replace some of my blog posts as the main way I release updates on projects, and as I’ve quit Twitter I have a small hole left inside me for short updates that happen once in a while. Astute readers would’ve noticed just below this post there is a post … without a post! Yes, it’s a tiny update and I shall use it for better means in the future than greeting mother Earth.

For those living under rocks, it’s basically a short sentence update that will not necessarily follow the post-every-2-days schedule I try to stick to. The update can also optionally include a link to another website.

For those curious on how I did this hackery, I followed the instructions from this guide. Well, not fully – I made some modifications and I couldn’t be bothered to style it so I just made it a header. It’s semantically incorrect – so sue me.

Hello, world!

Sunday, September 20th, 2009

http://thinkmoult.com/2009/09/20/implemented-a-new-asides-feature/

ADOM: Game review.

Friday, September 18th, 2009

I’m not a gamer. I don’t mind playing games, they’re fun. However I don’t see any sense in wasting a good majority of my day playing a game. Games attract me because of the intellect and flexibility within them, not so much the advance in graphics. Replay-value is probably what I weigh as most important for a game.

A good while back I was – I admit – searching for a game for my computer. As I was on Linux, the game had to be 1) Linux-compatible, 2) Free, and 3) Not lag. A quick public question in IRC came up with the answer: ADOM – Ancient Dungeons of Mystery.

It’s a command-line run game – a roguelike. For those unaffiliated with this genre a picture speaks a thousand words:

adom

Ok – it already looks ancient. As you might’ve guessed, it’s all text based, and you move about just like you would in any modern day RPG. The story revolves around you as a young explorer trying to discover the source of some evil thing called chaos that is destroying your world. You complete quests and learn through experimentation how to survive in this magical and mysterious world.

Being text-based, it allows me to play it when SSH’ed in remotely. This is a very ideal scenario for people who don’t do gaming seriously like me. It also helps that you can pretty much stop playing anytime and resume later exactly where you were without fear of the consequences.

What makes it fun is the flexibility and complexity of the game. There are a lot of things you can do – there are even several ways of winning. For example, I can attack a monster by throwing my hat at it – it probably won’t be very effective, but you get the idea. Or I could kill some rats and eat their corpses – or if there was a cat nearby I could feed it some rat corpses and it might become my pet. There are spells, races, classes, potions, herbs, weapons, shields, clothing, amulets, gods, quests, pets, shops, skills, talents, curses, special effects – you get the idea: it’s detailed. You can do a lot of stuff – and stuff you do affects stuff that happens to you. Heck, locations are randomly generated every single time you play the game. If that’s not awesome replayability, I don’t know what is. ADOM’s Wikipedia entry says a lot more about it than I can mention in this post.

Don’t be fooled by the hideous graphics – or lack of graphics. It’s a challenging and interesting gaming experience. I still haven’t won it – not even come close. True I’ve only played it 20 times or so (savefiles are limited to one per character, and once dead, that’s it. No saves), but yes, it’s challenging. You actually have to reason once in a while.

Just because it’s a console-based game doesn’t mean it doesn’t play nice with Windows or Macs. If you’re looking for an interesting gaming experience to try out next weekend I would recommend ADOM. Just a note: it takes time to learn, and it’s hard – don’t be discouraged if you keep on dying.

Using WIPUP – a practical example.

Monday, September 14th, 2009

Even though WIPUP still needs time to mature (as well as it’s still very incomplete as of writing) as most of the basic functionality is up I wanted to show a practical example of what it is.

WIPUP is my idea for my OpenDesktop competition submission as well as my stepping stone into KDE development. Here is a demonstration on how it could be used.

A while back I told you I was working on a composition. This can be called my “Evan” project, as the name of the piece is “Evan”. It is also a work-in-progress. Originally I would give updates via blog posts, however a system like this allows people to view my updates through time and see it in a consistently formatted matter. If they wanted to keep up to date on what’s going on, they also won’t need to sift through all my blog posts.

So I created a project for it and added what was my previous post on it. You can see the update here. Now you realise from that page you’ve essentially see what I’ve done on the project and nothing else. Compared to my blog post, which contained a lot of my usual drivel, here you see what’s important only. The astute observer would see that that’s not the only thing I’ve submitted from the “Moult’s Other WIPs” section, as well as seeing the timeline arrow buttons on the top right of the update page. Depending on how curious they are on this project, they could move ahead and see how I have progressed.

update1

Today I realised I’ve been a mean person from my logs available on the dashboard (this feature is still under construction) and that I haven’t given you an update in a long time. So I decide to give you another update. Just by glancing at it you can definitely see that I’ve done work. Clicking on the image allows me to preview the score full size to check out in detail and full-resolution glory what has been added. If I liked the changes, I could add a kudos to it. Unfortunately since I own the update I can’t demonstrate this (it’ll be stupid if you kudos your own work).

update2

The update also says to “See next update to download the PDF so you can print it out and try it out on your own.” – so I click the timeline button to bring me into the future (at 88 miles per hour!) and that throws me at another update page. At this page, it’s a no-nonsense here-it-is-go-away style. I can download the music score PDF, print it out and play it to see how horrible it sounds.

update3

Notice this example is of a music composition in the works – it has nothing to do with a programming project. I understand that many people have similar needs (I know I definitely do!) and that’s what WIPUP is all about. Unfortunately the chronological timeline view and profiles page is still under construction or I could’ve shown how we can effectively display “progress over time” to any random person viewing our work.

Many open-source projects use this model too, and I believe this is an invaluable tool to showcase this behind-the-scenes development – and to show that we are a really alive community, not just developers, but users as well! This way it’ll be easy for users to know what’s going on on their favourite projects and applications.

Unfortunately it’s still unfinished but this will later use the OpenCollaboration Services API to allow you to integrate this system into your desktop workflow. Imagine publishing a savefile right from the GIMP itself!

That’s all for today, hope you liked it!

Never gonna give you up.

Saturday, September 12th, 2009

My previous post featured a sarcastic article that conflicted with all my interests to take advantage of the fact that somebody had hacked my school website to make it rick-roll everybody. They accredited (see synonym “framed”) this hacking to me, linking to my blog in the process. This allowed me to use my blog to broadcast that message to any folks who bothered to click on my name there to say that I was actually innocent.

Of course, I’m no stranger to love, and I myself rickrolled my school during an assembly presentation. But you know the rules and so do I, that was in good humour and didn’t involve giving epilepsy to the lower year parents who were expecting the new on-line extra-curricular activity registration system but instead were thrown at Rick Astley singing his heart out.

A full of commitments what I’m thinking of – I was immediately summoned by people who could join the two dots between the two mass rick-rolls together. “You wouldn’t get this from any other guy“, they said.

I just wanna tell you how I’m feeling“, I replied. “Gotta make you understand“.

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

… and at this point I figured out that Rick Astley’s lyrics didn’t work too well in a blog post.

The website is full of security holes and I’m not surprised it got hacked. The next day after the site got restored, the hacker had hacked it again and put up a lovely “goodbye, and thanks for all the fish” page with … a shoutbox! This nifty widget allowed the students to go crazy on their thoughts, some impersonating staff members (such as the principal) – but more importantly allowed me to chat with the hacker, who was undoubtedly monitoring the messages. Interesting revelations ensued as he stated that he wasn’t the one who put my name on it (interestingly enough I remember my name was added a good 3 hours after the rickroll was added) and that my guess of an MSSQL injection was correct. Of course, the honesty of such individuals is always questionable, but I’m simply stating what happened. Here’s a screenshot I grabbed of the page:

2009-09-10-232409_1280x800_scrot

Dan Fego on the previous post wisely suggested that “the next step is to find the bastard“. Unfortunately my involvement – or better put, lack of involvement – meant that I couldn’t exactly “find the bastard“. Personally like any other student I thought it was a fine joke – until my name was put up there of course.

So that means strolling throughout the school I don’t appreciate “hey, you whacked the site!” or “who did it, do you know?”.

There isn’t that much of an epic conclusion to the story (yet, perhaps?), and I’m back to doing my usual whatever.