Wednesday, March 28, 2007

On SQLObject

I have recently used SQLObject in a few projects. My first encounter of SQLObject was as a component of TurboGears, a framework for creating web sites. But I soon realized that SQLObject can be quite handy on its own.

What is SQLObject then, really. I don't want to do a full tutorial on SQLObject, so please head over to the SQLObject website to familiarize yourself with it. In short, it is a object oriented wrapper to SQL databases, for Python. You can freely choose among several different backends, like SQLite, Mysql, Postgres, and so forth, and most of the details of the particular backend you use will be hidden within SQLObject. If you want to create a table with SQLObject you simply say
class MyTable(SQLObject):
name = UnicodeCol()
date = DateCol()

(assuming you have done from SQLObject import *, which you of course have not). SQLObject takes care of all the SQL woodoo, and you can go ahead saying things like
mt = MyTable(name="someday",date="2007-03-28")

To get rid of the entry again, you just say
mt.destroySelf()

In addition to get rid of the object within your Python code, this also removes the corresponding row in the table on the sql server.

So far all good, and quite stright forward. Next, you want one-to-many relations, or maybe many-to-many relations. No problem, SQLObject can handle those as well, using MultipleJoin or RelatedJoin, together with ForeignKey. Assume that you wants a many-to-many relation between the MyTable above, and some other table:
class FooTable(SQLObject):
name = UnicodeCol(alternateID=True, length=50)
mytables = RelatedJoin('MyTable')

To get symmetric behaviour, you also wants
  foos = RelatedJoin('FooTable')
inside MyTable. With this setting, you can still use destroySelf(), and SQLObject figures out the right thing. So, that was many-to-many relations.

Now, I had a one-to-many relation in my code, like this:
class Foo(SQLObject):
name = UnicodeCol(alternateID=True, length=30)
mybar = ForeignKey('Bar')

class Bar(SQLObject):
name = UnicodeCol(alternateID=True, length=30)
foos = MultipleJoin('Foo')

So, this is a one-to-many relation, as Bar may have many Foo's, but Foo only link to one Bar. Then I did something like:
b = Bar.byName('mybar')
b.destroySelf()
Only to discover that I got errors next time I tried to do anything with the Foo's. Reason was that there was Foo's still linked to the Bar I destroyed. Thinking about it, this make perfectly sense. It also shows that SQLObject is not perfect in some sense. It does what you tell it to do, even when that is evil. This can be both good and bad, depending on how you look at it. Fortunately, the fix is quite easy:
if len(b.foos) > 0:
print "There are still Foo's linked to this Bar"
Then of course more lines, if you want to deal with it in code - like relinking the Foos to other Bars, or just leave the user with that message - probably followed by some raise to signal an exception.

If you go out there search the blogs, you will find people telling you that SQLObject is not good. They are probably right. But to me, it felt just right from the very beginning. When I dig deeper into it, I will probably complain too. But so far I am happy. Nevertheless, I see that something called SQLAlchemy is mentioned together with turbogears now, and I guess SQLAlchemy is a replacement for SQLObject. I have to check that out, maybe it is even better. Until then, I stick with SQLObject, at least for non-turbogears apps, because I think it does its jobb very well.

Take care folks, and keep that Python code flowing from your hands.

Monday, March 26, 2007

Could it be a favourite?

Now, this is something. Spotted this over at Gizmodo today:

HTC Shift is the UMPC for UMPC Haters - Gizmodo: "HTC Shift is the UMPC for UMPC Haters



It surprises even ourselves when we say that HTC's Shift should be the UMPC device that makes us—who were mild on UMPCs before—a fan of the platform. Instead of using a split keyboard or a *shudder* on-screen circle pad, the Shift makes like the Advantage with its sliding and flipping screen. With the input problem solved, you can really enjoy the 7-inch touchscreen, 30GB hard drive, Tri-Band UMTS/HSDPA, Quad-Band GSM/GPRS/EDGE, Bluetooth 2.0, Wi-Fi, and Windows Vista."

Look at those specs! With a 7" screen, this shouldn't be far from my PictureBook in size, which I have blogged about earlier - go search if you wonder what that's all about. Size should be just right for an ultraportable, the built in connectivity looks like what I have missed on all my small computers (except the HTC TyTN) so far. And the ability to run Vista probably make it possible to run a real OS as well, like linux. And the device even have a nice look.

I am so close to order a Flipstart as soon as that will be possible, as I really need a modern small computer. But this looks much more like what I am after.

Q3 of 2007 is ETA. That's way into the future. Can I wait, or do I need something in between?

Friday, March 23, 2007

Here we go again

What should I say - you know the drill now. It's a new version of qtpfsgui out. The upstream maint. working really hard, so I have to keep up. So, v.1.8.3 of qtpfsgui for mac is out. This time on sourceforge, where it really should be. But sourceforge is a crazy system, I think I did it right, but it is hard to tell.

If sourceforge does not work for you, you may also grab qtpfsgui at my other site

Take care!

An updated dmg of qtpfsgui 1.8.2

I recompiled the qtpfsgui v.1.8.2 today, with debugging info turned off; that is enabled Release mode in Xcode. I also added the icon used on the Linux version, such that it shows up in Finder and Dock. Enabling release mode actually reduced the size of the binary to 1/4 of the original size . I was quite suprised that the difference was that big. The program even feel a lot more snappy.

So, reminder to self: Turn off all the debugging before I throw apps at folks, at least if I don't want them to debug for me!

Go grab from at the usual place. I see if I can get it up on sourceforge as well. But I also realized that 1.8.3 of the app is already out, so there will probably be another update on this before I can call it a day :-)

Take care folks, and let the HDR flow from your Macs!

Thursday, March 22, 2007

Flickr: Popular cameras

Flickr: Camera Finder: "Most Popular Cameras in the Flickr Community
% of members

* Canon EOS Digital Rebel XT
* Nikon D50
* Canon EOS 20D
* Nikon D70
* Canon EOS Digital Rebel XTi"




Flickr shows this graphics on their site in the popular cameras section. I think it is in particular interesting to observe the trends of the XT compared to the XTi. When XTi first is out, the curves for XT and XTi continue increasing - XT owners keep their XT and discusses with spouse about switching gears. Flickr attract a few of the new XTi owners. Then suddenly the XT curve starts dropping almost with the same rate as XTi increases; XT owners have made up their mind, or convinced the spouse - lets go for the new stuff. The decrease in XT isn't as fast as the increase in XTi in this period, as some of the new XTi flickr memebers keeps the XT around because it still works, and they are more familiar with it. After a while, this stabilize - some XT owners think XT is good enough, some thinks the new XTi isn't good enough and decide to wait for the next one, some keeps both, etc...

It is also interesting to see that this whole story is completely decoupled from the other cameras, like the Nicons and Canon 2oD/30D. Different camps.

Now, what about me? I (or my wallet (or my spouse)) have decided that I wait until the next one. Really, I want the 40D i guess, whatever that will be. I presume EF-S mount (x1.6 crop), DigicIII, better high-iso/noise ratio, etc. But I'm not sure what my wallet (or my spouse) decide.

That's enough for todays observation. Take care, folks!

Sunday, March 18, 2007

New version of qtpfsgui!

Hi there,

Giuseppe Rota has released a new version of qtpfsgui over at sourceforge, it's now at version 1.8.2. I have compiled an universal binary, but have not packaged it up yet. Stay tuned, it will appear here, and hopefully at sourceforge as well, tomorrow. For now, adventurous people can grab a zip-file with the app.

The problems with my 1.8.1 on PowerPC was presumable due to some alignment problem, and should be fixed in this version. For those of you who know what I'm taking about, I'm happy to get some reports!

Update 19.03: One user reports that the colorproblem on PowerPC with the 1.8.1 version is fixed (by upstream maintainer, Guiseppe Rota) in this version.

Second update 19.03: The dmg for v.1.8.2 is now up at one of my other places. There seems to be a problem with sourceforge tonight, but as soon as that is sorted out I will make this as a release there. Future releases of the MacOSX version of qtpfsgui will probably only be at sourceforge, but I will continue to comment on it here.

Friday, March 16, 2007

Python, flickr, and Unicode

I found a script the other day, for generating a wallpaper based on images from flickr. In its original form, the script expected one or more tags as argument and get a number of random pictures from flickr that have these tags. I wanted to make it a bit more interesting, so I looked at API at flickr to see what is available, and discovered the getHotList method. I added this method to the python wrapper of the flickr api I am using (one of those listed under Python at the site), and changed the logic slightly to fetch the 3 most popular tags during the last day if no tags are given as argument.

And now comes the interesting thing. The getHotList gives you tags in unicode, looking like u'mus\xe9edelelys\xe9e' (one of the popular tags today). But when this tag is fed into flickr.photos.search to retrive urls for some images, an exception is thrown, as the method can not use this tag format. More or less obviously, it needs to be on an urlencoded form, as we are communicating through http. Reading documentation here and there, I figured out that unicode was expected, but more on an ascii form. The tag mentioned here should look like 'mus%C3%A9edelelys%C3%A9e'. After quite a few minutes with google, I figured out a possible solution:
tag = urllib.quote(tag.encode('utf-8'))

Looks kind of funny to me, but it works.

Lesson learned: Unicode is not unicode is not unicode.

Wednesday, March 14, 2007

Maybe I should reconsider

I haven't bother to look very close into the 802.11n topic. As all of you know, we have for some time now been able go to our store and buy Draft-n equipment. That is supposed to be hardware implementing what is now know as the draft 802.11n specification; the new fast Wireless network. And further supposed to be easy upgradeable or cooperative with final Draft-n (or just -n) hardware.

My position on this up to now has been to not buy Draft-n stuff, because of 1) can I be sure it will actually work with final-stuff, 2) there isn't much of client support yet, and 3) I expect the final stuff to be just around the corner. I truly belived that, until I read over at extremetech today:

Draft 2 of 802.11n Standard Sails Through: "Following those changes, Draft 3.0 is expected to emerge in late 2007 and gain approval by early 2008. The IEEE says Draft 3.0 will, for all intents and purposes, be the 'final 802.11n' in all but name, and that the final spec is now expected in April 2009."


April 2009! That's not just around the corner. I'm not sure I can wait that long. At least that is a problem if we want to go for VoIP on WiFi at work. Not that we are seriously considering that at the moment, but it is really something I like to be able to do not very far into the future. I probably have to go back to the place, which I do not know where are, where I can think long and uninterrupted thoughts, figuring out what is the best thing to do. Should we go draft-n now? Should we go draft-n when it is really Draft-2.0-n or is it best just waiting.

Besides, draft-n is popping in on clients all over the place now. Apple have it, thinkpad-which-we-dont-like-after-lenovo-takeover seems to have some new models with it in the pipe, Dell have cards, Engadget have reported on Asus laptops with it, which we do love more than lenovo these days. And the list will go on and on, and I do not want to be left out in the slow and cold dark.

That was just a few thoughts an evening in the middle of march.

Take care, folks!

Sunday, March 11, 2007

Updated version of the qtpfsgui

Today, I finally manage to build an universal binary qtpfsgui for MacOSX. This time the only external dependency is Qt, at least should be. The program works for me on intel-mac, but I have to test it tomorrow at work where I have access to a power-mac. Also, I have to verify that I actually have removed the external dependencies as much as possible. If you don't have Qt installed, get it from trolltech. The download link to the MacOSX binary may be a bit hard to find, this is a direct link!

Please, if you like to try the program, go grab it here. And if it works for you, I very much like to hear about it!

I will probably write up a bit more on the process of creating all the components as universal binaries, and then some issues on qmake. But now I have to make some dinner for me and the kids.

Update: I have now verified that this binary also run on PowerPC, MacOSX Tiger.

Saturday, March 10, 2007

Update on qtpfsgui

In addition to the fink-packages mentioned in my prefious post on the qtpfsgui DMG image I have created, you also need to install the package libexiv2-0.12-shlibs from fink, since I link qtpfsgui dynamically against this lib. If you get exiv2 from some other source, make sure that you enable shared libs.

My First DMG Image

After playing with MacOSX for quite some time now, I finally created my first dmg image today. I am working on creating a universal binary of qtpfsgui, a program for creating HDR images. I have not manage to create the universal binary yet, but I have at least compiled a version that can be used on intel macs.

I will guess more fancy tools for creating dmg's exist these days, but I found a step-by-step walkthrough on the net which did the trick for me. For future reference for myself, and for others stopping by, I
provide the steps here. Most of this is taking place in a terminal window:
# create a dmg image of some suitable size
1>hdiutil create -megabytes 10 qtpfsgui.dmg -layout NONE

# mount, but don't mount!
2>hdid -nomount qtpfsgui.dmg
# record det /dev/disk returned from that command

# create filesystem
3>sudo newfs_hfs -v QTPfsGUI /dev/disk1 #insert correct device

# eject the unmounted image, and re-mount for real
4>hdiutil eject /dev/disk1
5>hdid qtpfsgui.dmg

# Now, use e.g. finder to put some files into the image, and eject it when ok
# then convert to a readonly compressed image (suitable for 10.1+)
6>hdiutil convert -format UDZO qtpfsgui.dmg -o qtpfsgui.1.8.1.dmg

# mount to check that everything is ok
7>hdid qtpfsgui.1.8.1.dmg
That's all it takes to create the image. If you want to test the program for your self, you are free to grab the image. Beware that before you can use the application you have to install some prerequisites: QT4, libexiv2, libfftw3 and libjpeg. QT4 can you get from Trolltech, the creators of QT4, while the easiest way to get the rest is probably from the fink project. Install the fink packages exiv2, fftw3, and libjpeg. After that you should be abel to use qtpfsgui on your intel mac. If not, bug me!

Remark: I am not in any way resonsible for the qtpfsgui program itself, I am just trying to package it up for the Mac. The program itself is the creation of Giuseppe Rota.

Friday, March 09, 2007

Bye bye, Valla

I følge aftenposten har Valla trukket seg som LO leder. Det er en trist dag for norsk presse og kringkasting, for Hallo i uken og Nytt på nytt, og mange, mange andre som kommer til å savne den mest mandige LO lederen vi har hatt på lang, lang tid.

Alle vi andre? Tja, vi bryr oss kanskje ikke så mye. Ihvertfall vi som ikke er medlemmer. Men alle ledere der ut: Behandle dine medarbeidere rettferdig og riktig. Ikke vals over dem. De må merke at du bryr deg om dem og deres meninger. Så kan du til slutt være sjef og bestemme. Og aner jeg hva Yssen/Valla saken egentlig handler om? Nei, jeg har ikke fulgt med så mye...

Wednesday, March 07, 2007

Update on the vim-blogger plugin

Today I wanted to install the vim-blogger plugin I mentioned in an earlier post, on another computer. I couldn't remember exactly where I found it, so I just went to google and searched. And figured out it was hard to find - first this very page was the only relevant thing I managed to dig up.

After a while I found what I was looking for, and figured out that proper attribution should have been given the first time I mentioned the plugin. It is "the geek wannabe" over at http://djcraven.blogspot.com who has created the plugin. The plugin can be downloaded here, and djcraven provide some documentation in this post in his blog

Thansk, geek wannabe for the great tool!

Take care

Monday, March 05, 2007

A new place on earth

There is a new fully buzzword compliant place for bloggers available, tumblr. The idea seems to be that it should be really easy to blog, even if you have very little to blog about. Of course, I have to test it out! You can check out my entry into that thing. My review goes like this:

1. Signing up at tumblr is very easy. Go to tumblr.com, hit Sign Up, type in email and a password, and pick a url (the part in front of tumblr.com), and you're halfway there. Wait for a confirmation email, confirm, and you're in.

2. If you're like my, you want to configure template and stuff right away. Up in the right corner you have a link saying "Change settings" once you are logged in.Hit it, and a nice interactive web2.0ish page is loaded, where you can pick a template, and adjust colors, and see a more or less live preview as you test away. On the settings-page you can also adjust what the url of you blog should be. You may even choose a custom domain name which probably mean you can have tumblr on your own domain. I haven't tested that out yet. Finish by saving changes. This should take you back to the front page. If you don't like the templates, you can go custom as well, which brings up the template for you to edit in a simple textarea. You can update the preview by pressing a button. Beware, you should now change colors inside the textare, not using the color-edit-section. You figure out why if you try!

3. Start creating posts. There are shortcuts for regular posts, photos, quotes, links, conversations and videos on your tumblr dashboard. You can also grab a button for your bookmarks bar for quick access to creating link-posts. I have only tested the regular post and the link thing so far, but those seems to work ok.

4. Will I use this? I don't know yet, we will see in the future!

Sunday, March 04, 2007

Vi elsker ministere med gode matteegenskaper!

Festministeren, eller idrettsminister som han kalles for anledningen, Trond Giske uttaler i Aftenposten følgende etter Petter Northugs rykk i ski-vm:
Det som skjedde var helt mirakuløst, Petter fikk jo 80 meters forsprang på 50 meter. Det er ikke så verst å være trønder på en slik dag.

Mirakuløst er nok helt riktig ord - Selv den godeste Einstein ville ha problemer med å forklaret et rykk på 80 meter i løpet av en distanse på 50 meter, gitt at konkurrentene ikke beveget seg bakover. Gratulerer Giske.

Og gratulerer til de norske gutta i VM selvsagt. Jeg aner ikke noe om deres ferdigheter i matematikk, men gå på ski kan de ihvertfall. Og det er alt vi forventer fra den kanten.

Thursday, March 01, 2007

Ikke min oppgave, men noe må da lagres...

For de som ikke aner hva nam er, og heller ikke kjører mc, les videre eller gå et annet sted. Av og til faller noen utsagn i baren som bare bør tas vare på. Jeg er vel kjent med at dette er en oppgave som egentlig tilligger andre, og jeg er stort sett bare en lurker i baren. Men allikevel, følgende utsagn må jeg bare lagre. Noen (Herr Bang) spør i en tråd (sitat):


Hvor ble de av alle sammen, alle de gamle heltene?

Gikk de hjem?

Hvorpå "mac" svarer følgende bevingede ord:


Det hviskes fortsatt om heltedåder og bragder, om DoD'eres overdådige treff i De Dype Skoger, om DAMN og 900 cc bæplukkere og ovloV, om buddhister fra Flatlands, fartsmonstre fra Finland og besøkende brødre fra Sveariket med uendelige powernaps etter tusener av mil forkledt som arkeolog på italiensk stål. Det ryktes om en velformet hekk innpakket i italiensk skinn som nesten forårsaket en ulykke, en figur med raket skalle, bukkeskjegg og balluminium, en annen med seilersko som motorsykkelstøvler. Det mumles om brorskap, dårskap, barskap og farskap. Om telt og hotellrom, om Baren(tm), om Bjørnepalasset, om Grava, om EBS(tm) og EBB(tm). Om MacAllan og Aass. Om slosskamper med laservåpen, Jägermeister og gocarts. Om vinterlagring av Ducatier i blokkleiligheter, om scottoilere og katter.

Noen gikk sin vei, noen ble, og noen gikk og kom tilbake igjen. Og nye kom til - alle på to hjul, på evig jakt etter neste sving, neste bakketopp, neste vannhull. På nye sykler og på gamle sykler. I bunnløs vinterdepresjon og på jakt etter våren.

Sånn kan de sies. Snart kommer våren, og vi kan atter plukke frem redskapen folkens. Jeg føler snøen smelter allerede.