Tags

quit tryin' to be clever

4:16pm

I was trying to be clever, using the filename portion of the image URLs fed by Plus for the thumbnail images. Yeah, should know better. Now I'm just generating a filename from a UUID, ignoring what the Plus service provides.

So the images are showing up in the right column again. Huzzah!

The stars at night

2:49pm on Jan 11, 2012

I've been working on an Android program which uses 2D graphics over the past few days, and since it's always nice to have sample code to start from, I dug up my old Android starfield simulation.

I wrote this thing back in 2008, not that long after Android first came out, as an introduction to doing 2D graphics. I've written starfields before, first in C (and modeX) back in 1996, then in Flash's ActionScript around 2002.

I just compiled the Android version, and discovered that nothing has changed in the API since 2008 - a very good thing. I did speed up the animation a little and add more stars, since modern phones are a lot faster, and there were odd gaps in the animation.

You can find all of these versions, with source code, right over here.

Naturally, all source is copyright (c) me, and released under the Creative Commons by-nc-sa license.

Finally, a plus API.... well... almost

1:06pm on Oct 20, 2011

So now there's a Google Plus API for Python. You will notice I've added +1 buttons.

However, the sidebar on the right is gone for the moment, because there's a rather major bug in either the Plus API, or the image resizer Google use for the thumbnail images. So right now I can't actually pull thumbnails from Plus, I'd have to pull them down myself.

I'm pondering that, sure, but it seems the wrong way to do it.

Anyway, here's the bug I've submitted to the Plus bug tracker. I suspect that'll languish there for a year or so in the 'new' state, and by that time, I'll have stopped caring.

You know, like most of the Android bugs I've cared about.

cool

5:57pm on Oct 06, 2011

I finally quit being lazy and updated my first Android app, calCOOLator. It was semi-broken because it was using standard java.lang.Double numbers, now I'm using java.math.BigDecimal and dealing with precision much better.

Maintaining old applications, especially when it's been years since you even looked at the code, is a little annoying.

I'm sure I'll still get comments about how it doesn't handle percentages correctly. "50 + 10% = 55" - wtf kind of math is that?

everyone's an amateur

2:04pm on Aug 18, 2011

Yep, I'm doing it again. I'm trying to fix poorly-written libraries. This time it's the python bindings for net-snmp, the most popular SNMP library for unix.

Libraries should never, just print error messages when they can instead throw an exception. Throwing an exception means the application developer using your library has an opportunity to handle the error gracefully, rather than having the library just crash, or in this case, not being able to determine an error condition even exists.

Bad practice.

Here's a link to my bug report. Until they fix it, just edit netsnmp/client.py and replace the 'print stderr...' line with one that throws a useful exception.

Stock quotes, currency, and airports

11:59pm on May 25, 2011

For a recent project, I had need of simple Python libraries for currency conversion, stock quotes, and airport code lookup. In the past, I was using perl for this, so I used Finance::Currency::Convert::XE and Finance::Quote.

But since I'm using Python here, those aren't available to me. And unfortunately, I couldn't find anything on the web either.

And for the airport codes, I got a list and stuck it in a database. But then I have to maintain that... and that's annoying.

So.... here you are. airportcodes.py, googlequote.py and xecurrency.py.

Python RSS and Atom feed library

6:42pm on May 07, 2011

I'm now officially a contributor to feedformatter, a Python library to generate RSS and Atom feeds. I'll probably use it for this site soon.

Drag and Drop in PyQt

10:54am on Jan 14, 2011

So you want to be able to drag items out of a QListView? The docs suck on this. Here's how simple it actually is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class MyListView(QtGui.QListView):
  def __init__(self, parent=None):
    super(MyListView, self).__init__(parent)

    # enable dragging
    self.setDragEnabled(True)

    # I'm only interested in drag, not drop, so I disable drop
    self.setAcceptDrops(False)
    self.setDragDropMode(QtGui.QAbstractionItemView.DragOnly)

    # use this to allow selecting multiple entries
    self.setSelectionMode(QtGui.QAbstractionItemView.ExtendedSelection)

  def mouseMoveEvent(self, event):
    self.dragObject()

  def dragObject(self):
    if not self.selectedIndexes(): return

    drag = QtGui.QDrag(self)

    data = []
    for index in self.selectedIndexes():
        if not index.isValid(): continue

        # this assumes your model has a nodeFromIndex() method -
        # it's easy to set one up, you'll probably have a custom
        # model class anyways
        node = self.model().nodeFromIndex(index)
        data.append(str(node))

    # in this case I'm just making a newline-seperated list
    # of the data, you could do pretty much anything here
    md = Qt.QMimeData()
    md.setData('text/plain', "\n".join(data))

    # this is important.  Without this, it won't do anything.
    # you can use different actions like Qt.MoveAction, which
    # would remove the item from your model, but then your model
    # has to be more complicated.  I'm only interested in copy here.
    drag.setMimeData(md)
    dropAction = drag.exec_(Qt.Qt.CopyAction)

Yup, that's it. There's lots of conflicting docs, some tell you to do complicated things with mousePressEvent(), others are older than modern Qt, others just plain wrong.

Google Buzz

3:48pm on Nov 04, 2010

You may have noticed the word 'buzz' at the top of the right column on my site here. Yes, that does link to my Google Buzz account. Most things I post there, will also show up on this page.

This is actually quite easy to do.

The first thing you need is Google'z Buzz client library. I'm using Python, so I use this one here. The docs explain pretty well how to use it, but the basic code looks like this:

1
2
3
4
buzz_client = buzz.Client()
buzz_client.oauth_scopes=[buzz.FULL_ACCESS_SCOPE]
buzz_client.use_anonymous_oauth_consumer(oauth_display_name=g.buzz_name)
buzz_client.build_oauth_access_token(YOUR_API_KEY, YOUR_API_SECRET)

That will get you an active buzz client. Here's how I fetch a list of my own posts:

1
2
3
4
5
6
try:
  for post in buzz_client.posts(type_id='@self', user_id='@me', max_results=10).data:
      # do something with your posts here

except buzz.RetrieveError, e:
  # handle errors

The things I'm most interested in are the photos I post to my Picasa dropbox (usually taken from my phone while out in pubs and such). Photos are found in p.attachments, you'll have to check for one with the attribute 'type' equal to 'photo' (videos are unsuprisingly, 'video'). Then you have attachment.preview and attachment.link - these are what show up on my page here.

Also interesting is attachment.type 'article'.

Tags