Saturday, October 30, 2004

XML-RPC - Multiple calls over same connection

This post is about this link

Login once and then succesive calls must assume those credentials.
The following is nice but "login profiled behaviour" is still a question, (or not? can we configure SSH env. such that it will proxy to different rpc servers based on auth. profile? and if yes, isn't multiple rpc servers a complication?)

The default implementation uses HTTP as a transport, but that is
not a requirement. You just have to be able to serialise the request
and response parameters into an XML stream. The xmlrplic loads and
dumps functions will do that for you.

In one of my projects I actually use XML-RPC over SSH and deal with
the authentication etc at the SSH level. (I use the excellent pure
Python paramiko library for the SSH protocol part).



Sunday, October 24, 2004

A draft ?

This post is about this link

How to not enjoy a draft if Bush is re-elected.
www.enjoythedraft.com

Is there some how to enjoy taxes a la Europe more then rumor web presence?. Don't balance taxes at end of year, pay taxes included in the prices of things.
How would this be implemented? What would there be in this for small businesses, and what for big wolfs?

Thursday, October 21, 2004

Links to remember

http://www.williamgibsonbooks.com/
read something from there (SF ?)
awarded + "Neuromancer" I heard but never went anywhere with it yet

http://compsoc.dur.ac.uk/whitespace/
how to code some language keywords as white space
=> bored people build boring stuff

http://www.worldwidewords.org/
good ???? for an english illiterate like myself

Metaclass to autoupdate existing instances of a class to newly modified and reloaded classes

This post is about this link


Pretty simple yet so powerfull:
ideas:
-name the class __metaclass__ so all we need is import
-keep track of the instances in a new key (A) of the class attributes dictionary
(use instance __init__ to add the new instances to A in the class)
-at module reload, check sys.modules for the old class and copy A from old class
to new class dictionary
-for each instance (a) in A replace a.__class__ from old class to new class


#----- autoupdate.py
'''metaclass for auto-update classes'''
class __metaclass__(type):
# automatically keeps tracks of instances
def __new__(cls, class_name, bases, class_dict):
import inspect
module_name = class_dict['__module__']
#we will update bellow the class_dict with a new key:
#instance_dict_name and value a list of instances

instance_dict_name = '_%s__instances' % class_name
# see if there is already an older class
import sys
old_instance_dict = None
if sys.modules.has_key(module_name):
module = sys.modules[module_name]
if hasattr(module, class_name):
old_instance_dict = getattr(getattr(module, class_name),
instance_dict_name)
# add instance list
import weakref
class_dict[instance_dict_name] = weakref.WeakValueDictionary()
# override the __init__
if class_dict.has_key('__init__'):
def new_init(self, *args, **kw):
instance_dict_name = '_%s__instances' % (
self.__class__.__name__)
getattr(self.__class__,
instance_dict_name)[id(self)] = self
self.__original_init__(*args, **kw)
class_dict['__original_init__'] = class_dict['__init__']
class_dict['__init__'] = new_init
else:
def new_init(self, *args, **kw):
instance_dict_name = '_%s__instances' % (
self.__class__.__name__)
getattr(self.__class__,
instance_dict_name)[id(self)] = self
class_dict['__init__'] = new_init
# build the class, with instance_dict
new_class = type.__new__(cls, class_name, bases, class_dict)
# copy over the instance dictionary, and update __class__
if old_instance_dict is not None:
for instance_id, instance in (
old_instance_dict.iteritems()):
getattr(new_class,
instance_dict_name)[instance_id] = instance
instance.__class__ = new_class
# return new class
return new_class

#----- Spam.py
from autoupdate import __metaclass__
class Egg:
'''Put here your class code'''
# def print(self):
# print 'Hello World!'

#----- from your Python console
import Spam
x = Spam.Egg()
# ... edit your Spam.py file and change code for Spam.Egg class,
# e.g.: add a print() method to Spam.Egg by uncommenting
# the corresponding lines. Save the file.
reload(Spam)
x.print() # prints 'Hello World!'

Wednesday, October 20, 2004

color SynthAxis

This post is about this link

The "bester" coloring tool: color SynthAxis.
It actualy allows anti-designers pretend to be "ok" designers as far as "color schemes" go.

Test Driven Development

One aspect I cannot understand in TDD is how someone can assume that code is good if it's tested.Code that tests something is still code isn't it?
How do you know if you tested for everything that may go wrong?
If you can get the test correct then you can also get the main code correct.

The only help I see from TDD is that it may allow to see how fixing something here breaks something there. But that means the code is coupled and then how do you test for all this coupling?

-Your code should not be coupled.
-But how do I write GUI code that is uncoupled?
-Don't couple beforehand, instead use runtime registration of event handling.
-How is that uncoupling? How do you test for this chain of events and how do you know how are they going to happen?
-Test everything behind the GUI and leave GUI tests for later.
-What's the point?
-You should not write GUI code and start do some tests.
-Ha?

Python Interfaces

Ned Batchelder had problems mimicking Java's interfaces in Python and then he also had problems departing from that too.

The problem is that the implementer actually implements all the methods in the interfaces (via inheritance) regardless of whether it overwrites the behavior or not.

If there were real interfaces in Python's language, then this would not be a problem since it would only be implemented if it actually implements it.

He also explains how one does this in Java, which IMO is because Java forces you to implement all the methods in the implementer, so you must start creating hierarchies of interfaces to allow the implementer implement only one method, namely the child interfaces's method.

In python, thanks to the fact that everything is an object and dynamic nature of things you can declare that something does something other ways:
methodName.notYetImplemented = True even if there is code in the body of the method and then rely on this attribute of the method's object rather then on the fact that there is code in the body of the method or not like in Java.


def makeAbstract(f):
f.abstract=True
return f

class NotImplemented(Exception): pass

class Executable:
@makeAbstract
def oneWay(self):
raise NotImplemented
@makeAbstract
def secondWay(self):
raise NotImplemented
or for py2.3
oneWay = makeAbstract(oneWay)
secondWay = makeAbstract(secondWay)

class Statement(Executable):
def oneWay(self):
print "one way executed"

s = Statement()

if not hasattr(getattr(s, 'oneWay'), "abstract"):
s.oneWay()
else:
s.secondWay()

Of course someone can argue how much more readeble an interface inheritace dispach mechanism is vs a switch dispache mechanism such like the one above, and I agree that often that is true, however there are many instances when "simple is simpler and therefore better". However this discution dosen't interests me and I let the purists take onto that.
Now if you would like to let the dispach mechanism be taken care of by someone else, not you, then better use something like "runtime object providing a protocol"PyProtocols wich is now also arguable as clean or cleaner then a "compile time object following interface specifications" such as Java's.

Tuesday, October 19, 2004

Are we becoming robots?

We can't really see what technology does because:
an exponential curve approximates a straight line when viewed for a brief duration (Ray Kurzweil)
So predictions are always in linear way (see below) because they are ideas applied to ideas.

The problem with "non-technological" fields of knowledge is that there is no reliable apparatus to effectively remembering and so to being able to quickly applying knowledge, rather a cycle of re-inventions and epiphanies (lousy memory triggers) represent the engine of evolution.

So really what technology does, it allows us to remember?.

Technology way, the exponential way (the anti-struggling way?)
Ideas build concrete objects. A
A and ideas build concrete objects. B
B and ideas build concrete objects. C
...

Gnoseology way, the linear way (the struggling way?)
Ideas build ideas. A
A builds ideas. A
A builds ideas. A
...

The equation to spin around Bill Joy:
linear + exponential = exponential
gnoseology + technology = technology
epistemology = gnoseology + technology
ontology = epistemology
ontology = technology

versus the old way
epistemology = gnoseology
ontology = epistemology

Thank you syllogism for being a friend again and probably still let me be with the ontology maped the old way.

OS religion

Install XP in 5 hours or less
Install X-Chat in 5 hours or more

Sometimes you may find yourself taken over by the flow of things, when your brain is more in a "sensory like" state.
=> You may find this funny

Sometimes you may find yourself taken over by the critical you, when your brain is more in a "why, when, how" state.
=> You may find this sad

Again IMO is always about "my world" rather the "the world".

Subjectivism

Via Ian Bicking

I realized I dislike Kerry because he isn't who I want him to be. But that's unfair -- he is who he is. He was selected for who he was.



IMO this is most often what the problem is:

The world does not exist, what exists is "my world" where the world is in the ways I got where I am know, with my frustrations, my happy moments, my knowledge and from there the inferred inevitable subjective opinions etc.


I strongly believe that even mathematics to a prety large degree is subjective, then what to talk about the less a priori wings of the world.



html image inlining

I didn't know about this
Nice

I've been inlining in emails, but for web I was always using a separate script to
give out images for which links should not be known like:
<img src="getImage?id=bla">
<img src="getImage?id=bla2">
where getImage only works if a user is signed in or something.
Now I can turn more round trips into one if images are not big using something like

<img
src="data:image/gif;base64,
R0lGODlhAwEgAPcAAP///87OzqWlpYSEhHNzc2tra1paWiEYGQv+E
AP/OGP/OAM7Oxr29xjEA/2MA/5wA/+8A/+dK79573ta8AGAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAIpHuDBABsMANrb8JqF0gFxG+XAAHeqe2S+
Rh//hEFwEiA8ENJPN8K6NawcWA50CCLMnw7kUa/p
Rdrpco7uOexAMKBLYPpNlxAZ6DAnJlm7WlavA4FANR0Kg9CEAC
BAQAOw==
" >