PHP, cURL, and Expect: 100-continue

I’m writing a script which queries the Wikipedia API, and with that I’ve encountered an issue with cURL.

Wikimedia’s servers aparently don’t like the Expect: 100-continue header, and cURL seems to send it by default. Unfortunately, it seems the easiest way to disable it is just to override the header.

curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

Thanks to Matt Thommes and Stickman for their posts about this :)

My Development Environment

I thought I’d share my development environment with you, the basic tools and computer systems I use to develop software.

Most of my development is done on a Core2Duo 2×2.26GHz 4G RAM 1280×800 Win7 machine (taurus), occasionally using an Atom 2×1.6GHz 2G RAM 1024×600 Win7 netbook (orion) if I need portability, sometimes even testing on a Motorola Xoom (gemini).

My web production environment is a Linode 512 running Ubuntu (latest) hosted in London (blastoise), just the standard LAMP stack. Database hosting is done on a different machine, another Linode 512 also in London (metapod), which jointly serves as a code-review host. CI is hosted (spearow) on a Linode 1024 (you guessed it, in London), using Atlassian Bamboo as the software in question.

Source control is github, and I can’t say how awesome git (and the GUI tool Git Extensions) actually is! :D

As most of the development I do is either PHP-based or C#-based, these are the two areas I’ll cover.

If I’m working at home, I’ll write PHP code with Notepad++, and test it on my local server, IIS (yuk, but it does the job). I’ll still use the database server sat on metapod. If I’m not at home, and have an internet connection, I’ll do most of my work directly on one of my servers using GNU nano, and a plethora of GNU screen sessions. Everything still goes into git, and pushed to github.

Unfortunately, this tends to end up with hacks such as:

if(WebRequest::serverOS() == "WINNT")
{
   /* something specifically silly for windows */
}
else
{
   /* something posix-compliant, like sensible stuff */
}

Most of the time I try and keep most of that stuff confined to a file or two though, or try to find other ways of doing what I want without depending on OS-specific stuff.

C#.NET

Visual Studio 2010 Ultimate. Thanks, MSDNAA. Oh, Git Extensions too, but standalone cos the VS integration is annoying.

Progress reports really do slow things down!

This is something I’ve known for quite a long time, but if you’re ever thinking “it’s not that much extra power to add progress reports”, just make a mental note of exactly how many progress reports you’re making, and try commenting them all out.

BeebMaze generated a new maze in mere seconds, but at the same time, that was seconds too long. As part of refactoring, I took out the progress reports with the intent of putting them back in, since there wasn’t that many.

It now generates a new maze in about the time it takes to paint the screen once. :D

(Download this build from the build server now: Build #18)

Multi-lingual interfaces for a website

One of the uni projects I’m doing is a Hotel Management system for “The Blackfish Hotel”, as part of the third-year group project. Part of this is an online booking system, where customers can book rooms in the hotel.

Our “customer”, the manager of the hotel, has asked for the website to have a version in Finnish as well as English, as apparently a large percentage of his customers are from Finland. This posed a challenging problem for us to solve… well… sort of.
Continue reading

Pigs do actually fly!

Well, we finished the Computer Graphics project!

Take a look at some of the photos on the page about it!

It took more than a couple of nights in the Uni Linux labs to complete, but we managed it.

This was Vasileios’ first time using Git, and to be quite honest, I don’t think we could have done this without using some form of version control software. Other groups were messing around trying to dig the latest files out of each other’s home directories, which is a rather bad way of doing it. Git handled all of that for us automatically.

OpenGL is quite an interesting bit of software too, I’d not expected it to be quite so straight-forward. It’s simply a case of saying what you want to draw, giving it a set of vertices, and then telling it to draw them. You then can apply mathematical transformations to the set of vertices, and draw more vertices and transform those to build your final model. By using the matrix stack and some clever modelling techniques such as scene graphs, you can (for example) draw an apple, move it onto a tree, then move the entire tree plus apple to where you want it.

It’s been a very interesting project, even if the final rush and the heaps of documentation (read: 78 pages) that needed to be written almost overnight made me hate the module.

Regular Expressions Tester Engine

I’ve actually taken a bit of time to fix up, make user friendly, and publish a tool that I wrote a little while ago, and has been very useful to me.

The regular expressions tester engine basically provides a front-end to the Microsoft .NET Framework Regular Expressions engine, allowing you to test regular expressions you’ve written to your hearts content.

As usual, I’m releasing it as-is under the MIT licence, and as usual the source can be found on GitHub.

For a page which might have more information on it at some distant point in the future, but more importantly has a download and bugtracker link, see this page on my main website.

ACCBot’s recent breakage

A couple of weeks ago, the IRC bot that we use over at Wikipedia’s Account Creation Assistance project decided it would stop giving notifications to the IRC channel. Previously, it used UDP as the transport between the web interface and the IRC bot. However, for some unknown reason, this stopped working.

After seemingly endless messing around with PHP, netcat, more PHP and a bit of telnet, I came to the conclusion that it was fucked, and there was no way to recover it with any ease.

Previously, the code looked something like this:

For receiving notifications over UDP, that was all we needed – it worked and was semi-secure. However, when it stopped working, I took a more radical approach.

You’ve probably heard of Amazon Web Services (AWS) by now, if you haven’t then I recommend you take a look.

One of the AWS services is something called the Simple Notification Service, which seems to be exactly what I want – a notification system. However, the only notification endpoints are HTTP pings, e-mail, or an SQS endpoint.

SQS is what I chose eventually – it’s another of Amazon’s services, the Simple Queue Service. This has the “advantage” of queuing all the notifications so if you’re offline you will still get them all. However, for our case this isn’t ideal, but the bot isn’t usually down for long if it goes down. So, I decided to go for SNS->SQS over HTTPS as the transport for the notifications, rather than UDP.

Of course, code needed changing – at first I thought drastically, but it turned out to be a much smaller change than I anticipated:

It looks small, just another explicit check to see if we actually received anything. That’s until you realise that I wrote another function to take some of the work off to one side.

There’s not much that’s changed, but it was an interesting technical challenge :P The only thing that has noticeably changed is the lag from notification generation to display on IRC – can be anywhere up to about 5s if you’re unlucky!

Strobe Light

Growing tired of the poor strobe light applications available on Android Market, I decided to build my own.

Lots of the so-called strobe light apps which already exist on Market seem to be of the type which use the phone screen as the “strobe” – this isn’t good cos it takes a while to update the screen, and it isn’t as bright as the camera flash led.

My app is a very simple one – a quick loop to set the flash on, wait a while, set the flash off, and wait a while.

The two waits are configurable with sliders, with values of anything from 0 (theoretically) to 500ms.

The only problem is the fact that developing camera-based applications on Android is a bit of a dark art – not all manufacturers seem to use the Camera API to access their camera. Therefore, camera-based apps can be a bit hit-and-miss as to whether or not they will work. As I only have the HTC Desire, I can’t test it on anything other than the Android Emulators, and my actual phone. I have, however, had reports of it working on a number of devices, including the Samsung Galaxy S2, HTC Incredible, and the HTC Evo 4G. There have also been reports of it NOT working on the Galaxy Tab, Droid X, and the XT720 Milestone.

As all the flashing takes place in an infinite loop, there’s no time to handle GUI events. Therefore I branch out the flashing bit to a separate thread, and use Handlers to make the necessary calls back to the main thread to update the GUI as necessary.

The main reason to update the GUI is to make sure that should the strobe thread get stopped in any way, such as on activity changes or screen re-orients (currently disabled) etc, the GUI “enable” toggle button actually shows the correct status, as well as to easily display any error messages as necessary.

There’s still a few outstanding bugs (screen orientation!), and there’s a few changes I’d love to make to it, but it’s coming along quite nicely, I just need more time to actually work on it!

Technology updates

Quite a bit has happened recently!

I’ll try and give a bit of info about each, there’s quite a lot to write about though!

EyeInTheSky

An IRC bot which stalks changes to Wikipedia based on regex matches. Read more

caterpie beedrill as minecraft server

Those of you who use my Minecraft server will know that the server known as “caterpie” was bad. Any more than one person connected, and it would lag to the depths of hell. I’ve replaced it with a 1.7G beast of a server, still running as an Amazon server instance.

stwalkerster.co.uk

I registered a new domain! I’m still in the process of setting the thing up though, but that will become my main website, not quite sure what I’m gonna put there yet, but it’ll probably replace what webspace I had at http://helpmebot.org.uk/~stwalkerster/

ACC‘s IRC Bot, ACCBot

A couple of weeks ago, the IRC bot that we use over at Wikipedia’s Account Creation Assistance project decided it would stop giving notifications to the IRC channel.

I’ll write more about this at a later time, hopefully soon, but probably when I’ve finished messing with my new site :P

strobe light

Growing tired of the poor strobe light applications available on Android Market, I decided to build my own.

I’ll also write more about this too at a later time – I think this bit and the last one need their own posts.

EyeInTheSky

EyeInTheSky is one of my newer projects, an idea which I’ve stolen from two other people.

Wikipedia has so many modifications being made to it that it’s just not possible to keep an eye on everything you want to watch. While the MediaWiki software has a feature known as a watchlist, it’s neither flexible nor easy to use in my opinion.

EyeInTheSky is an IRC bot (seems to be my speciality!) which monitors the Wikimedia IRC recent changes feed, compares every entry to a set of regular expressions and reports them to a different network.

It’s possible to set up the bot with an entire XML tree of regular expressions matching on the username, edit summary, and page title. There are also logical constructs which allow more-or-less unlimited regexes to specify what exactly you want to watch.

For example, with this tree, I could specify I wanted to stalk all the edits which are made by someone with “the” in their name, “and” or “or” but not “xor” in the page title, and with “train” in the edit summary:

I also can set a flag, something that I can then set my IRC client to respond to, and it will speak that flag for every stalked edit.

Of course, it’s not just edits that can be stalked this way – log entries are sent to the IRC RC feed in the exact same way. It’s just a case of specifying Special:Log/delete as the page title to get the deletion log, for example. The entire log entry except for the time/user is sent in the edit summary field. This means the same system can be used to stalk log entries as well.

The bot logs all stalked edits, and is capable of emailing the entire log to me, so I can clear the log when I disconnect from IRC, and when I get back on, I can email the log, go through what I’ve missed, and catch up.

I’m planning on making it multi-channel too, with probably multiple people able to command it to email them the log. I can already tell it to not email certain stalks, especially as some of the stalks that have been set up are not things that interest me, but rather interest other people. I just ignore those when it reports them, and have it set not to email me for those stalks.

There’s quite a lot this little bot can do, if you want to learn more, I’d recommend taking a look over the source code, and see what you think!

The source code is available on GitHub here.