Posted by
Tsukasa on November 29, 2008
Well the deadline has come and passed, and we have a clear winner. That winner is Katie. Her solution comes in at a tiny 121 characters, with the closest solution coming from Tim with 187 characters.
The main difference came down to the fact that Katie decided to avoid using the regular expression that was given in the sample, and just parse the lines with str.split.
So without much more talking, here is the winning solution.
import sys
s=sum(([l[0]]*int(l[-1])for l in map(str.split,sys.stdin)if l[-1]!='-'),[])
for x in set(s):print x,s.count(x)
It is also interesting to note how she uses the sum function to append a set of lists together.
Posted by
Tsukasa on November 23, 2008
I have written a few entries on python golf before, but I have now decided to make an official competition from it. The rules are fairly simple: I pose a problem simple problem which must be solved (in python) in the lowest number of characters (where a new line counts as one byte). Solutions may be written for any 2.x version of python (ie, 2.3, 2.4, 2.5 or 2.6), and may use any library found on default install on a Debian machine.
Solutions must be emailed to me. In the case where two people have the same character count, the solution that arrived in my inbox first will be declared the winner (this is to stop people from playing with the date header in the email ^^). The winner will receive a chocolate bar or coffee — their choice.
The problem this week is one of parsing log files. You must parse a log file in the common log format that will be given on to your program on stdin. You must then print on stdout the amount of data that was sent to each ip address (and the ip address). A sample program has been provided:
import re, sys
def main():
clf_regexp = re.compile(r'''^(\S+)\s(\S+)\s(\S+)\s\[([^\]]*)\]\s"([^"]*)"\s(\d*)\s(\d*)$''')
mapping = {}
for line in sys.stdin:
m = clf_regexp.match(line)
if not m:
continue
ip, _, _, _, _, _, size = m.groups()
size = int(size)
if ip not in mapping:
mapping[ip] = 0
mapping[ip] += size
for ip in mapping:
print '%s %d' % (ip, mapping[ip])
if __name__ == "__main__":
main()
Solutions will be accepted until 11:59:59pm(EDT) on Friday 28th November 2008.
Posted by
Tsukasa on November 12, 2008
As most people know, I have moved away from using Apple’s Mail.app as my email client. I now use mutt to perform all of my mail duties… or, so I thought.
The other day I decided to use iCal to send an event invitation to a friend. When I clicked on the send button, I was greeted with a copy of Mail.app, not exactly I wanted. At this point I changed the default Mail application to mutt (via iTerm).
Now you would expect iCal to listen to this setting, but alas, the mail was still (automatically) sent with Mail.app.
After a lot of investigating, I discovered there is a apple script within the iCal app bundle. The script of interest is /Applications/iCal.app/Contents/Resources/Mail.applescript. After spending a few hours learning applescript, I came up with a solution. You will need to replace the file /Applications/iCal.app/Contents/Resources/Mail.applescript with the one available from my repositories.
Once you have replaced this file, you must then recompile the script: osacompile -o /Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt /Applications/iCal.app/Contents/Resources/Mail.applescript
Note: You will need to have at the mail script and modify it so that it points to the correct version of mutt on your system.
Posted by
Tsukasa on November 4, 2008
So James and I decided to take the plunge and install the intrepid update on a newly installed machine we had here (it had had xubuntu-hardy installed only a week earlier).
This machine was using the nvidia binary package, but other than that did not have anything that was from a restricted repo.
Upon the upgrade we found that the nvidia package no longer works. In fact, it no longer compiles the kernel module (even though it claims that the package is installed correctly). This left us without an X11 server. Even when trying to use the nv driver we could not get it to work.
On a side note: We found that the nv driver is now no-longer installed by default.
After about an hour of trying to get things to work, we decided that we will just have to live with the vesa driver. Although this makes the system slow, at least we can use X11.
Another thing I noticed, is that it now spams me with an annoying motd, I mean sure system stats on login is may be nice for some people, but I already have most of that coded in my scripts. The easiest way to get rid of this is to remove the package landscape-client with the following command:
sudo aptitude purge landscape-client