Redirect stderr into becoming dots in Bash

September 2, 2006
3 comments Linux

Here's a whacky idea; in a shell script I want to convert every line of stderr into a . on the same line. I'm still a shell scripting newbie but I know that bash can be quite powerful if you know what you're doing to it.

To begin with I've written a little wrapper on cvs commit called ~/bin/cvs_commit which does the following:


#!/bin/sh
cvs commit -m "$1" | grep -v '\.bak*' | grep -v '\.pyc'

Because cvs prints all folders it recursively traverses I if it's a big tree all of that ugly stuff is print to screen via stderr. To get rid of that, I've changed my command to:


#!/bin/sh
cvs commit -m "$1" 2>> /dev/null \
| grep -v '\.bak*' | grep -v '\.pyc'

Let's improve even more...

Truncated! Read the rest by clicking the link below.

Web 2.0 logo generator

August 20, 2006
1 comment Misc. links

Fuckr Hilarious pun where anybody can create a Web 2.0 logo that looks like pretty much any other web 2.0 company's logo.

If you don't know what the Web 2.0 hype is, perhaps you've heard of the "dot com" hype that happened a couple of years ago. Now they're doing it again but instead of "dot com" it's "web 2.0". more info here

Losers like me who haven't been bought up by Google or Yahoo! yet hate the "web 2.0" phenomena and considers it a bad thing. Am I just jealous maybe?

A "web 2.0" buzzword cloud can be seen here if you're wondering if your IT supplier is taking you for a ride.

Madonna's birthday party at the Lounge Lover

August 17, 2006
23 comments Photos

Madonna mugshot Yesterday it was Madonna's birthday. To celebrate her 48th birthday she put on a concert somewhere in London and after the concert throw a little party at the Lounge Lover. The Lounge Lover is a uptown cocktail bar tucked away on a little side street off club row where I live.

It was a lot of commotion. Staff of the bar swept the floor outside and put up barricades. Some paparazzis came already at half eight but the first celebrity didn't arrive until half nine. That was Gwyneth Paltrow

More and more celebrities came. One of the early arrivers was Kevin Spacy but he came in and walked past us so fast that I never had a chance to take a picture of him.

There were a lot of people that the paparazzis seemed to recognize that I didn't. In those cases I just took some wild pictures in hope that someone can explain who that was later. (for example, Lawrence Dalaglio who my flatmate had to explain to me who he was. Sorry Lawrence, I don't watch much television)

Last night was without a doubt an experience. I haven't seen that many nice Mercedes lined up since I was in Monaco a couple of years ago. Pet Shop Boys was the only people arriving in a limo and Jason Statham arrived in a regular black cab.

Now, let us see the pictures

Fastest way to uniqify a list in Python

August 14, 2006
92 comments Python

SEE UPDATE BELOW

--

Suppose you have a list in python that looks like this:


['a','b','a']
# or like this:
[1,2,2,2,3,4,5,6,6,6,6]

and you want to remove all duplicates so you get this result:


['a','b']
# or
[1,2,3,4,5,6]

How do you do that? ...the fastest way? I wrote a couple of alternative implementations and did a quick benchmark loop on the various implementations to find out which way was the fastest. (I haven't looked at memory usage). The slowest function was 78 times slower than the fastest function.

Truncated! Read the rest by clicking the link below.

Unicode strings to ASCII ...nicely

August 8, 2006
20 comments Python

This has been a problem for a long time for me. Whenever someone enters a title in my CMS the id of the document is derived from the title. Spaces are replaced with '- and &' is replaced with and etc. The final thing I wanted to do was to make sure the Id is ASCII encoded when it's saved. My original attempt looked like this:


>>> title = u"Klüft skräms inför på fédéral électoral große"
>>> print title.encode('ascii','ignore')
Klft skrms infr p fdral lectoral groe

But as you can see, a lot of the characters are gone. I'd much rather that a word like "Klüft" is converted to "Kluft" which will be more human readable and still correct. My second attempt was to write a big table of unicode to ascii replacements.

It looked something like this:


u'\xe4': u'a',
u'\xc4': u'A',
etc...

Truncated! Read the rest by clicking the link below.

More crappy album covers

August 6, 2006
0 comments Misc. links

Manowar Some people might think I have a fetish for bad album covers. I do.

Here's another site which seems to be quite focused on metal records and other 80's glam rock stuff. I actually have MP3s with some of those bands, namely Manowar, Pantera and Yngwie Malmsteen.

Check them out here

Sorting transform function in PostgreSQL

August 3, 2006
5 comments Work

A database table that I've had to work with has a something called identifiers which are humanreable names of questions. There's a HTML template where the question designer can place the various questions in a human-sorted order. All questions get identifiers in the form of <something><number> like this: Head1 or Soma3 or Reg10 where Head, Soma and Reg are sections. Changing the nameing convention from Head1 to Head01 is too late because all the templates already expect Head1 not Head01. Initially I sorted the identifiers like this:


SELECT id, identifier 
FROM questions
WHERE section=123
ORDER BY identifier 

The result you would get is:


Head1
Head10
Head2
Head3
...

The human readable sort order should have been this:


Head1
Head2
Head3
...
Head10

Truncated! Read the rest by clicking the link below.

Exploding Dell laptops

July 31, 2006
0 comments Misc. links

Dell laptop number 3 This just in on Engadget, Dell number 3 explodes That's right. Explodes! Yep, you heard right, third explosion.

That can't be good for business. But most importantly, security. Imagine if you're sitting with the laptop and it explodes in your face, whilst it also explodes in your lap when you're on an airplane!! The amazing thing is, Dell hasn't yet started recalling laptops. That means that somewhere sometime someone will be the unlucky owner of the fourth exploding Dell.

Here's number 1 and number 2

Truncated! Read the rest by clicking the link below.

slim in ruby

July 26, 2006
0 comments Linux

Just figured out how to call my slim web service via XML-RPC using Ruby. It's as easy as in Python.

Here's the code:


require "xmlrpc/client"
# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "www.peterbe.com", "/")
# Call the remote server and get our result
result = server.call("slim", "h1 { font-family: Arial;}","css")
puts result
result = server.call("slim", 
  "function add(var1, var2) { return var1 + var2; }","js")
puts result

And when you run this on the command line this is what you get:


$ ruby dummy.rb
h1{font-family:Arial}
function add(_0,_1){return _0 + _1;}