In case anyone finds this useful, I made a small sed-like program in Python. I call it pysed.
The rationale for this tiny program is that I often want to make regexp substitutions but find the classic regular expressions syntax of sed (and emacs) outdated and not as powerful as Python's. For example, suppose you want replace ".m_" with "." except when preceded by "m_state". You do:
pysed -i -e '(?<!m_state)\.m_' -s '.' file.cc
With traditional sed, or with gnu emacs, it does not look like this is possible, as far as I can tell...
2007-07-25
2007-05-31
python bindings generator
For the ns-3 project, I've been trying for some time to create some Python bindings. I've been using Py++, which uses gccxml to parse C++ header files and automatically generates Boost.Python code that tries to wrap it.
Py++ is really nice. Unfortunately Boost.Python isn't nearly at the same level. Boost.Python is heavily built on C++ templates. Mastering C++ templates is Hard™. Everything Boost does is practically black magic to me. While using Py++, Boost.Python has been fighting with me every step of the way, and winning too!
I decided to move away from Boost once and for all. Some of the non-boost alternatives I could find were:
bzr (0.15) branch: http://telecom.inescporto.pt/~gjc/pybindgen/bzr
Releases: http://telecom.inescporto.pt/~gjc/pybindgen/releases
Launchpad (bug reporting, etc.): https://launchpad.net/pybindgen/
The project uses WAF to build; Running "./waf" should be enough to build the example. "./waf check" should be able to run the unit tests.
Py++ is really nice. Unfortunately Boost.Python isn't nearly at the same level. Boost.Python is heavily built on C++ templates. Mastering C++ templates is Hard™. Everything Boost does is practically black magic to me. While using Py++, Boost.Python has been fighting with me every step of the way, and winning too!
I decided to move away from Boost once and for all. Some of the non-boost alternatives I could find were:
- Python-SIP: the code generator itself is written in C++; that doesn't make any sense! I want something I can easily hack;
- SWIG: also made in C/C++, and in addition generates very ugly code, almost unreadable with so much macro abuse;
- The PyGtk code generator. I know this one very well :) Unfortunately it has some problems, the biggest of which is that it doesn't support C++ classes, while the ns-3 code I want to wrap is pure C++.
- Must be written in pure Python, and in good pylint-checked style;
- Must have unit tests;
- It should have a simple python API to generate the code, other frontends (such as header file scanning) optional and layered on top of the python API;
- Must be easily extensible to handle new types, with strong focus on correct memory management of type convertion code;
bzr (0.15) branch: http://telecom.inescporto.pt/~gjc/pybindgen/bzr
Releases: http://telecom.inescporto.pt/~gjc/pybindgen/releases
Launchpad (bug reporting, etc.): https://launchpad.net/pybindgen/
The project uses WAF to build; Running "./waf" should be enough to build the example. "./waf check" should be able to run the unit tests.
2007-03-21
Publication
Yesterday I received a notice:
/me is very happy.
I am glad to inform you that the revision of your paper, “QoS Abstraction Layer in 4G Access Networks”(TS2006-69) was approved for publication in Telecommunication Systems.
/me is very happy.
2007-01-04
OpenOffice.org still sucks, only a bit less
So it seems that OpenOffice.org 2.1, present in Ubuntu Feisty, finally has a native AMD64 executable, which should improve its memory requirements and make copy-paste less buggy. Unfortunately it seems you still are unable to insert cross-references to numbered items in enumerated lists, which is the technique of choice of MS Word users to insert bibliography references and lists. And of course creating a "Bibliography Database" is both non-trivial and very buggy. I tried it again but had to give up.
Thankfully I can still use LaTeX, which has much better quality anyway...
Thankfully I can still use LaTeX, which has much better quality anyway...
dijkstra in python
Given an arbitrary network, I knew that Dijkstra's algorithm computes the shortest path between any pair of nodes of the network. In a distributed routing protocol, Dijkstra is often used to compute shortest paths to destinations. I already knew, but wanted to confirm, that for any shortest path computed centrally from one edge node to another, you could apply the same Dijkstra algorithm to each intermediate node in the path and obtain the same result. So I put my Python coding skills to good use and created a small program that generates lots of random graphs with lots of nodes and lots of links with random "distances" and, for each such graph picks a couple of nodes and checks the assertion above. I only had to convert the Dijkstra algorithm expressed as pseudo-code in wikipedia to Python, which was pretty easy. The assertion is confirmed.
/me loves Python.
/me loves Python.
2007-01-01
2006-12-31
holiday season sickness
No, I'm not sick of the holidays, just plain sick. I think it's bronchitis (but no, I don't smoke). Been like this for over a week, now. Meanwhile I entertain myself playing Neverwinter Nights 2, reading, and watching some tv series.
Subscribe to:
Posts (Atom)
