Category Archives: Coding

Programming, HTML, CSS and all similar

OCTGN reminded me how much I love programming

example of Python language

Ever since I’ve started coding games on OCTGN and working significantly with python, my ethusiasm for programming has been rekindled. So much so that I’ve pretty much stopped doing almost all other things I was doing lately, including reading reddit.

Today, after I went to bed coding and woke up to code afresh, I got to thinking why I ever stopped doing it. The truth is that I stopped doing it (or rather, never fully started) because I didn’t have a good base at modern programming languages and because I didn’t have a project to draw my interest in doing learning them. This is actually a big problem for me. Due to the way my ADHD-addled brain works, I find it nearly impossible to work on something that A) doesn’t excite me, B) doesn’t give me a clear short-term goal. And because of this, the thought of first learning a programming language before trying to use to code something I want to have, was overwhelming.

I always wanted to get into python, and I did start with a few introductory texts, but I quickly lost attention. Not being able to do, or having something to do with what I learned, killed my interest. And this is where OCTGN helped: It allowed me to start slow (small incremental improvements), on a working base to work on (other games), on something that interested me (making defunct CCGs I love work online).

Slowly I’ve been building up steam and learning python as I go, which is the only way I know that works for me. The result is that I spent almost all day yesterday getting the automation for the Dune CCG work, and then re-writing the code to be more intuitive and succinct. This shit’s addicting!

My hope is that once I’ve perfected all the games I want to on OCTGN, I’ll be able to use the knowledge and familiarity I’ve achieved in python to move to some of the other projects currently sitting in the back-burner of my brain.

Preparing for a long-time-coming upgrade

The Keyboard Parade
Image by theopie via Flickr

I’m finally preparing to upgrade my theme to the latest version (ie the next part in my ongoing attempts to upgrade) as I really should finally start using wordpress widgets. Unfortunately the theme seems to be unmaintained at the moment and the author MIA since April this year. Also the theme still hasn’t been moved to the shiny new official WordPress repository which tells me that Nalin must have lost all interest in it.

Hopefully I’m wrong. I’ve sent him an email and left a forum post asking to add to the repository and allow me to pickup the maintenance if he’s not interested anymore. If he doesn’t come back to me, I’ll unfortunately have to fork it in order to make it compatible with newer version of WordPress and to merge the changes I’ve made into it for others to use. We’ll see.

Some of the things I’m planning to add/modify are

  • Support for the new way of styling so that it works properly with Zemanta and builtin alignments.
  • Option to enable drop-down menus for the header (as you see above) through suckerfish and possibly superfish in the future.
  • More options to tweak.
  • Widgetize the single-post sidebar to allow some content in the generally empty area on the left.
  • Hardcoded support for the various plugins I’m currently using. So for example, if you install emo-vote, there code will already be in your theme to activate it but nothing will be visible if the plugin is missing. I will probably add support for tweaking these plugins in the options page as well.

And that’s for starters. Fortunately I see that the community around this theme is still alive so I’m guessing I’ll be getting more ideas for addition from there as well.

I’m still running my old theme since I managed to debug the suckerfish issue a few minutes before I left for work today, but now that my biggest hurdle is resolved, I’ll soon my changing into “fresh clothes” so to speak.

Reblog this post [with Zemanta]

Is Dreamhost PS simply a way for Dreamhost to wash their hands of support?

Another month, another total crapdown of my sites which are hosted at the moment in Dreamhost’s Virtual Private Server offering. Once again the story begins in the usual way, all three of my  sites start puking Internal Server Errors all over the place which generally means that you are out of available RAM on your server. As I generally have about 180 Mb of availability, it would meant that either I have a huge amount of traffic that my Cache did not alleviate, or that something is going wrong on the server.

Going to the Resource Management, I am greeted by a classic figure

Up, up and away!
Up, up and away!

Having looked at my traffic already which had stayed steady in the last days, I know that this is certainly caused by some server/app malfunction. I know this from experience because the same goddamn problem happens to me so regularly, it’s not even funny anymore.

Since this happened while I was at work, I could troubleshoot it through the terminal as they have the ssh ports blocked so I had to wait until I came back home to investigate. Once I arrived, I fired up an ssh connection and checked what processes were running. As expected, it was PHP in CGI mode that was sucking my life’s blood.

Bad PHP. Baaaad!
Bad PHP. Baaaad!

Now mind you, I know all this because I’ve done it before where I had to google around and learn which commands to use to discover this info. The first time it happened, my ram usage was slowly creeping upwards in jumps of 30 Mb per week or so. After that, it simply happens all at once suddenly.

Now this is extremelly difficult to troubleshoot as you can have no idea what is causing this. A php5.cgi process can be anything under the sun that runs on PHP. Basically the whole wordpress interface or any of the dozens of plugins I have installed. You can kill the processes but this will not tell you what is happening and as it does not happen persistently, you can’t figure out which plugin might be causing it as shutting down a plugin does not stop the process and you don’t know when a process will get stuck again.

Unfortunately, and this is what is annoying me mostly, Dreamhost’s answer in the past has been that “It’s not our fault. Figure it out yourself”. A very unfulfilling answer as you might guess. But at least I know that I can expect very little help from them anymore so I avoid them.

So then I got to process killing. Unfortunately this time it seems that I had found a resistant strain of bug. As soon as I killed a process, 5 seconds later and a new one would be spawned, then another and another, until all my RAM was eaten up, no matter how much I increased my available. At this point I was fast reaching a deadend with my current skills as I couldn’t make the problem go away. I couldn’t even access my wordpress’ admin panel to disable plugins.

At this point, a former colleague suggested that this might be caused by a known PHP 5.2 bug which leaves processes hanging when done with them. I thought this might be a good thing to suggest to Dreamhost support to check so I fired up a support ticket.

A while later, I noticed that the RAM usage seemed to have dropped off so I thought that the problem had resolved itself. Unfortunately, while the main page was working the admin panel refused to work.

What admin panel. There's no such thing here
What admin panel. There's no such thing here

In desperation I did a quick server reboot and this was the point where the universe b0rked. After the reboot the whole site was off and my memory usage was stuck at around 20Mb which means that basically the whole thing failed to load. I fired a new ticket to support and waited.

I had to wait until today for an answer which basically told me that they managed to get the sites running again but advised me that my RAM usage was high so I should be checking that and no, they still can’t help me. Thanks Sherlock…

Looking around the interwebs however, I did stumble on a page in the dreamhost wiki where there was a note under supercache under caching that warned not to utilize the “super” part of WP Super Cache as it may drive resource use up on Private Servers. Gee, it would be nice if I knew of this a bit before. It would also be nice if Super Cache was not installed as part of the standard one-click installation of WordPress by Dreamhost which makes people assume that if anything, this plugin will be working well.

So I disabled Supercache on the Division by Zer0 and on the Wesnoth Journals and killed the remaining php processes. Lo and behold, no more processes were spawned. Unfortunately I was lucky that I could access the admin panel of these two sites after I increased my available resources to some ungawdly amount (1.5Gb of RAM or so). Unfortunately I was not so lucky in the Antichristian Phenomenon where not only I could not access the admin panel (never finished loading) anymore but the php processes kept spawning repeatedly and fast.

I tried deleting the plugin directory which led to my whole page being turned off. I tried fixing the .htaccess file. Nothing. Anything I tried, I couldn’t get the site to work properly. So I did the only thing I could do, renamed the whole wordpress directory and reinstalled again. At least this gave me an opportunity to finally rename the prefix of my database tables which helps avoid zero-day exploits by script kiddies. After a few hours, the site was back online.

Unfortunately the latest ordeal has really disillusioned me about Dreamhost’s PS and their support of those. From the 3 times I’ve contacted them about issues in randomly increasing resources, their reply has been “Deal with it yourself” because apparently now I control everything on the server and if anything goes wrong, it must be my own scripts or whatever. Seeing as I only use standard software like WordPress and Gallery this reply does not help me much.

Basically what seems to be happening is that when one decides to go to a PS in order to get a bit more speed (since shared hosting seems at time to be powered by hamsters) you’re on your own. If you’re not a (quite) techical user and have made the grave error of installing wordpress plugins on your site, you’re fucked. It seems that as far as Dreamhost is concerned, you shouldn’t be running plugins in the first place. Just vanilla WordPress for you.

Luckily for me, I know a few UNIX commands and how to use an ssh shell to do some troubleshooting. However even for me this kind of response is definitelly inferior. It would be nice if I could expect the Dreamhost support to ask questions like “Are you using WP Super Cache?”, or something similar. It would be nice to expect the support people to know of a few issues that generally might cause this kind of trouble. Is this is all too much to ask? Is it too much to ask to expect some attempt to help your users?

Last time I was delighted when the support tech gave me a simple command to help me trouble shoot but since then, all replies have been to explain me that it’s my own damn fault and this is very disheartening. To everyone considering the Private Server offering, if you’re not very technical and open to spending a few hours now and then to troubleshoot random issues that occur without you changing anything, then stay away from it and stick to simple shared hosting.

As for me, now my sites are all in the classic WP Cache mode and I’ve used Hyper Cache for the ACP to see how it goes. If all goes fine, I will switch everything to Hyper Cache and drop Super Cache altogether. ‘Till next time my site craps down…

Reblog this post [with Zemanta]

I love WordPress! Now I've got a series plugin

As I’ve been progressing with my misunderstanding communism series it has become to me painfully obvious that I need a better way to organise the links and the format of it in a much better way than what I’ve been doing until now. Specifically, what I have been doing was to copy paste a small introduction text within a style-customized <div> and then manually update the links towards the previous and next articles.

This is what I had been doing in my self-hosting with WordPress series as well and, frankly it was an annoying process. I thought that there must be a more optimal way to go about doing this and fortunately others had the same idea as me.

A quick search for relevant plugins immediately landed me two results. Without knowing the difference, I simply went for the one which has been updated more recently (plugin developers, this is why it pays to keep your code up to date): Organise Series

This one takes the more exciting road of actually using the wordpres taxonomy capabilities and creating a new one. As such I do not have to mix up my already existing tags or categories (which would appear in the various parts of my theme) and I can rest assured that I will not b0rk it by mistake.

I faced the first hurdle when I discovered that the plugin did not have the correct link structure for the options page and eventually that it is not yet ready for WordPress 2.6. However actually opening my eyes a bit more showed me that some kind soul has already submitted patches for this and the beta versions are working. Thus, since I had already initialized it anyway, I took the dive and upgraded to the developer version No problems there.

Then I set about making it look good. It took me a while to figure it out but the author of the plugin has gone into the trouble of writing a use howto…well, series, which goes quite in depth. Eventually I figured it out and made my pages look readable again. But as always, I wanted more bling. So, since I’m already using scriptaculous through backlinks, why not make my series description available without crowding the actual post, through the nice toggle function. And lo, there was code!

The following went into my “Series Meta”, which is the text that appears very first on the post, announcing it as part of the series.


<div class="seriesmeta">This entry is part %series_part% of %total_posts_in_series% in the series %series_title% - <a href="#" onclick="Effect.toggle('series_description', 'slide')">%series_icon_linked% About this series</a></div>%postcontent%

This goes into my Series post list Template:

<div class="seriesbox" id="series_description" style="display:none;">
%series_description%<hr/>
<ul class="serieslist-ul">%post_title_list%</ul>
</div>%postcontent%

And thus, after customizing the css a bit, you get the nice result you see now in any post in the series where you can click on the link and the description of the series, along with the whole list of posts drops down for your viewing pleasure. And I didn’t even had to hack my theme as you can do all this from the options page. Sweet!

The plugin has other nice options like the ability to assign an icon/image to a series, a standalone series page and the capability to read all the posts in a row when clicking on their series link. Unfortunately for me the last does not work as it simply kills the html loading of the page. I assume this is because it’s not yet fully compatible with 2.6 but I’m going to soon open a bug about it.

All in all, I like!

How to load a javascript through your wordpress plugin

I’ve been struggling today to manage to make Backlinks to use the Scriptaculous script library in order to have the list of backlinks hidden until the viewer chooses to see them. While in the Division by Zer0 I already have those libraries loaded for my navigation, it’s certain that not everyone who is going to use it does the same.

Initially I was thinking of simply asking everyone to use a plugin loading these libraries as a dependency but that’s simply over the top for something this simple. Instead I decided to find out how to load the script within the plugin and to my delight I found out that not only does wordpress has functions explicitly for this purpose, but it already includes most common javascript libraries, inclusing Scriptaculous.

Unfortunately, although there were a number of guides trying to explain how to use this, none of them was complete. Simply adding enqueue_script in my function didn’t work and I couldn’t see a full example.

Fortunately someone had thought to add a mailing list discussion which gave me the solution after a few pages. I need to use the template_redirect hook (wp_head is not good, I tried) and I need to put that at the very start of my plugin, after the information but before any function begins. It then needs to call a function which enqueues the scriptaculous effects of which “blind” is used by Backlinks

The end result looks like this

add_action('template_redirect', 'addeffects');
function addeffects() {
if (function_exists('wp_enqueue_script')) wp_enqueue_script('scriptaculous-effects');
}

Of course, the name of the function can be anything you like and you can call any javascript library you wish instead of scriptaculous-effects. Feel free to download the whole plugin to see the whole code.

Backlinks

I just created a new plugin which allows you to display backlinks for your posts similar to the way it exists in Blogger. It is called, appropriately Backlinks.

If you do not like that wordpress does not display links coming from blogs that utilize trackbacks, or if you simply want a simply list of incoming links (instead of having them scattered in your comments), this is for you.

If it still in the very first version so it is quite basic. I plan in the future that have a configuration page, the ability to hide or display the links (just in case the list gets too long) though scriptalicious etc. For the moment you can simply put it anywhere in a template and it will automatically show you blogs linking there.

Let me know what you think or if you have any ideas that might make it better.

UPDATE: I’ve now managed to get the plugin to hide the results until the header/link is clicked. This will save people with a lot of incoming links from having a huge list in the middle.

Last.fm activity now in Complexlife

Last.fm is one of the top, if not the best music service out there and it’s something I’ve been using for quite a while now. While last.fm includes things like groups, friends, forums and other aspects of a social network, your activities in these was never provided. In the latest version these activities (new friends, loved songs etc) were shown in the form of a little block in the sidebar but unfortunately there has been no way to grab that for use in Complexlife.

I knew there is a way to get these activities somehow as Friendfeed does show you when you love a track but having asked directly about it in the forum, I was told that getting this in a feed was just not an option.

Fortunately web-mastered stepped up and created a yahoo pipe which grabs the last.fm latest activities API and returns it as a feed. Very useful but unfrotunately I noticed that it wasn’t exactly in the format I needed. If I used that in Complexlife then you would only see the title (a generic “New activity from <username>”) and having no date info in the feed, b0rked the sort by date of Simplepie.

Thus I had to modify the pipe in a way that

  1. Made the content become the title of the post (removing any html which might break Complexlife)
  2. Provide the date in the RSS so that the item can be sorted

Creating the title

It took me a while to figure it out, but making the content become the title was the easiest part of it all. Since yahoo pipes provides a handy renaming function, all I needed to do is tell it to rename the content as the title

Renaming the content as Title
Renaming the content as Title

The first part copies the whole content as the date field. I will later use this get the date. The second part renames the current content to the title so that it is displayed in whole. If I didn’t do it, I would get only part of the content displayed with elipsis after 30 characters or so.

Now I need to remove all the html code the activity stream has in. As it includes links to my profile as well as to artists and tracks, this would break the link complexlife puts for each row. The only way to remove the unecessary parts is of course through regular expressions and yahoo pipes gives exactly that function.

Removing the unecessary parts from the content
Removing the unnecessary parts from the content

This part actually goes before the renaming/copying as I remove various parts I also don’t need from the date field. Thus when I copy, I save duplicating the work.
The most interesting part is the previous the last field, wherein I tell it to remove all html tags (anything between < and >) and all their settings (i.e. target=”_blank”). Thus I’m left with the title in plain text.

Creating the date

This was a more tricky part as not only does the last.fm activity stream API consider it a good idea to put the date on the content but it also puts it in as a relevant entry to the current date.

Putting the date in the correct field was the easy part as all I needed to do was copy the content in the date field and remove everything except the date. As right before the date there was a fullstop, it was fairly simple to use another regex to delete anything until the last fullstop

The regular expression removes everything until the last fullstop
With a little regex magic, anything except the date is gone

The more difficult part was to make the relevant fuzzy date to become something that is expected to be in an RSS feed, which is something very specific in time and format. Fortunately, I noticed that there is a specific module that does exactly that: Date builder. How convenient.

Unfortunately this module accepts only strings so I could not really parse my whole feed through it unless I had a loop. Oh wait…

With a loop I can make all date items in the correct format
With a loop I can make all date items in the correct format

Sweetness. Unfortunately one problem remains which is that because the date provided is always fuzzy, I end up getting a rolling date for the item each time the pipe is run. For example, an item which has a date of “one month ago” today will point to Aug 28, tomorrow on Aug 29 etc. There’s not much I can do about it other than wait until (and if) last.fm deems it worthy to give us a proper feed.

And now my new shiny feed is in exactly the format I need to have for Complexlife to use it. A little hacking later and version 0.9.8 is ready to go. The last.fm activity stream is finally lifestreamable 🙂

Reblog this post [with Zemanta]

ComplexLife

window peeksSo finally my very first WordPress plugin is accepted into the official plugins repository 🙂

This is a historic event. I’m certain that fame and fortune will not be very far back!

In case you haven’t seen my recent page about it and you don’t care to read it, Complexlife is a lifestreaming plugin which is a fork from SimpleLife (You see what I did there? 😛 ).

After adding a lot of features and options to it and seeing that Simplelife is not progressing I thought I’d go ahead and just upload it as a new version. This will allow me to have a more organised development and also have the help of anyone who wishes to improve it.

I’ve already got a few features I want to add and I’m also going to be merging changes from other places where I find them, i.e. the trumblog.

So if you’ve got a self-hosted WordPress blog, give it a go and let me know what you think. I’m eager for feedback.

Memberlist for Collaborative WordPress Blogs

In case you have a self-hosted Worpdress blog which has multiple authors you may have noticed that you don’t have lots of option to show information about each one. You can have each author create a post for himself and link it from the sidebar (Which is how Debunking Christianity does it), or you can create a page for each one after they provide you some information about themselves. Finally you can just leave each author’s page to be the default list of posts.

I wasn’t satisfied with either of those options so I looked around and found something better. So I have just finished with my custom member list setup at the Antichristian Phenomenon and I thought I’d share how I did it in case anyone wishes to implement it as well.

I started after I discovered this excellent guide from WPDesigner. Although I didn’t need the role manager, the rest of the instructions were perfect for my purpose. So I installed the necessary plugins (plus Register Plus to stop spammers registering) and started adding fields.

I then needed to display those fields in each author’s page somehow. In also wanted to do that without making the page totally different from the reast of the site. So I copied the archive.php file to author.php. I enterred the file and inserted all the necessary variables for my fields (as described in the guide) and deleted all archive loops except the author’s. This way the user visiting the author page could see the author profile but also a list of articles they have written.

The curauthor variable was used to grab information for some of the default fields. Unfortunately the Wp User Manager plugin does not give you the names for all the default wordpress fields but fortunately the documentation in curauthor is complete. I copied the html div the archive loop was in (so as to have the same format) and created a little list to show each author’s profile. Here’s how it looks like currently

Once that was done, I decided to see if I could also put comments in each author’s page as well. Unfortunately, just putting the php call for the comments template between the info and the archives did not work. Apparently WordPress does not expect comments on archive pages. However since I am using Intense Debate Comments at the moment I figured that they would be agnostic on where I am putting their script.

Unfortunately since IDC works through the wordpress comments template, where that does not appear, so does IDC. I managed after all to work around this by copying the script itself into the template. It wasn’t easy to get the code for this since IDC insists on providing you with a WP plugin instead of allowing you the option to paste the script somewhere. I finally got the code by telling IDC that I wanted to install it on my gallery. Unfortunately, the script then had the wrong ID and I needed the correct one to have my comments logged at the correct blog. For this, I was able to just edit the WP plugin code and copy the ID from there. So I pasted the script in the template itself and, lo and behold, it worked! I now had comment capability on each author’s profile page 😀

Once this was done, I made a quick test comment to check if it works and noticed that IDC was logging a strange page title for the Author’s profiles. It seems that my theme is using a title for author archives as if they were a category archive and that would not do. I thus edited my header file and placed an if statement to check if it is an author page. On a positive, I changed the page to show a more appropriate title as well as the author’s nickname (through curauth again). Unfortunately IDC still kept grabbing some weird titles (or not at all) but it’s not caused by the title anymore.

Finally, I listed the authors of the blog on the sidebar through a php widget, I looked at it, and it was nice.

Theme Upgrade Fail

I never understand why upgrading to the newer HemingwayEx is such a hassle. This is the second time I’ve attempted it now (once more on 1.0) and I just now gave up.

What is happening is that I get the theme to work, I can change the colours just fine and switch to finally using widgets, but for some reason I can’t get the suckerfish dropdown to work and I keep running into various other problems (like my gallery losing its theme etc).

It wouldn’t be such a great problem if I knew where to start but what is happening is making me scratch my head. Specifically, even drop-downs start to work once I put the code in, they get hidden behind the background. That is, I can see the dropdown menu appearing (the top of it) but its somehow placed behind the main content and even expanding the navigation does not make it appear. Grrr

Anyway, it’s too much bother to figure out what is causing this so I’ll stay with my current version which still seems to be working fine. I will however attempt to widgetize it and perhaps upload it as a different version from HemingwayEx. I’ve aready created a sourceforge page for it (waiting approval still) and then possibly more people might be willing to help.

It only annoys me that I spent so much time on it and I still couldn’t get it to work as the current version.