Search Results: "ag"

1 December 2005

David Pashley: Return of Accessors vs. public member variables

Steinar, Imagine a Word class:
class WordA  
   public:
      char * word;
 ;
class WordB  
   private:
      char * word;
   public:
      void setWord(char * w)   word = w;  
      char * getWord()   return word;  
 ;
WordA worda; 
worda.word = "WordA";
WordB wordb;
wordb.setWord("WordB");
printf("%s %s", worda.word, wordb.getWord());
Fine, this works well. Now imagine that you want to change word from a char * to a std::string to stop you dealing with pointers. For the WordBclass you only need to change the getWord function. You don't need to change any of your class's users. For the WordA class, you have a problem because you can't automatically convert from a std::string to a char *, so all your users have to change from object.word to object.word.c_str().
class WordA  
   public:
      std::string word;
 ;
class WordB  
   private:
      std::string word;
   public:
      void setWord(char * w)   word = w;  
      char * getWord()   return word.c_str();  
 ;
WordA worda; 
worda.word = "WordA";
WordB wordb;
wordb.setWord("WordB");
printf("%s %s", worda.word.c_str(), wordb.getWord());
This is the punishment you get for exposing the internal details of your class to your users. Please ignore any specific mistakes in my examples; the principles work the same with different types.

Clint Adams: Comunicaci n

Yo te hablo de poes a
y vos me pregunt s
a qu  hora comemos.
Lo peor es que
yo tambi n tengo hambre.
The following is dedicated to Og Maciel, whose life apparently would be empty and meaningless without it.
There was a couple
Not an underwater couple that controlled the sea
But a couple of people on land
Who courted one another with the magic of haiku
They sent haiku across the country
Every day
Until the philotes
Brought them together physically
Then the Great State of California
Pronounced them legally wed
Because it either didn't know
Or didn't care
That poetry is supposed to rhyme.

Clint Adams: That lego puzzle is exhausting

[lego dreams]

Clint Adams: Minogue

I disagree that the best thing Kylie Minogue has ever done is the video for her cover of The Locomotion, obviously . I think it's something more like singing with Nick Cave or showing up on The Vicar of Dibley .

Matthew Palmer: A trace mixin for Python

Although I am by means an expert Python programmer, I do dabble -- at the moment, I'm dabbling fairly heavily in a project for work. I had need, as you do on occasion, for a call trace (I called this method, it returned X, I then called this other method, it returned Y, and so on). Astoundingly, I got no answer when I asked on #python, as I would have expected this sort of thing to be a gimme -- even possibly including it as a core language feature. But nary an answer was forthcoming. Searches for mixins or magic function calls which might solve my problem were similarly fruitless. I resigned myself to manually sticking print wrappers around the function calls of interest, but that got old real fast (especially after I spent about a half-hour chasing my tail because I'd forgotten to return the return value after I printed it). As usual, my subconscious saved the day. On the train home this afternoon, I suddenly had a brainwave, and the code which I've reproduced below appeared almost fully-formed at my fingertips. It's times like this that I really enjoy programming. Now, of course, someone will pop up and say "oh here it is over here", or "you just set the __trace_me_baby__ attribute on your object", but I can console myself with the fact that I know a lot more about grubby Python internals than I did before. The code: (a pre-saved version is also available).
# tracemixin.py
#
# A python mixin to trace the calling of methods.
#
# Copyright (C) 2005 Matthew Palmer 
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#   or see http://www.gnu.org/licenses/gpl.html
#   
"""
A mixin class to permit the tracing of method calls on an object.
This class, when mixed in, overrides the default operation of method calls
so that requests to call methods which have been listed in the
self._traced_methods list will be printed with their arguments and return
values.  Also included is a simple call depth indication, using indents.
Tracing of particular methods can be turned on and off on a per-object basis
by simply including or removing the method's name in the _traced_methods
list on the particular object.  Whole classes can be traced by setting
the list as a class attribute.
To include this class, simply make it the first class name in the list of
parent classes when defining a new class, like so:
class Something(TraceMixin, RealParentClass):
You could probably leave the TraceMixin in your production code, although
it'll slow execution down by a bit.
Complete usage example:
from tracemixin import TraceMixin
class RandomTask(TraceMixin):
	def x(self):
		print "X!"
	
	def y(self, arg):
		print "%s Y!" % arg
		self.x()
x = RandomTask()
x.x()
x._traced_methods = ['x', 'y']
x.y('why?')
Output:
X!
::y(why?)
why? Y!
  ::x()
X!
  =>None
=>None
"""
class TraceMixin(object):
	_traced_methods = []
	_depth = 0
	def __getattribute__(self, attr):
		if attr in object.__getattribute__(self, '_traced_methods'):
			self.method = attr
			attr = '_trace_proxy'
		return object.__getattribute__(self, attr)
	
	def _trace_proxy(self, *args):
		realmethod = object.__getattribute__(self, self.method)
		if realmethod and realmethod.__class__ == self._trace_proxy.__class__:
			print "%s::%s(%s)" % (self._depth*'  ', self.method, ', '.join(args))
			self._depth += 1
			rv = realmethod(*args)
			self._depth -= 1
			print "%s=>%s" % (self._depth*'  ', rv)
			return rv
		else:
			raise AttributeError

Clint Adams: Minogue

I disagree that the best thing Kylie Minogue has ever done is the video for her cover of The Locomotion, obviously . I think it's something more like singing with Nick Cave or showing up on The Vicar of Dibley .

Clint Adams: That lego puzzle is exhausting

[lego dreams]

Clint Adams: Comunicaci n

Yo te hablo de poes a
y vos me pregunt s
a qu  hora comemos.
Lo peor es que
yo tambi n tengo hambre.
The following is dedicated to Og Maciel, whose life apparently would be empty and meaningless without it.
There was a couple
Not an underwater couple that controlled the sea
But a couple of people on land
Who courted one another with the magic of haiku
They sent haiku across the country
Every day
Until the philotes
Brought them together physically
Then the Great State of California
Pronounced them legally wed
Because it either didn't know
Or didn't care
That poetry is supposed to rhyme.

Joey Hess: money

I've followed AJ's experiment in funding free software development with his AJ Market with interest and have thrown money in the pot once or twice for some of the projects I care about. It's an interesting approach. I'm too lazy to do anything like that, or rather, I'm already paid sufficiently to work on free software that doing a joeyh market would too much resemble work. However, I did decide to try something I've seen done occasionally, since I also wonder how that works out -- I added a paypal donations button to the website for one piece of free software. Just as a test, to see if it annoys anyone, and if anyone bothers clicking on it. I chose alien since it's well known, regularly used by a suprisingly large number of people and even appears on the first page of otherwise quite amusing results on a google search for "alien". (I suppose that adding google ads to the page would generate more money, but in a probably less interesting way.) Unlike AJ, I won't promise that clicking on the link will motivate me to work on anything. In fact, the most likely use of any money I get from this will be to pass the buck along to the AJ market or something similar.

Kenshi Muto: Speech at MOSS4

I was invited MOSS, Medical Free/Open Source Software Council, on last weekend. My speech was about the risk management of Debian. I believe we should more consider risks of FLOSS (at least as same as we choose proprietary commercial software) when we use FLOSS on business scene.

Dirk Eddelbuettel: Mail broken

Comcast, in their infinite wisdom, decided to RBL block (at least one of) Debian's mailhost(s), master.debian.org. As essentially all my mail is forwarded from Debian to Comcast, mail traffic was affected. At first, I noticed dropped posts from mailing list subscriptions relative to the list web archives. I posted the suggested noticed to the Comcast RBL admins, so far to no avail other than a to yield a more complete stop. The mail forwarding has been disabled for now, and I am dealing with this more manually. If you tried to contact me in the last few days and have not gotten a response, please resend your mail. I should now be in a position to receive it. Sorry for any inconveniences. Offers of better mail hosting would be gladly accepted, of course.

30 November 2005

Jonathan McDowell: OpenWRT on the Netgear DG834G

I spent too much time today reading MIPS disassembly of the ADAM2 bootload, as used on the Netgear DG834G. The problem is that the version used on the Netgear performs a checksum over most of the flash device on every boot. This makes the use of JFFS2, as done by OpenWRT, somewhat problematic. In an ideal world I'd try to compile up a newer, less restrictive version of ADAM2 but there's no JTAG on the Netgear that I've found and the thought of frying the bootloader and bricking the device wasn't appealing. So what I've ended up doing is finding where the checksum is done and changing the branch instruction that aborts the boot to a nop. It's still scary, but it appears to do the job. PLEASE NOTE THE BELOW COULD PERMANENTLY BREAK YOUR ROUTER First, obtain your ADAM2 image. This is 128K and is mtd2 from the bootloader view. It should have an md5sum of 0530bfdf00ec155f4182afd70da028c1. If it doesn't, stop. The version I'm talking about is 0.18.01 as distributed by Netgear. Assuming you have the right md5sum you want to go to offset 0x3944 where the 4 bytes should be 44 09 00 0C (representing a jal 0x90002510 during execution). Replace these 4 bytes with 0 (representing nop) and you should end up with a new image with an md5sum of d8a2f4623bf6f64b7427812f0e849aa7. You'll then need to do something like dd if=adam2-fix.bin of=/dev/mtdblock/2 on the device (I don't believe you'll be able to rewrite the bootloader from the bootloader for some reason...). After that ADAM2 will still checksum the flash, but will continue to boot it after printing a checksum error message. This means you can go off and build yourself an OpenWRT AR7 based image and install it on your Netgear. Rock.

Ari Pollak

< piman> Why don't we have a drama severity/tag?
< ari> piman: because we're not on livejournal
< ari> let's post all of -private to livejournal with backdates
< mjg59> We should move debian-devel to Livejournal
< piman> Let's move all Debian development to LJ.

Antti-Juhani Kaijanaho: I won

Antti-Juhani Kaijanaho has won National Novel Writing Month in 2005 with his novel THE MAIL SHIP I won. I completed 50,000 words in time. Of course, only about 13,000 words are directly usable if and when I end up editing the story, the rest will have to be removed – they were imposed by the strict timetable and the explicit leave to lower one’s standards. But, bottom line: I WON! Ps. Please don’t ask to see the manuscript. It’s not that good :) Pps. My mother won, too. Conga rats!

Filip Van Raemdonck: AMD64 Sarge packages

Trying to build the unofficial Sarge DVD images for AMD64 today, jigdo-lite could not find several packages on the regular mirrors. Next it tried to fallback to amd64-cdsnap.debian.net, which I believe is a mirror listed in the jigdo template, but still failed to find them over there. Browsing the port pages, I found out that the Sarge release for amd64 is hosted on amd64.debian.net rather than that -cdsnap location. It seems those jigdo templates need an update...

Enrico Zini: Fixed order of posts

The 'tags' plugin of pyblosxom was kindly forgetting about sorting entries. pyblosxom is the first real python code I've put my hands on. pyblosxom isn't too bad, but my impression after seeing its plugins is: "why do people choose python because of its elegance, then write really ugly code with it?" At least the blog is currently fixed. If someone wants the patch, ask me and I'll be glad to send it: I gave up contributing them back to authors that haven't replied after months. I'll try to survive with this until a new Debian Stable includes Rails and a Rails blog I can play with.

Mike Hommey: pbuilder and ccache

Isaac, there is actually a cleaner way to do the same as your hook. Just add the following to your .pbuilderrc file :
export CCACHE_DIR="/var/cache/pbuilder/ccache"
export PATH="/usr/lib/ccache:$ PATH "
EXTRAPACKAGES=ccache
BINDMOUNTS="$ CCACHE_DIR "
That will need bug #341453 to be fixed first, though, but if you set both BUILDUSERID and BUILDUSERNAME it will work out of the box (with the default configuration, PATH is not preserved because of the bug). Note that you can also set HOOKDIR instead of using the --hookdir command line argument, thus not needing your wrapper.

Erich Schubert: Pyroman V0.1 finished

I just finished rewriting an old firewall tool from Perl to Python. Since it's in Python and about firewalling I dubbed it Pyroman. I investigated a dozen of firewall-tools before, including shorewall and firehol. Each had it's stength and its weaknesses. After writing iptables rules in a shell script every now and then for a more complex project (with like 6 networks of which 3 are bridged together) and two dozen of differently configured hosts, NATs, VPN, everything. My predecessor had written a shell script to configure the firewall, but this was really bad to maintain. So I ended up writing a perl application to generate the rules from a modular configuration (read: usually one file per host, containing a perl hashmap) Well, after happily using this script for two years, I dedcided it's about time to rewrite it and document it extensively. I chose python for the rewrite. You can get the result here: Pyroman 0.1.1. The good: The bad: To tease you a little more into testing, here's an example host configuration: ("dmz" is an interface alias - where the web server is connected to -, as are "INT", "DMZ" and "ANY" for clients on these interfaces)
"""
A really simple webserver configuration.
These examples are just boring... ;-)
But without NAT they would be even more boring. ;-)
"""
# web server
add_host(
        name="web",
        ip="10.100.1.2",
        iface="dmz"
)
# offering, well, web service.
allow(
        client="ANY DMZ INT",
        server="web",
        service="www ssh ping"
)
# internal hosts may access FTP, too
allow(
        client="INT",
        server="web",
        service="ftp"
)
# setup NAT
add_nat(
        client="ANY INT",
        server="web",
        ip="12.34.56.80"
)
(Yes, this is a python script. No, you probably won't care to write your configuration in a programming language, will you?)

Jeff Bailey: Nope, nothing secret here.

From CBC News: Harper reopens same-sex marriage debate:
Some observers say the Tory stance against gay weddings cost the party crucial support in urban Ontario and among younger voters. But Harper may have raised the issue to pre-empt his critics, who say he's intolerant and has a secret agenda.

Martin 'Joey' Schulze: ffis e.V. still considered charitable

At the beginning of this month we have received the assignment from the local tax office stating that the ffis e.V. is exempted from several tax classes. Apparently we have managed the association in a proper way and are able to continue so in the future. This letter is also an implicit statement that the association may write tax-deductible donation receipts for the next five years which is very good news. In another letter the last modification to our charter of the association has been approved by the legal office. We are now able to plan the next plenum which should take place soon anyway. Our plan is to hold the meeting in December.

Next.

Previous.