Python Element Tree Writing to New File

The ElementTree.write method defaults to us-ascii encoding and as such expects a file opened for writing binary: The output is either a string (str) or binary (bytes). This is controlled by the encoding argument. If encoding is “unicode”, the output is a string; otherwise, it’s binary. Note that this may conflict with the type of … Read more

Represent directory tree as JSON

I don’t think that this task is a “wheel” (so to speak). But it is something which you can easily achieve by means of the tools you mentioned: import os import json def path_to_dict(path): d = {‘name’: os.path.basename(path)} if os.path.isdir(path): d[‘type’] = “directory” d[‘children’] = [path_to_dict(os.path.join(path,x)) for x in os.listdir\ (path)] else: d[‘type’] = “file” … Read more

Fast, templated, C++ Octree implementation

http://nomis80.org/code/octree.html This is my favorite. It is GPL and has it’s own homepage, so it’s meant to be used by others. It has Doxygen documentation, and the authors are taking questions. http://www.flipcode.com/archives/Octree_Implementation.shtml This one is not templated. It has more comments in the code than every other I’ve seen, so that might be more useful … Read more

How do I show marriages in a d3.js based ‘family-tree’?

There are some options, but I believe each would require a bit of work. It would help if there were one single standard for representing a family tree in JSON. I’ve recently noticed that geni.com has a quite in-depth API for this. Perhaps coding against their API would be a good idea for reusability… — … Read more

Tail recursive function to find depth of a tree in Ocaml

You can trivially do this by turning the function into CPS (Continuation Passing Style). The idea is that instead of calling depth left, and then computing things based on this result, you call depth left (fun dleft -> …), where the second argument is “what to compute once the result (dleft) is available”. let depth … Read more

Representing an Abstract Syntax Tree in C

You can make any of these work. I prefer the union layout, because then all nodes have “the same” layout. [You may find it useful to have a “child sublist” option, e.g., and arbitarily big, dynamic array of children, instead of having left- or right-leaning lists.] You are going to find that this issue isn’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)