31 Mar 2009, 19:40
Tags: , , , , , ,
2 comments

Hours of fun for my dog

Recipe:

  • One large Kong,
  • About 250g of diced chicken filet,
  • A freezer.

Combine the first two, put the result in the freezer for a night and Aagje has hours of fun!

Tags: , , , , , ,

26 Mar 2009, 14:48
Tags: , , , ,
9 comments

iTunes: DJ sucks

I hate the new iTunes DJ, which came with the 8.1. It keeps putting songs I just listened its list. And I mean that like, three times the same song, one after the other. Even an options that says “make sure the list in iTunes DJ never contains the same song twice” would be enough to fix it. The previous Party list option was far better at it.

And don’t tell me the chances are very small, I have a music library of 16.26GB (that’s more than 3200 songs), plenty of music to choose from. If it was truly random, it should haven’t every 5 songs or so.

Tags: , , , ,

25 Mar 2009, 22:46
Tags: , ,
Comments Off

Broken pieces

“I was never one to patiently pick up broken fragments and glue them together again and tell myself that the mended whole was as good as new. What is broken is broken — and I’d rather remember it as it was at its best than mend it and see the broken places as long as I lived.” — Margaret Mitchell

Tags: , ,

15 Mar 2009, 22:12
Tags: ,
Comments Off

Python: My .vimrc

This is especially for working with Python. I welcome additions or better practises!

set term=builtin_ansi
syntax on
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd BufRead *.py inoremap # X^H#
autocmd BufRead *.py set tabstop=4
autocmd BufRead *.py set shiftwidth=4
autocmd BufRead *.py set smarttab
autocmd BufRead *.py set expandtab
autocmd BufRead *.py set softtabstop=4
autocmd BufRead *.py set autoindent
autocmd BufRead *.py highlight BadWhitespace ctermbg=red guibg=red
autocmd BufRead *.py match BadWhitespace /^\t\+/
autocmd BufRead *.py match BadWhitespace /\s\+$/

(The ^H is typed by Ctrl+V Ctrl+H.)

Tags: ,

11 Mar 2009, 23:46
Tags: , , , ,
2 comments

Python: IMAP IDLE with imaplib2

Had a little fun today trying to get IMAP IDLE from Python working. It’s not in the default imaplib, but Piers Lauder’s imaplib2 has support for it. (I read on another blog that Piers Lauder is also the writer of imaplib, so that’s kinda nice.)

I don’t really program a lot anymore, so I had some trouble trying to understand how it’s supposed to work. Luckily, the blog post that I linked above, also had a link to the git sources of offlineimap, which uses it. Their imapserver.py has a nice implementation that I kind of copied.

As a proof of concept, and hopefully so others can use this too, I created the script below to see if I could get it to work. It doesn’t do a whole lot, just print a line when the mailbox gets a new mail. But you can build on it from there. I need these kind of examples to get stuff like this, so I hope it helps someone else! Leave me a comment if it does.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import imaplib2, time
from threading import *
 
# This is the threading object that does all the waiting on 
# the event
class Idler(object):
    def __init__(self, conn):
        self.thread = Thread(target=self.idle)
        self.M = conn
        self.event = Event()
 
    def start(self):
        self.thread.start()
 
    def stop(self):
        # This is a neat trick to make thread end. Took me a 
        # while to figure that one out!
        self.event.set()
 
    def join(self):
        self.thread.join()
 
    def idle(self):
        # Starting an unending loop here
        while True:
            # This is part of the trick to make the loop stop 
            # when the stop() command is given
            if self.event.isSet():
                return
            self.needsync = False
            # A callback method that gets called when a new 
            # email arrives. Very basic, but that's good.
            def callback(args):
                if not self.event.isSet():
                    self.needsync = True
                    self.event.set()
            # Do the actual idle call. This returns immediately, 
            # since it's asynchronous.
            self.M.idle(callback=callback)
            # This waits until the event is set. The event is 
            # set by the callback, when the server 'answers' 
            # the idle call and the callback function gets 
            # called.
            self.event.wait()
            # Because the function sets the needsync variable,
            # this helps escape the loop without doing 
            # anything if the stop() is called. Kinda neat 
            # solution.
            if self.needsync:
                self.event.clear()
                self.dosync()
 
    # The method that gets called when a new email arrives. 
    # Replace it with something better.
    def dosync(self):
        print "Got an event!"
 
# Had to do this stuff in a try-finally, since some testing 
# went a little wrong.....
try:
    # Set the following two lines to your creds and server
    M = imaplib2.IMAP4_SSL("mail.example.com")
    M.login("mylogin","mypassword")
    # We need to get out of the AUTH state, so we just select 
    # the INBOX.
    M.select("INBOX")
    # Start the Idler thread
    idler = Idler(M)
    idler.start()
    # Because this is just an example, exit after 1 minute.
    time.sleep(1*60)
finally:
    # Clean up.
    idler.stop()
    idler.join()
    M.close()
    # This is important!
    M.logout()

Tags: , , , ,

11 Mar 2009, 12:26
Tags: , , ,
1 comment

I love the music of this game

Too large to fit into my design, so just linking to it.

Music Catch 2

Tags: , , ,

1 Mar 2009, 20:43
Tags: , , ,
Comments Off

Dungeons & Dragons: Return of the Weekend (after)

You might remember that I wrote about my D&D weekend before. Well, my friends left a few hours ago. I’m just about doing the dishes and some final cleaning.

Best. Weekend. Ever.

I had so much fun, seeing my old friends again and playing a game that I forgot I liked so much. It was great, people arrived Friday around 19:00 and we all ordered pizza. Most of them needed to fine-tune their character a little (Joke even had to create her character!), so it took several hours before we were ready to start.

But once we were ready, we played until 3:00. And the next day we started around 13:00 and played till about 1:00 (I was so tired that I needed to stop). Joke and Remko cooked for us and Wilko, Steef and I did the dishes.

The game was awesome. My preparation sucked (I’m the Dungeon Master), but the players amply made up for it. They were great, still the same different characters as years ago. Even though the game is great, the social interaction with these friends is just awesome. Everyone is different, but we can get along so friggin’ great.

Thanks people, for coming over and having a great weekend. I miss you already.

Hopefully, we get to do this again next year, maybe a little longer than one weekend.

Tags: , , ,

 
  • Search


  • Twitter

    Powered by Twitter Tools

  • Calender

    March 2009
    M T W T F S S
    « Feb   Apr »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031  
  • Archives