Jacobian highlighter

May 2, 2005
2 comments Python

My friend Jacob from Galdrion taught me about "positive lookbehind assertion" and "lookahead assertion" when writing regular expressions in Python. It was new to me and I can't believe why I didn't read up on this more earlier because they're really useful. I've now got a usage for these which I use to find words that written on their own. For example, in the string "peterbe" the word "peter" doesn't exist really. You only want to find your words when they're written alone. You can't rely on it being spaces always on both sides either. You might find brackets, fullstops, end-of-string, you name it.

Enough chatting about it, I have now put together a little something that does this properly which I for no real reason call:

the Jacobian highlighter

Please give it a spin to see if it behaves like you expect it too. If you find any problems, let me know and I'll fix it and add them to the unit tests.

Next on the todo list for this is Unicode support of course.

Better select boxes for issue tracker

April 29, 2005
5 comments Web development

If you look at the Add Issue form on the Demo issue tracker you should see the three select boxes (aka. drop downs) and if these become too long they tend to be difficult to use. Here's a potential solution that; I just need to know what you people thing about it's usability.

I use onfocus() and onblur() to change the size attribute of the select input element thus temporarily giving the user a bigger workspace. Please have a play on this demo page and return here after for feedback.

Truncated! Read the rest by clicking the link below.

The Geeks Revenge

April 29, 2005
0 comments Misc. links

This is yesterdays's Dilbert (28 April 2005) but I guess its genius had to sink with my slow brain. It's just so funny. Yesterdays Dilbert

Being a geek myself I unfortunately resemble myself in Alice here.

TAL here hack in Plone

April 28, 2005
1 comment Plone

Had to do a very useful and ugly but also smart hack in Plone today.

In the portal root I have a Document with Id index_html that the client is changing with the WYSIWYG editor. What I wanted to do was to change some METAL calls in the <head> tag of that one document. In fact, what I wanted to do was to cover up the left hand column which is done this way:


  <head>
       <metal:override fill-slot="column_one_slot" />
 </head>

The problem was that the index_html Document is a Document so I can't edit it's TAL. I could have customized document_view.pt but that would have applied for all Document objects in the site. Here's how I solved it:

Truncated! Read the rest by clicking the link below.

Gmail shortcuts

April 26, 2005
4 comments Linux

If you use Gmail but haven't started to use the keyboard shortcuts, then you're really missing out on something.

A peculiar thing is that when you enable it you get the extra > pointer along the side which makes it possible to navigate up and down. Anyway, when you're in the inbox you us k for going up (new emails) and j for going down (older emails). BUT when you click on a conversation (several emails all with the same subject line for people who aren't familiar with Gmail yet) there are other keys for going up and down. This time it's p for going up and n for going down. Why can't it be the same which would make it two keyboard commands less to remember?

Truncated! Read the rest by clicking the link below.

Grep results expanded

April 23, 2005
5 comments Python, Linux

I find myself often running a grep command with the -n which means that when it shows the filename it also shows the line number it matched it on. Then what I often do is that I open the found file with my editor and move to that line with the gotoline feature. Here's a cute little bin Python script that expands the result a little bit. Try:


$ grep -rin 'def set' *      
frintranet/sequence/tests/testSequence.py:26:    def setUp( self ):
slimmer/tests/testSlimmer.py:37:    def setUp(self):
slimmer/tests/testSlimmer.py~:37:    def setUp(self):
slimmer/tests/testSlimmer.py.bak:42:    def setUp(self):

Truncated! Read the rest by clicking the link below.

Serious flaw in Bose headphones

April 23, 2005
7 comments Music

Perhaps you saw my praise over my new Bose headphones with noise reduction a couple of days ago. Well, now I've discovered a serious flaw that I didn't realise before.

When you run out of batteries, like I have now, the headphones don't work at all. Granted that the noise reduction feature can't work without batteries but I should at least be able to listen to music in them don't you think?

It should work like this:


function listen2music():
    if hasBatteryPower():
       playMusic(enable_noise_reduction=true)
    else:
       playMusic(enable_noise_reduction=false)

pg_class to check if table exists

April 20, 2005
4 comments Linux

I just learnt a better way to check if a PostgreSQL table exists. Before I did this to find out if table mytable is defined:


SELECT * FROM 'mytable' LIMIT 1;

But this had to be wrapped in exception catching application code because I was able to tell if the table existed if the select statement worked. That's the wrong and naive way. The correct way is to use pg_class and look at how many rows were returned:


SELECT relname FROM pg_class 
WHERE relname = 'mytable';

Why have I missed this before? No explanation?

A disadvantage with using pg_class is that it's not ISO standard, meaning that it's specific to PostgreSQL only. The first pattern will work on all relational databases.

Google blogs about their Maps

April 19, 2005
0 comments Misc. links

This is possibly the best blog entry I've seen in many months. It's a summary of some really interesting Google Maps searches

The quality still isn't great but the potential sure is interesting. I for one love the airplane graveyard search

North america sure is interesting geographically because it's so varied but just imagine the potential when Google Maps reaches the whole world! (probably not North Korean) And on this page, make sure you have a look at the slideshow in the Wired article they link to.

"Can you help me about ZOPE?"

April 18, 2005
2 comments Zope

Not sure what people think of me but I get a lot of strange emails. Last week I got an email about a guy wanting me to teach him Kung fu via email correspondence. Today this arrived plus can see what my reply was:


Yeah, sure. Don't bother reading any documentation or books. Forget 
about installing it and playing with it because the only way you'll 
ever learn is by me explaining everything via email to you. Now, were 
do we start? Shall I maybe just take the rest of the day off and 
theorise about the kind of questions you might have?

On 4/18/05, [[name hidden]] <[[Email hidden]]@yahoo.com> wrote:<br />
> Could you help me about ZOPE. <br />
>  
> 
>  ________________________________
> Yahoo! Mail Mobile
>  Take Yahoo! Mail with you! Check email on your mobile phone. 
> 
> 

-- 
Peter Bengtsson, 
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com

Do you think I was too harsh on him/her? Or more interesting, do you think he/she understands my sarcasm?