photo
Jordan Sissel
geek

Thu, 13 Jul 2006

Grok to be rewritten in python

I spent a few hours tonight working on new features for grok and kept running into problems keeping track of data structures in my head. Grok currently makes heavy use of hash-of-hash-of-hash-of-ha...-type datastructures in perl. Remembering context is annoying and slows development.

I decided that grok could use some serious refactoring. So much refactoring, that I could probably get away with rewriting it faster than redesigning portions of it. Since I need to know Python better, and I am more familiar with OO in Python than I am in Perl, I figure I should rewrite grok in Python. Python already has one critical feature that I need in grok, named captures. The hack for this in perl is unwieldy and potentially unmaintainable if future perl versions change the format or deprecate it. It is listed in 'perldoc perlre' as experimental.

At any rate, I made a little prototype that tries to be very OO. My experience with Good(tm) object oriented programming is still limited. The CS curriculum at RIT sucked for teaching proper OO, too many professors taught wildly different styles or were unclear about what Good(tm) OOP should look like.

Therefore, rewriting grok is a good opportunity to explore test-driven development and maintainable object-orientation. Oh, and synergism too. *shifty eyes*

I've got a bit of code up and running already, and writing "for tests" seems to be a very cool way to think about programming. If I force myself to write easily-testable code, then writing tests is easy. Furthermore, initial experience seems to show that adding new features is much easier when all of the code is compartmentalized.

If nothing else, I wrote a somewhat cool debug method that accesses the call stack for function, class, module, etc. Check out the 'debuglib.py' file. The output looks something like this:

grok/groklib.py:52] RegexGenerator.saveRegex: happy message here
The file, line number, class and function name are all discovered magically in debug(). I like this.

If you get bored, you can look at the original stuff here: scripts/grok-py-test

Comments: 0 (view comments)
Tags: ,
Permalink: /geekery/grok-python-rewrite
posted at: 03:43

Wakeup call using /bin/sh and at(8)

Using at(8), I can schedule jobs to occur, say, when I need to wake up.
nightfall(~) % atq
Date                            Owner           Queue   Job#
Thu Jul 13 07:30:00 PDT 2006    jls             c       14
Thu Jul 13 08:00:00 PDT 2006    jls             c       15
Thu Jul 13 08:20:00 PDT 2006    jls             c       16
All of those jobs run my 'wakeup.sh' script which is somewhat primitive, but it does the job.

Using this script: scripts/wakeup.sh

Comments: 1 (view comments)
Tags: , , ,
Permalink: /productivity/wakeup-script
posted at: 01:44

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< July 2006 >
SuMoTuWeThFrSa
       1
2 3 4 5 6 7 8
9101112131415
16171819202122
23242526272829
3031     

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati