Saturday, 27 June, 2009. 12:54:55 AM
Memory upgrade on helium from 4G to 8G done tonight. This will allow more virtual machines to run at the same time.
/n
Thursday, 25 June, 2009. 10:31:20 PM
When I was in 6th grade I cut a reproduction of Farrah's famous pinup poster out of a magazine, took it to school, and impressed all my friends with it.
/n
Saturday, 20 June, 2009. 11:09:20 PM
I'm thinking of moving my site from a set of static pages generated by custom Python scripts to a dynamic EEJB site with a Postgres database under it.
/n
Friday, 12 June, 2009. 01:36:10 PM
I just ordered a paper copy of one of my favorite books: "The
Metamorphosis of Prime Intellect" by Roger Williams. In my life I've
only read a few books more than once, and that includes MOPI (3 times)
and the entire Dune series (2 times). I may as well own a physical copy.
/n
Tuesday, 09 June, 2009. 12:57:20 AM
For a long time now I've struggled with the American English placement
of punctuation inside of adjacent quoted words.An example would be
ending a sentence with a quote; for example here, Abraham Lincoln's
famous phrase "four score and seven years ago." That previous sentence
is properly ended with the period inside of the ending quotation,
according to the American convention. This is fine for conventional
English. In England, apparently the convention
is to place the period outside of the ending quotation.
When the American convention is followed in computer instruction manuals,
it can cause confusion. For example, a manual might instruct a computer
to list the directory by typing "dir." If the user entered the quotation
as written, D-I-R-{period}, that would be an error. Only someone who was
already familiar with the correct command syntax would be able to tell
if the period was required.
It would be possible to clumsily rephrase each sentence to not end with
a quotation, but it would be far preferable to just abandon the American
convention in favor of the British convention. The punctuation should
always be placed outside of the quotation mark. I think that this usage
will become more and more common as the meaning of a quotation becomes
understood as a literal sequence of characters. Any other convention
invites ambiguity.
/n
Sunday, 07 June, 2009. 09:37:57 PM
I've been working on a recursive zipfile reader that uses the Poco Zip library.
Poco Zip is really easy to use for extracting zipfiles, but I needed it to also
look at zipfiles inside of zipfiles (as many levels deep as needed). I thought
the PartialInputStream library was going to work, but it's buggy. It doesn't keep
a proper file position pointer.
My solution was to mmap the file and use that as a buffer on a StringStream to read the file.
Enclosed zip files just needed the buffer to be mapped to a new location in the mmap and
call the extraction recursively.
/n
Friday, 05 June, 2009. 11:14:38 PM
POCO Partial Input Stream
Constructor:
PartialInputStream(
std::istream & istr,
std::ios::pos_type start,
std::ios::pos_type end,
bool initStream = true,
const std::string & prefix = std::string (),
const std::string & postfix = std::string ()
);
It's a tricky class, and the documentation isn't useful at all, so here's a better description of this useful function.
A PartialInputStream reads a subset of bytes from the istream passed in. The 4 parameters PLUS the file position of the istream passed in determines what subset is actually read.
Case #1
The input stream is used to directly initialize the PartialInputStream. Start is set to 0, meaning that the character counter starts incrementing from 0. End is set to 7, meaning that the PartialInputStream will return eof()==true when it the character counter reaches 7. The total number of characters read is the end position-start position (7).
Test input file:
0123456789 (10 bytes)
ifstream inp("testfile", std::ios::binary);
PartialInputStream pis(inp, 0, 7, false);
while (!pis.eof()) {
int ch = pis.get ();
cerr << (char) ch << " " << (int) ch << endl;
}
output:
0 48
1 49
2 50
3 51
4 52
5 53
6 54
? -1
Case #2
The input stream is used to directly initialize the PartialInputStream. Start is set to 2, meaning that the character counter starts incrementing from 2. End is set to 7, meaning that the PartialInputStream will return eof()==true when it the character counter reaches 7. The total number of characters read is the end position-start position (5).
Test input file:
0123456789 (10 bytes)
ifstream inp("testfile", std::ios::binary);
PartialInputStream pis(inp, 2, 7, false);
while (!pis.eof()) {
int ch = pis.get ();
cerr << (char) ch << " " << (int) ch << endl;
}
output:
0 48 character counter is 2
1 49 character counter is 3
2 50 character counter is 4
3 51 character counter is 5
4 52 character counter is 6
? -1 character counter is 7
Case #3
This is just like case #1, except the initializing input stream has a byte already read from it. The character counter starts at 0, and reading continues until the character counter reaches 7. Because the initializing input stream was positioned at file position 1 instead of file position 0, the output is slightly different from case #1.
Test input file:
0123456789 (10 bytes)
ifstream inp("testfile", std::ios::binary);
inp.get();
PartialInputStream pis(inp, 0, 7, false);
while (!pis.eof()) {
int ch = pis.get ();
cerr << (char) ch << " " << (int) ch << endl;
}
output:
1 49
2 50
3 51
4 52
5 53
6 54
7 55
? -1
Case #4
This is just like case #3, except the initStream flag is set to true. The initializing input stream had a character read from it, but the initStream flag instructs the PartialInputStream to ignore that. The PartialInputStream doesn't begin reading from the file position of the initializing istream, but from the beginning of the initializing istream. Therefore, despite the inp.get() which moved the file position, the PartialInputStream behaves as if that character had not been read at all.
Test input file:
0123456789 (10 bytes)
ifstream inp("testfile", std::ios::binary);
inp.get();
PartialInputStream pis(inp, 0, 7, false);
while (!pis.eof()) {
int ch = pis.get ();
cerr << (char) ch << " " << (int) ch << endl;
}
output:
0 48
1 49
2 50
3 51
4 52
5 53
6 54
? -1
Case #5
This is just like case #1, except the prefix and postfix strings are set. The output contains the prefix and postfix strings on the front and the back of the stream. The data is otherwise read from the file as expected.
Test input file:
0123456789 (10 bytes)
ifstream inp("testfile", std::ios::binary);
PartialInputStream pis(inp, 0, 7, false, "prefix", "postfix");
while (!pis.eof()) {
int ch = pis.get ();
cerr << (char) ch << " " << (int) ch << endl;
}
output:
p 112
r 114
e 101
f 102
i 105
x 120
0 48
1 49
2 50
3 51
4 52
5 53
6 54
p 112
o 111
s 115
t 116
f 102
i 105
x 120
? -1
/n