NoshBar's Dumping Ground




Rambly introductory


Until recently, I had no reason to code something in Python, as I had all my bases covered by C/C++, ObjectPascal, and PHP.
Lately work has had me pottering with some utilities written in Python, and even though I don't "know" Python, I could read the code just fine (as I guess is the case with most coders), and it seemed like something that would be good for quick prototypes (especially as my main development machine is now a Mac - it comes with Python pre-installed).

So I set myself the task of re-creating HelperMonkeyBot in Python.

Things I used


Having had some frustrations with getting an XMPP library and its dependencies set up and working with cross-platform C++ compilers, I was delighted to find SleekXMPP, which is easily installed by typing:
python setup.py install
I had Python 2.7 on OSX and Linux, and Python 3.2 on Windows.
I figured this would let me target the two different versions (and -hey-, how different could they be? More on that later, SIGH).

As before, I used SQLite for the database, using the full-text-search capability it provides.
This seems to be enabled in the OSX and Linux distributions I was using (10.7 and 11.10, respectively), but not on Windows Python 3.2.
The easy fix is to go the SQLite website and download a new sqlite3.dll and plonk it in the Python32\DLL folder.
Well, it WOULD be, but I guess the API has changed (or something, I didn't have the patience to check)... so I did what any impatient prototyper would have done (just me?) and uninstalled Python 3.2, and installed Python 2.7, replaced the DLL as before, and et voila, success!

For an editor/IDE, I initially just edited the code in Xcode, but that provided very little other than syntax highlighting.
So then I tried SPE, which was great, I could debug code, set breakpoints, do all the things I'm used to with compiled code... buuut it would sometimes crash, or just act weirdly. Nothing deal-breakery, but my lust for shiny new things had to be met, and it was the perfect to excuse to look for MOOORE.
I then used Aptana Studio 3, which has PyDev support built in, and worked pretty well (apart from the eye mangling default theme)... but still didn't feel quite right.

After much elimination and many crying supermodels, I finally chose Python Tools for Visual Studio... what can I say? I absolutely adore that IDE.
All the shortcuts I know, incredibly quick stepping through code (with Python 2.7 anyway), easy process killing, warnings in the IDE about mismatched white-spacing... it just felt right for me.

The story so far...


Despite the warnings and dismissals from internet experts and people I know, my opinion is that Python doesn't suck too bad.
I know my opinion is worth as much as the rest of the experts, but it boils down to this:
Bad code is bad code, how bad it is depends on how much you let yourself abuse the available functionality.

This initial code for HelperMonkeyBot must be horrendous to seasoned (hmm, salty) Python coders, but it's a stepping stone for me, and one I am proud of.
Not because I learnt a new language, not because I think it's great code, but simply because I didn't abuse it too much.

I think the thing I like most about Python is the same thing that has me liking Pascal/Delphi still:
people who provide examples in Python/Pascal provide code that is understandable, and seemingly want to explain things more than C/++ coders.
For years I would search for things like "avi player delphi" because the code would be easy to read, and there would normally be an accompanying article.
The great thing is that Python seems way more popular than Delphi, so a whole new world of easy-to-understand code has opened up to me, huzzah!

So, soon I will provide an updated HelperMonkeyBot (I'm testing it at the moment) which -thanks to being in Python with some easy to use helper libraries- sends mail reminders.
Not the world's most amazing feature, but considering the C code I'd have to do for that... YAY!

[ view entry ] ( 1146 views ) permalink print article

So, I finally managed to get myself a TouchPad, and it's even more awesome than I thought it would be.
It's currently set up to dual boot between Android and WebOS, and it runs Ubuntu within WebOS just peachily.
WebOS just feels so good to use, the browser just _feels_ nicer to use than Android's or iOS's.

Anyway, kicking the nerdiness up a notch, man oh man is the PDK nice and easy to use, providing OpenGL and SDL from the start, with the ability to test and debug things on Windows.

The fairy tale version of my porting story: I barfed up a bit of SDL bootstrap code to create a window and handle inputs, and everything else just worked!

The real version: I am a bleeding tool. I initially looked at the PDK samples, one called "simple", which included an OpenGL ES 2 header file.
So I went on a learning escapade where I FINALLY addressed my lack of GLSL knowledge and suspiciously loving attachment to the fixed rendering pipeline.
Shaders and whatnot had never made sense to me, until I found this awesome tutorial.

So I finally had some shaders up and running, I had some hand-coded matrix maths stuff going, I had 3d models on screen and rotating and... annoyingly disappearing (some Z issue) and going all over the place.

In an effort to see what else GLES 2 provides, I decided to see if there were any other header files...
There were/are.
An OpenGL ES 1 header file.
DAMN MALE OFFSPRING OF A FEMALE CANINE!

So yes. Drumpster runs on the TouchPad fantastically.
Take that Joggler.

Oh, and I found and fixed the bug in MonkeyBot... and got it running on the BeagleBone and Bifferboard.
I'll upload the new code "soon".

[ view entry ] ( 310 views ) permalink print article

While that's not strictly true, I am overly paranoid about a bunch of things, opening a port on my firewall being one of them.
Not because I think SSH might have flaws, or the firmware on my modem, but because I'm a complete dufus with no self-esteem who doesn't trust himself, and I really don't feel like setting up my PC again, post internet-abuse.

Sooo, introducing (Helper)MonkeyBot, a little instant messenger bot that sits and worships and listens to your commands.
You also get a single-page PHP file to view the stored messages more purdy like.
MonkeyBot is open source and released under the ZLib licence, and is thus compatible with its dependencies, SQLite and Gloox (which uses GnuTLS).



It's a little program that logs into an XMPP account and listens for commands from another specified XMPP account (with a secret handshake phrase), and basically stores whatever you type to it (with a category), with the option of recalling/viewing/deleting/searching the data via IM, as well as downloading files for you so that they are ready by the time you get home.

An example dialog would be:
nashbor@gmail: Hey Asshat.
monkeybot@gmail.com: What do you want?
nashbor@gmail.com: todo: Make Drumpster less poo.
monkeybot@gmail.com: Stored. (MessageID: 1)
nashbor@gmail.com: download:http://www.3dconstructionkit.co.uk/3dkit/PC-3D_Construction_Kit_2.zip
monkeybot@gmail.com: Stored. (MessageID: 2)
...<time passes so slowly, slowly...>
monkeybot@gmail.com: Download finished successfully: PC-3D_Construction_Kit_2.zip
nashbor@gmail.com: search:Drump*
monkeybot@gmail.com: ID1: Make Drumpster less poo.
monkeybot@gmail.com: Search finished.


MonkeyBot is super easy to compile on Ubuntu.
apt-get install gcc g++ libgloox-dev
change to the folder with the 7 or so MonkeyBot source files
compile sqlite with FTS4 support
g++ *.o *.cpp -lgloox -lpthread -ldl

On any other platform though... I came across some PITA's:

Not every version of Linux has a package manager, especially when trying to use embedded systems, so you're stuck compiling things for yourself.
I spent much too long trying to get libnettle to compile (WHY? Why can't you see the libnettle include files? The paths are PERFECT you piece of gangrenous armpit slug!), which GnuTLS needs, which Gloox needs.

For Windows however, you can get a precompiled GnuTLS DLL and DEF off the gnu website, which you can create a LIB file from, and link against in Visual Studio.
I thought it would be:
Compile Gloox, linking to GnuTLS. (of course, you have to remove some files from the solution and make a typedef before it will compile)
Compile MonkeyBot, linking to Gloox.
Make sure all the GnuTLS and Gloox DLL's are in the MonkeyBot.EXE folder.
Run.

But nooo, that gave me weird connection issues in Debug mode, or a crash in Release mode.
However, deleting all the GnuTLS DLL's from the .EXE folder made the Debug build connect just fine all of a sudden.
My random-unproved-and-probably-shitty theory is that the Debug Gloox.DLL includes the GnuTLS stuff, at least it should, given its size.
As for the Release mode crash... some std::string thing that I couldn't be bothered trying to find out about.

I'm considering rewriting the ChatEngine class so that it can use either Gloox or the XMPPFramework for OSX/iOS... with plans to run MonkeyBot and Apache and PHP and the viewing program on a poor abused jailbroken iPhone I got handed down to me by someone rich because I'm so 3rd world.

Anyway, it works for me for now, I discovered a crash when creating custom actions JUST as I was uploading the files to my site... so I guess v0.2 will be coming soon... annnd that you should probably take the time to learn about cron and watchdog scripts...
Lots to still be done on MonkeyBot, like remote shell, not sucking, reminders that do something actively...

Use it, don't use it, I don't care.
Rock on.

[ view entry ] ( 344 views ) permalink print article

|