For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
A collection of coding snippets, tips, hints and random thoughts.
For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
Today I finally found out the difference between class and instance attributes in Python. In C++, this is done by putting the static modifier in front of the declaration. Consider the following code:
#!/usr/bin/env python
class B:
b = 2
class C:
a = B()
def __init__(self):
self.a.b = 1
c = C()
c.a.b = 3
b = C()
print c.a.b, b.a.b
Here, a is a class attribute of class C. That is, there exists only one such attribute for all objects of kind C. So the output of the print statement will be “1 1”. This is the same as a static attribute in C++. But often I want an instance attribute. The correct way to do this would have been:
#!/usr/bin/env python
class B:
b = 2
class C:
def __init__(self):
self.a = B()
self.a.b = 1
c = C()
c.a.b = 3
b = C()
print c.a.b, b.a.b
Now the output is “3 1”, just as expected. I guess this all somehow makes sense in the Python world, but I tripped over this, and worst of all: Sometimes you don’t even notice. If the class attribute is a simple type, like int, the first solution would have worked. However, I have not yet understood why that is the case. One more Python semantic that eluded me so far.
Finally. My blogs now also support mobile devices with rendering suitable for small screens. All thanks to Blogger, who have introduced a beta version of the mobile templates via their beta program. You can force the template on every blog by appending “?m=1” to the blog URL. On your own blog, you can just enable it in your blog’s mobile settings via draft.blogger.com. Here’s how my blog looks in the mobile version:
I have to try this out some time: There is an Emacs mode for code completion using CLang. It is mentioned in a blog entry by some guy. The nice thing here would be, that it enables ObjC code completion, which is a good thing™. Especially if your are coding for OS X or iOS.
As volcore pointed out, there is a library called pycuda, which allows for CUDA programming in Python. It also comes with a nice ReductionKernel class, which allows one to rapidly develop custom MapReduce kernels.
Update: Even better, the same author has published a Discontinuous Galerkin solver, based on the same stuff. This can be used to solve partial differential equations, e.g. for fluid simulations, but also for EM simulations, using Maxwell’s equations.
I like to use MacPorts for installing certain libraries and programs. When running an update old versions are still kept on your disk. I never did care for those old versions, so you can simply let MacPorts remove them while updating:
$ sudo port -u upgrade outdated
This is taken from another blog post.
#!/bin/sh
# Use the name and email address of the author of the last commit.
USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
USER_NAME=$(git log -1 --format=format:%an HEAD)
. $(dirname $0)/post-receive-email
I then also changed the default post-receive-email script, to look like this in the send_mail() function:
send_mail()
{
if [ -n "$envelopesender" ]; then
/usr/sbin/sendmail -t -f "$envelopesender"
else
/usr/sbin/sendmail -t -F "$USER_NAME" -f "$USER_EMAIL"
fi
}
Well, MobileMe does not yet support the expiration of mails in folders. Especially for mailing lists, I want this feature. After let’s say 90 days the mails should be automatically deleted. I do not need to store mailing list contents for longer. So I took the nice tool imapfilter and wrote a config file that expires old mails from a selection of folders. I installed a cronjob on my web server that now automatically calls imapfilter every night. The config file (~/.imapfilter/config.lua) looks like this:
Myaccount = IMAP {
server = ‘mail.me.com’,
username = ‘your.name@me.com’,
password = ‘yourpassword’,
ssl = ‘tls1’
}
folders = {‘folder1’, ‘folder2’, ‘folder3’}
for k,folder in pairs(folders) do
foldername = ‘Mailinglists/’ .. folder
results = myaccount[foldername]:is_older(90)
myaccount[foldername]:delete_messages(results)
end
I am currently migrating my >4GiB of mail data from GMX to MobileMe. I have been using offlineimap regularly to backup my mail data. So first step was to update the backup. Now the next step is to run imapsync, which can migrate whole IMAP accounts. The full command I am using for this is:
imapsync –sep1 ‘/’ –prefix1 ” –ssl1 –ssl2 –authmech1 PLAIN –authmech2 PLAIN –host1 imap.gmx.net –user1 “yourname@gmx.de” –host2 mail.me.com –user2 “yourname@me.com”
I will report back once the sync has finished, this might take a while.
Update: Yup, it worked. My mail is now hosted on MobileMe. More disk space. What is missing at MobileMe is that it does not support automatically expiring mail folders. I.e. for mailing lists, I sort the mails into subfolders for each list. The lists are often high volume traffic, and not very important. So I’d like the mails to expire after, say, 30 days. With GMX this was not a problem, but MobileMe does not yet have such a feature. However, I found a nice tool called imapfilter. It allows you to do all kinds of stuff, besides other things it allows you to filter mails according to date and to delete them. This is what I will do. I’ll write another post, when I found out how to do that exactly.
When using ImageMagick to convert an RGBA picture (e.g. an OS X window with shadows) to an RGB JPEG file, you should use the following command:
$ convert input.png -flatten +matte output.jpg
If you don’t do that, you will end up with a picture like this:
The right conversion leads to this result instead: