Toothpicks

September 25, 2010 · Posted in Blog · 1 Comment 

1. Moisten thoroughly in mouth.
2. Insert pointed end between teeth with flat side next to gums as shown.
3. Use gentle in-and-out motion to clean between teeth. Do not force into tight spaces between teeth.

It is official. The world has gone insane.

Lua

September 13, 2010 · Posted in Blog, Programming · Comment 

So, I went ahead and tried out working with Lua. For those of you unfamiliar with it, Lua is a lightweight scripting language which is usually embedded in other applications – for instance, a whole lot of games use Lua for various purposes (configuration scripts, AI, and so on). The whole package is pretty small (the static library is actually less than 200 kilobytes, and that includes the standard libraries!) and it performs extremely well.

A couple of years ago I used Lua quite a bit (only writing Lua scripts, not applications that employ Lua). Back then I used to know it pretty well, but that was years ago. Not using the knowledge for so long combined with updates to the language make it necessary to re-learn a lot of things. But fortunately, Lua is actually a very simple language, it doesn’t come with tons of things we don’t need, the syntax is easy, and it has a couple of nice features.

One thing I love about Lua is the ability for functions to return more than 1 value. In pretty much any other language, a function can only ever return a single value, but often we want to return more data than that. In C/C++ the “obvious” workaround is to use additional function arguments, which will be pointers to the location where the result data is written to. Lua, on the other hand, does allow functions to return more than one value.

So instead of a complex function call with lots of arguments where you’re not really sure if they actually affect the behaviour of the function or if they are used to pass a result back, we can do this in Lua:

result1, result2, result3 = somefunction( argument1, argument2, argument3 )

Getting the basics of Lua working on your system isn’t that hard. It is downloaded in source form from the website, and needs to be built into a library (which you’ll also use if you write any applications that use Lua), the Lua interpreter (lua.exe), and the Lua compiler (luac.exe), which pre-compiles Lua scripts into bytecode (optional but does increase performance a bit). On Linux this is of course an extremely trivial task (tar xzvf lua-5.1.4.tar.gz, cd lua-5.1.4, make, make install), on Windows it’s a bit more work but still easy enough.

Then comes writing a little test application that calls an external Lua script, followed by making said test application a bit more complicated (by setting variables, adding functions, calling functions inside the Lua script, and things like that). To the untrained eye a C/C++ program that embeds Lua may seem complicated, but it’s really not that bad: Lua uses a stack for most of its work, and once you see how it works, it’s actually quite easy to work with. A lot of the work you do is just pushing or popping values to/from the stack.

I wonder how easy (or difficult) it will be to make Lua run from an embedded CPU.

Wiki

September 11, 2010 · Posted in Blog · Comment 

I set up a private wiki for myself last night :)

The thing is, I tend to gather a lot of random notes and things in text files. Also, I have an astonishing and ever-growing amount of bookmarks, which I usually have either on my PC but not on my laptop, or the other way around (and of course, I always need them while I’m using the computer that doesn’t have them).

Because that is rather inconvenient, and because I generally hate having lots of random text files and garbage around on my desktop, I decided to set up a wiki for myself, where I can dump all those random notes and little things. Any important bookmarks also get copied to the wiki. This way I can access them wherever I am, and keep my PC clean at the same time. Yay!

I can probably set up a little script to import bookmarks from the wiki into Firefox and run that on both my PC and laptop, that would be the ultimate awesome :)

Scratchpad

August 20, 2010 · Posted in Programming · Comment 

A few days back, I thought about if it would be possible to run SQLite on an ARM processor. If you can provide it with a filesystem (say, an SD card for storage), and get the memory usage low enough (or get an ARM with a ton of memory/external memory interface), I do believe that this would be possible.

Another interesting idea: Lua. As in, Lua, the scripting language that powers a lot of games, among other things. It would be interesting to run that from an ARM, again with the SD card for storage (its awesome if you can store your scripts somewhere). The libraries are small enough, if I recall correctly. I think it could work.

Thunderfail

August 11, 2010 · Posted in Blog, Random Things · Comment 

It seems that updating my copy of Mozilla Thunderbird on my laptop involved deleting the main program executable, because that is what the updater did.

Sure, it’s guaranteed bug-free now, but the number of new features is pretty disappointing.

Starcraft 2

August 10, 2010 · Posted in Games · Comment 

I’m not at all a big gamer. I enjoy the occasional game (usually leading to ‘oh crap, it’s 5 AM already?’ moments), but I don’t play a whole lot. But, after all the buzz surrounding it, I wanted to check out Starcraft 2.

I only played the campaign. I usually get kicked big time in multiplayer so I’m not even bothering to try that.

Anyway, I have to say, the campaign is fun to play. The story isn’t particularly good or revolutionary (and pretty predictable), but it serves its purpose of sending you in a direction where you can blow stuff up. (Yay for blowing stuff up.) What I do like is how the campaign is done: usually in an RTS the campaign is linear: you have to do mission A, then mission B, then mission C, repeat until end. In Starcraft 2 you get to pick what you want to do when, and not everything is mandatory. Doing missions does however grant you more types of units, allows you to purchase permanent upgrades for your forces, and there is the research thing which makes things interesting as well.

Most missions are the same in the basic turn of events – ie you go somewhere, you build a base, train forces, attack (or defend) something, and ‘lo and behold, the mission succeeded. It does not however feel repetitive to do so, which is obviously a good thing. Several missions have interesting twists to them – one for instance (and don’t read this if you don’t want a spoiler) involves a wall of fire, caused by a sun about to go nova, that slowly moves accross the maps and forces you to push onwards and relocate your base several times over. This relies on the interesting (though realistically speaking, completely absurd) possibility of letting most of the building in your base take off, fly somewhere else, and land again. You’ll need to rebuild a few structures after each relocation but most can be moved that way.

The campaign plot is pretty generic. Rogue hero fights against evil empire to free the people (and of course the inevitable element of rescueing a long lost girlfriend), slowly gets to his goal, after gaining some sort of a foothold comes the ever-present inspiring speech after which the troops march into almost certain doom and succeed againt all odds. The girlfriend of course is saved, the old friend who betrayed the hero is killed, and they all happily watched the credits roll over the screen.

While theĀ  campaign is fun to play, the core of the game is similar to pretty much every other RTS that’s out there. You’ve got the technologically mediocre humans who, of course, are the big good guys who rule over most of the galaxy, there’s the mysterious ancient alien race with expensive but strong units, and the guys that rely on hordes of weak units to flood their way to whatever their goal is. The game mechanics are fairly uninspiring but they work well and do provide a good couple of hours worth of time-spending.

One thing I do love big time is the mech unit called ‘Thor’. Like most mech units it is entirely unrealistic, but it’s voice sounds like Arnold Schwarzenegger and it has some of the more awesome quotes I’ve heard from RTS-game-units in a while. It bothers me that it is not really THAT powerful and you need a bunch of them to really do anything, even though it is supposed to be based of Odin, a really giant mech that pretty much vaporizes anything (where did he go after the broadcast tower mission, anyway?), but the line ‘I am here, click me!’ easily makes up for that. Most of the other units’ speech is less interesting (and especially in case of the marines, starts to annoy really quickly), but who listens to that anyway.

Overall I’ve so far found Starcraft 2 to be enjoyable, but to say that it’s a big revolution that was really worth waiting so many years for… ?

No, not really.

Blue Toys

August 7, 2010 · Posted in Electronics · Comment 

I got a new toy in yesterday: the NGX Technologies BlueBoard LPC1768-H. As the name suggests it is a blue board with a LPC1768.

What is a LPC1768? Well, it’s a microprocessor. More specifically, an ARM Cortex-M3 capable of running at speeds up to 100 MHz with 512 kb of Flash memory, 32 kb RAM, and a huge load of peripherals: eight DMA channels, Ethernet MAC, USB 2.0 (Device/Host/OTG), four UARTs, 2 CAN channels, SPI, I2C, I2S, 12-bit A/D converter, 10-bit D/A converter, 4 timers, and a real-time clock – amongst others. Disregarding peripherals, it comes with up to 70 GPIO’s (the chip itself is a 100-pin package, part of which is dedicated to things like power, crystal, and the JTAG interface).

It puts any PIC, AVR, or similar small micro to shame.

The reason I went with this particular board is that it doesn’t come with crap. Most development boards out there come with tons of circuits and peripherals (buttons, LEDs, LCD displays and whatnot) and don’t leave a whole lot of room to do what you actually want to do with the board. This one contains just the chip, all the basic supporting circuitry, a few things like a USB connector and an onboard LED for testing/status-displaying purposes, and all other pins are broken out on standard .1″ headers. Yay for that!

The board comes from NGX Technologies. I ordered from them directly – SparkFun also sells the board, but the SparkFun price was about as the total cost of the board and shipping directly from NGX, so that’s an easy choice. They were pretty quick with shipping – I had the package delivered via the EMS service. At first they e-mailed me warning about previous bad experiences with a package getting held up in customs, but that’s not the fault of the shipping service. Since the alternative was a lot more expensive I had them ship EMS anyway and it went fine, the package was here in about a week.

I’m using the Olimex ARM-USB-OCD programmer (starts at about $50, and is really the way to go over the parallel port Wiggler-type interfaces, which tend to be glitchy and slow), combined with Rowley CrossWorks for ARM ($200 for a home use license). Currently also connected to the board are my Saleae Logic (inexpensive, very user-friendly 8-channel USB logic analyzer – very happy with this one!) and some breadboard with RS232 line level converters, hooking up the chips UART0 and 1 to my PC.

I’ve never dealt with these chips before, and there are a few things to be aware of:

  • In CrossWorks, you need to create a project (with the LPC1768 as target chip) and have that project open before the JTAG interface will connect to it. If you try to connect without an open project, it will say ‘target not responding’. This had me stuck for about half an hour at first.
  • The startup file (LPC1700_startup.s) that comes with the CrossWorks LPC1000 support package by default does does not jump to code execution after a reset. There is a good reason for this (explained in the comments in the file). Your code will only run if you use the ‘Build and Run’ option (from the ‘Build’ menu), or when the STARTUP_FROM_RESET preprocessor directive is defined (at which point the startup code will jump to main() as normal).
  • As with most electronics things, the first task is to get a blinking LED. The BlueBoard has a LED at pin 1.29. The initial delay routine I wrote consistently blinked the LED at 333 KHz no matter how long or short I made the delay loop. It turned out that the compiler optimization had a hand in this. After disabling optimization (build configuration under ‘Code Generation Options’), doing nothing for 4 million clock cycles produced a neat 1 second delay. (4 MHz is the default speed from the on-chip oscillator, at which the chip will always run after a reset; I’m not spinning it up to the full 100 MHz just to blink a LED :P ).
  • If you buy the Olimex ARM-USB-OCD, it comes with a DC jack outlet and a short cable the purpose of which is to power Olimex-built development boards, but it also works perfectly fine with the BlueBoard, removing the need for a dedicated lab power supply (though I’d prefer to use that anyway, since it can provide much more power than the USB port can and removes the risk of blowing up said USB port in case of a short).

Overall, even though the BlueBoard lacks an on-board RS232 level converter (which is useful, since RS232 is the best invention since sliced bread, or at least, it is when you’re dealing with embedded software) and there is no documentation to speak of (aside from the board schematic, which does contain all the info you need though), there aint much that can beat it, especially at the price. I would definately recommend it to anyone looking for an ARM to play with.

Coding…

July 21, 2010 · Posted in Programming · Comment 

I’ve been doing a bunch of PHP stuff lately. One interesting project is the template engine, which has seem some really awesome progress over the last weeks. But more on that later…

Something else I’ve tried out a few days ago is using memcached. Memcached is a small server program that runs in the background (as a service on Windows machines, or as a daemon on Linux) and uses spare RAM to store data. It can also run distributed, with a bunch of servers all throwing their spare memory into a big pool which can conveniently be accessed as if it was on a single machine. PHP has a standard plugin that can communicate with memcached – what can you do with that, you wonder? Well, as the name suggest, memcached is a cache which stores data (in key/value) pairs in memory. Basically your script can store data in it so you don’t have to fetch it from the database (saving you from executing a time-consuming query and putting load on the database server).

It is actually quite efficient – all of the world’s big websites (especially a lot of social networks and such) use it. Some sites even have massive amounts of servers dedicated to it. In such setups getting everything right is tricky (you want to be sure that everything is consistent – with a large distributed system it’s easy for something to go out of sync, potentially causing a lot of trouble), but it is quite useful.

I played with it for a bit and it turns out that memcached is really very easy to work with. Installation on my Windows box was a matter of putting the executable in a folder and running it command-line with a few options that make it install itself as a service, after which it is permanently available; accessing it from PHP takes no more than adding a standard plug-in to your php.ini file, restarting Apache, and calling the right functions. It’s actually very easy to work with. A quick measurement told me that, when loading some configuration data using memcache vs. loading it from the database, doing it from memcache is actually twice as fast – and that’s for a trivial task.

Unfortunately you’re not going to get memcached support with any basic shared hosting plans (and VPSes generally don’t have the spare memory capacity). It takes a bunch of setting up, securing, and firewalling to make it run securely in a live environment and you can’t let multiple users share the same memcached host without them being able to access eachother’s data. It’s a bit of a downside, but memcached was never intended to be used in a shared environment, so it’s not a big deal.

The project I’m working on right now is actually getting full-blown memcache support, so it will cache anything that can reasonably be cached (within configurable limits), making the whole thing run faster and using far less database queries.

Next up, the template engine. I’ve already written a template engine quite a while ago (several actually) – but I wanted to make some improvements and ended up rewriting most of it. If you don’t know, a template engine essentially separates presentation and program logic, which is very useful if you want to encrypt the actual PHP code without removing the ability to edit the HTML, or just generally to organize things – it makes it very easy to figure out where you need to be to change something, and even non-programmers can easily edit the layout of the page this way.

The previous incarnation of my engine supported variables and blocks. Variables are well, variables, and blocks can either be repeated any given number of times (the contents of variables can be varied for each instance – so this is what you would use to fill a table with data, for instance) or entirely hidden. This is sufficient in a lot of cases, but I wanted to add more: conditional statements, loops (other than repeated blocks), proper caching, and so on.

Previously, all parsing was done in the final processing function, which did everything by reading files and releasing a bunch of string manipulation functions on them. It worked, but the code was complicated as fuck and debugging (let alone adding something new) is a whole new kind of hell by itself. The new version uses a system not unlike what a compiler for, say, C, does: it splits the input data (the template file(s)) into a bunch of tokens (textual data, variables, blocks, etcetera), runs a lexical analysis check (grammar basically – make sure that the end if your if statement does not precede the actual if statement, for instance), and finally, goes over the list of tokens (using a specialized stack), combining it with the dynamic data (contents of variables, block instances, etcetera) to produce output.

That all sounds terribly complicated, and well, it is. One major advantage though is that now 90% of the processing effort (parsing and analyzing the template) can be stored for later use, and the engine does that either by files, or by sending the data to memcached (the latter being preferred, since it doesn’t involve hard drive activity, which is relatively slow). The result is a very powerful and fast system, in which it is actually possible to add a new feature, should the need for it arise.

The whole beast has a ton of features – variables (both local and global), blocks (plus ‘empty blocks’, something that gets shown if there are no instances of the block), conditional statements (if/elseif/else – admittedly expression handling is very basic at the moment, but that’s for future improvement), caching, variable modifiers, a bunch of debug features, tools like optionally stripping HTML comments from the final output – and the whole thing weighs in at ‘only’ 2650 lines of code (including tons of comments and whitespace) / 73.2 kilobytes (all in a single file). It’s definately not finished yet, but I’m quite satisfied already :)

Oh, and also, I now use NuSphere PhpED. Most of the time, IDE’s mostly manage to annoy the crap out of me, but this one actually works instead of being a constant pain in the ass. I’d definately recommend it.

Dvorak

July 15, 2010 · Posted in Blog · Comment 

This night I took all off my keyboard for a good cleaning. While I was at it, I re-arranged the keys to the Dvorak layout (which did require me to cut a few small pieces of plastic, but hey, it all fits and works now). And if I end up not using it too much, it’s okay since I can type in QWERTY blind (and really fast).

So, right now I’m typing REALLY slowly… But I’ll get used to it. My speed (and average amount of time spent searching for each letter) has already decreased significantly while I wrote this post – I can already find some letters blind (especially the ‘A’) – or at least, without spending half an hour searching for it

No, my experience in typing with Dvorak does not extend very far beyond this post… But practice makes porfect, and I am already noticing that the letters are arranged in a more logical way :)

Dragons

July 9, 2010 · Posted in Games · Comment 

Today I read that Bioware officially announced Dragon Age 2, sequal to Dragon Age: Origins. Yay!

I’m quite excited about this. I really liked DO:A (and hence did two playthroughs, despite the amount of time it takes to get through the storyline). Even though in some cases I got the feeling that everything was deliberately made more difficult to lengthen the game rather than to add something to the overall storyline, it’s one of only a few games that managed to really grasp my attention in the last year or so. So that is pretty damn good.

DA:O Awakening (the expansion) was good too – rather short compared to the original campaign, but definately enjoyable!

And to all people who whine about how there is too much dialogue and interacting with NPCs and having to deal with the storyline:

That’s the whole f*cking point of an RPG.

If you don’t like dialogue, then go play a shooter or something. Or Pong. I don’t care.

« Previous PageNext Page »