Distributed Systems & Transaction Processing books

Reliable Distributed Systems: Technologies, Web Services, and Applications (Hardcover)
# Hardcover: 668 pages
# Publisher: Springer; 1 edition (March 25, 2005)
# Language: English
# ISBN-10: 0387215093
# ISBN-13: 978-0387215099
# Product Dimensions: 9.3 x 7.2 x 1.5 inches

Transaction Processing: Concepts and Techniques (The Morgan Kaufmann Series in Data Management Systems) (Hardcover)
# Hardcover: 1070 pages
# Publisher: Morgan Kaufmann; 1st edition (September 15, 1992)
# Language: English
# ISBN-10: 1558601902
# ISBN-13: 978-1558601901
# Product Dimensions: 9.4 x 7.6 x 2 inches

Distributed Algorithms (The Morgan Kaufmann Series in Data Management Systems) (Hardcover)
# Hardcover: 904 pages
# Publisher: Morgan Kaufmann; 1st edition (March 15, 1996)
# Language: English
# ISBN-10: 1558603484
# ISBN-13: 978-1558603486
# Product Dimensions: 9.3 x 7.6 x 1.7 inches


http post using curl

curl -i -k https://my.host.com/a/b/c -d @c:/temp/1.xml 

wordnet 2.1 lexnames missing

download PyWordNet

>>> from wordnet import *

Traceback (most recent call last):
  File "<pyshell #8>", line 1, in <module>
    from wordnet import *
  File "C:\tools\python\2.6.2\lib\site-packages\wordnet.py", line 767, in </module><module>
  File "C:\tools\python\2.6.2\lib\site-packages\wordnet.py", line 763, in setupLexnames
    for l in open(WNSEARCHDIR+'/lexnames').readlines():
IOError: [Errno 2] No such file or directory: 'C:\\tools\\wordnet\\2.1\\dict/lexnames'

download WordNet-2.0.tar.gz

C:\tools\python>gzip -d WordNet-2.0.tar.gz
C:\tools\python>mkdir x
C:\tools\python>cd x
C:\tools\python\x>mv ..\WordNet-2.0.tar .
C:\tools\python\x>tar xf WordNet-2.0.tar
C:\tools\python\x\WordNet-2.0\dict>cp lexnames C:\tools\wordnet\2.1\dict

now it works

>>> from wordnet import *
>>> N['dog']
>>> V['dog']
>>> ADJ['clear']
>>> ADV['clearly']

Why lexnames is missing from wordnet 2.1 ?


python dict sort by value

many ways


alist = sorted(adict.iteritems(), key=lambda (k,v): (v,k))


sorted(foo.items(), key=lambda(k,v):(v,k))


def sbv0(adict,reverse=False):
    ''' proposed at Digital Sanitation Engineering
    http://blog.modp.com/2007/11/sorting-python-dict-by-value.html '''
    return sorted(adict.iteritems(), key=lambda (k,v): (v,k), reverse=reverse)

def sbv1(d,reverse=False):
    '''  explicit list expansion '''
    L = [(k,v) for (k,v) in d.iteritems()]
    return sorted(L, key=lambda x: x[1] , reverse=reverse)

def sbv2(d,reverse=False):
    '''  generator '''
    L = ((k,v) for (k,v) in d.iteritems())
    return sorted(L, key=lambda x: x[1] , reverse=reverse)

def sbv3(d,reverse=False):
    ''' using a lambda to get the key, rather than "double-assignment" '''

    return sorted(d.iteritems(), key=lambda x: x[1] , reverse=reverse)

def sbv4(d,reverse=False):
    ''' using a formal function to get the sorting key, rather than a lambda'''
    def sk(x):  return x[1]
    return sorted(d.iteritems(), key=sk , reverse=reverse)

def sk(x):  return x[1]

def sbv5(d,reverse=False):
    ''' using a formal function, defined in outer scope
    to get the sorting key, rather than a lambda
    return sorted(d.iteritems(), key=sk , reverse=reverse)

from operator import itemgetter
def sbv6(d,reverse=False):
    ''' proposed in PEP 265, using  the itemgetter '''
    return sorted(d.iteritems(), key=itemgetter(1), reverse=True)

D = dict(zip(range(100),range(100)))

from profile import run

run("for ii in xrange(10000):  sbv0(D, reverse=True)")
run("for ii in xrange(10000):  sbv1(D, reverse=True)")
run("for ii in xrange(10000):  sbv2(D, reverse=True)")
run("for ii in xrange(10000):  sbv3(D, reverse=True)")
run("for ii in xrange(10000):  sbv4(D, reverse=True)")
run("for ii in xrange(10000):  sbv5(D, reverse=True)")
run("for ii in xrange(10000):  sbv6(D, reverse=True)")


python reading table into list of dicts

create a list of dict from a table. First row of the table is header and rest is data. Each row should be converted to a dict where keys are header value and values are data.


header1 header2 header3
x1 x2 x3
y1 y2 y3
z1 z2 z3



print [dict(zip(header,table[rowx])) for rowx in range(1,len(table))]


[{'header2': 'x2', 'header3': 'x3', 'header1': 'x1'}, {'header2': 'y2', 'header3': 'y3', 'header1': 'y1'}, {'header2': 'z2', 'header3': 'z3', 'header1': 'z1'}]

lifetime of a finalizable object obj

lifetime of a finalizable object obj

  1. When obj is allocated, the JVM internally records that obj is finalizable. This typically slows down the otherwise fast allocation path that modern JVMs have.
  2. When the garbage collector determines that obj is unreachable, it notices that obj is finalizable — as it had been recorded upon allocation — and adds it to the JVM’s finalization queue. It also ensures that all objects reachable from obj are retained, even if they are otherwise unreachable, as they might be accessed by the finalizer.
  3. At some point later (only gc knows when), the JVM’s finalizer thread will dequeue obj, call its finalize() method, and record that the obj’s finalizer has been called. At this point, obj is considered to be finalized.
  4. When the garbage collector rediscovers that obj is unreachable, it will reclaim its space along with everything reachable from it, provided that the latter is otherwise unreachable.

garbage collector needs a minimum of two cycles to reclaim obj and needs to retain all other objects reachable from obj during this process.

Additionally, the JVM does not guarantee that it will call the finalizers of all the finalizable objects that have been allocated. It might exit before the garbage collector discovers some of them to be unreachable.


Difference between keystore & truststore

Difference between keystore & truststore

1. A keystore contains a private key. You only need this if you are
a server, or if the server requires client authentication.

2. A truststore contains CA certifcates to trust. If your server’s
certificate is signed by a recognized CA, the default truststore
that ships with the JR will already trust it (because it already
trusts trustworthy CAs), so you don’t need to build your own,
or to add anything to the one from the JRE.

SSL provides you with privacy, integrity, and authentication. That is,
the messages are encrypted, tamper-evident, and come from an authenticated
identity. Whether that’s the identity you want to talk to is another
question. So the application has to perform the authorization step, i.e.
check the identity against what is expected. You do this by getting the
peer certificates out of the SSLSession, usually in a HandshakeCompletedListener,
and check that the identity of the server is what you expect. SSL can’t
do this for you as only the application knows who it expects to talk to.
Another way around this is to ship a custom truststore that only contains
the server certificate for the correct server, so it won’t trust anybody else.