The READIN Family Album
Me and a frog (August 30, 2004)

READIN

Jeremy's journal

Dream is not a revelation. If a dream affords the dreamer some light on himself, it is not the person with closed eyes who makes the discovery but the person with open eyes lucid enough to fit thoughts together. Dream -- a scintillating mirage surrounded by shadows -- is essentially poetry.

Michel Leiris


(This is a page from my archives)
Front page
Most recent posts about The site
More posts about Projects

Archives index
Subscribe to RSS

This page renders best in Firefox (or Safari, or Chrome)

Monday, October 8th, 2007

🦋 On reinventing the wheel

When I was new to programming, in 1994 or '5 -- when OLE was a pretty freshly minted technology -- one of the projects I was working on was a way to abstract the functionality of some of my company's libraries into a common interface so that a program could load any of the libraries dynamically at runtime, based on a string key. I came up with the stunning realization that the interface could be expressed as a pure virtual C++ base class. All the libraries had to do was to export a function called "Create_x" which would instantiate an object whose class inherited interface x.

This seemed to me like an awesome bit of innovation. By funny coincidence, another project I was working on around the same time was converting some of the company's VBX controls to OCX. (I don't think the term "ActiveX" had even been coined yet, but regardless we were not using it.) I wasn't reading the documentation of OLE very closely, relying on Microsoft's compiler to do most of the work for me; so it wasn't until a month or so later that I realized I had just reinvented a subset of OLE, and that I could have used OLE's framework to give my design a little more robustness. But whatever, the feeling that I was doing something new and inventive was payoff enough.

So why this now? Well, I've been doing some pretty intensive design work in coming up with the database that supports this blog ("READIN 2.0", I am calling it in my head), and I have come up with a pretty cool idea. It seems innovative to me because it is something I've never heard of anyone doing; but I am not at all schooled in database design. I will write it up later on or tomorrow, and hopefully somebody will write back to me and let me know who invented it and where I can find out more.

posted evening of October 8th, 2007: Respond
➳ More posts about Programming

🦋 Categories

Like I said below, I don't have much experience with database design. I don't really have any clue how to write a design document. But I want to describe the design I've come up with and see if I can make it sound as good as it appears to me to be.

The thinking behind this is as follows: I have a lot of text records ("posts") which I want to classify by subject. I've done this, just like every other blog around, by using keywords -- if I tag a post with "food" say, or "singing", then it will show up when somebody looks at the site filtering for that subject. This is implemented with a simple search through the list of keywords on each post; not particularly fast but that's not a major problem in the context of my low-traffic site.

But when I was putting the new software together, I had the idea that it would be great if, when somebody looked at the blog filtering for "food", they would see a little sidebar explaining what I write about when I write about food, and maybe some links to food sites I like etc. And more to the point, when somebody filters for "book:namered" (which is how I've been tagging my reading posts, "book:" and then a short identifier for the title), they would see up top that the posts were about My Name is Red by Orhan Pamuk, links to some outside reviews, links to Amazon and Abebooks, maybe a list of other of Pamuk's books that I have written about. So that is the problem I am trying to solve; and I think my solution is a pretty good one.

First, simple keywords, like "food" and "singing". This is pretty easy; I have a table keyword with columns tag and description -- the description is what will be displayed in the sidebar when somebody filters by the tag. And I have a table (which I decided to name categories, for reasons that will soon become apparent) with two columns, postid and keyword -- I can join this table with posts when I want to do a filtering operation.

Now what about the complex keywords like "book:namered", which include a class and an instance? Well check it out: every time I add a keyword which has a new class, I can just add a column to the categories table with the class name as the column name. And add a table with that name, which looks the same as the keyword table. And think of simple keywords as a special case of complex keywords, as if they had "keyword:" in front of them. So if somebody requests a filter for "book:namered", I can query from "posts JOIN categories ON posts.id = categories.postid JOIN book ON categories.book = book.tag" where book.tag = "namered". This will work for movies, projects, whatever. But the really cool thing is, I can add whatever columns I want to the book table and write a custom script to display the data associated with the tag "namered" in my sidebar.

Consider these three requests:

  • SELECT posts.* FROM posts JOIN categories ON posts.id = categories.postid WHERE categories.book = 'namered';
    (This query would be represented by the keyword "book:namered".)
  • SELECT DISTINCT posts.* FROM posts JOIN categories ON posts.id = categories.postid JOIN book ON categories.book = book.tag;
    (This query would be represented by the keyword "book:".)
  • SELECT posts.* FROM posts JOIN categories ON posts.id = categories.postid JOIN book ON categories.book = book.tag WHERE book.author = 'pamuk';
    (This query would be represented by the keyword "book:author:pamuk".)

The first query will bring back all posts about My Name is Red. The second query will bring back all posts about reading any book. The third query will bring back all posts about reading any book by Orhan Pamuk. And all this is pretty easy to automate! It's all nearly in place!

The next step, which will be a bit of effort to keep it elegant but totally within reach, is to create an administrative page for writing scripts to render an informative sidebar based on the column data contained in, say, the "namered" record in books.

posted evening of October 8th, 2007: Respond
➳ More posts about Programming Projects

So as I go through my site testing various filters and archive pages, I am reading a fair amount of what I've written over the last four years. And -- im ganzen und großen -- I'm pretty happy with it.

posted evening of October 8th, 2007: Respond
➳ More posts about Projects

Friday, October 12th, 2007

🦋 Passed the first test

So in my log I see a bunch of requests today for

GET blog/?k=<keyword> \'\'
and(char(94)+user+char(94))>0 and 
\'\'\'\'=\'\'

where <keyword> is one of the keywords that links exist to on the site; and also I see that my script translated those requests to

<keyword> \\\'\\\' 
and(char(94)+user+char(94))>0 and 
\\\'\\\'\\\'\\\'=\\\'\\\'
before passing them to the database. So the queries just returned empty sets instead of wreaking whatever havoc they might have wruck unescaped. Yay PHP! Yay careful programming!

(Note: but while editing this post I realized there is a different kind of escaping that you have to do when you are writing to forms -- the < and > signs were translating to markup in my inputs. Funny I never ran into that problem on the old site, you wouldn't think it would be a PHP-vs.-ASP distinction.)

Update: So what do I have to do to ban these guys from my site? I tried putting the following in my httpd.conf:

<Directory (path to root of my site)> order allow,deny deny from (IP) deny from (IP) allow from all </Directory>
and restarting the service, but that does not seem to have done it.

Another Update: I think I got it: the Directory directive in apache2/sites-available/default is overriding the directive in httpd.conf because httpd.conf is included first. I think I just need to take the default directive out.

posted evening of October 12th, 2007: Respond

Monday, October 15th, 2007

🦋 Font query

I'm interested in sweetening up the look of this blog by changing the fonts used, and wonder if anybody reading has advice about what fonts to use. Here is what I'd like to do:

  • The three sections of the blog -- left sidebar, body, and right sidebar -- should be distinguished from each other. My thinking was that the left sidebar should be a slightly smaller font size, and maybe the right also, and possibly a different named font. But I don't have a designer's eye of what named font looks good where.
  • The headers should be a different font from the text, I was thinking they should be sans-serif.

That's pretty much it; I will check what wordpress stylesheets look like, since I tend to really like their presentation. I need to learn how to use css, which seems pretty easy but which I have been resisting up until now. Anyone got advice for me?


Update: Hmm... well that's something anyway. Plagiarized some styles from wordpress, added a couple of my own. Still not totally sure how this thing works.

posted evening of October 15th, 2007: Respond

Tuesday, October 16th, 2007

🦋 Comments are open

Ok: All the time I've had a blog I've wanted to host comments. And now I do, at least in a rudimentary fashion. You need to put <br> and/or <p> tags in your text if you want paragraph separations. html is allowed for now; indeed security is almost entirely lacking. It would probably be possible to break my software; please don't try. Or at least, send me a note if you have an idea for something that could break it.

Update: I fixed it so you do not have to markup your paragraph separations. Yay me!

Update as of Wednesday morning: Here are some more things you can newly do: Include apostrophes in your name/handle, and not have them show up backslash'd; include apostrophes in the body of your response, and not have the whole thing chucked out; include links in your response and not have them stripped out. I am using tidy to clean up the html in the comments and it is a temperamental thing. Powerful tho'.

posted evening of October 16th, 2007: 10 responses

Thursday, October 18th, 2007

🦋 First comment spam

Wow, that was fast! Guess I will hafta come up with some kind of security thingy.

Update: Well I wrote a script for quick deletion of spam. What should I do about blocking it? A captcha?

posted morning of October 18th, 2007: Respond

Tuesday, November 6th, 2007

🦋 Woo-hoo!

I hit on a way to defeat comment spam coming in from chin/e/sefr/eewebs, which I'm getting a lot of lately. Not saying what in public, in case they come around and notice; but if you are getting hit with similar traffic, drop me a line and I'll give you the recipe. It's pretty simple.

posted afternoon of November 6th, 2007: Respond

Friday, November 9th, 2007

🦋 Archives

Looking for that READIN post you read and enjoyed last year, but can't find it? I've added an Archives page that should be of some use. Posts are sorted by topic and by date. Let me know if you like it or if you think of any features that would make it more useful.

posted morning of November 9th, 2007: Respond

🦋 Reboot! Restore!

Boy oh boy, tonight I rebooted the new server for the first time since I got it running back in late September! Why, you might ask -- it was not sick, nothing was wrong with it. Well: I inherited an oldish flatscreen monitor from my workplace -- a reboot was necessitated in order to get the computer talking to the screen. That's kind of big news; the old monitor was the one I've been running with ever since I inherited the previous computer from my previous workplace back in 1996 or thereabouts. It was a totally inappropriate monitor for the purpose it was serving; a monstrous, 22" CRT that must weigh over 30 lbs., that totally dominated the desk even though it was never turned on. The new screen will be a much better neighbor for the other things on the desk.

I was a little concerned when I rebooted and the web site was not accessible; I had sort of assumed that apache set itself up, when I installed it, to run as a daemon without anyone having to log in. Turns out that's not the case! Anybody want to tell me how to make it so? sshd starts automatically, which is good. Took me a little while to figure out how to start mysqld -- this would also be a great process to have loaded automatically when the system boots.

And: After I posted this, I noticed its id was 877 and I thought that's weird, wasn't I posting stuff in the 880's earlier? And I looked at my database backup from this morning (!) and saw that there were indeed more posts than I was seeing on the site. Kneel before me, Mysql! I know how to backup and restore databases! (And thanks, Mysql, for making it so easy to do, that a lazybones like myself can do it.)

So... If you're commenting on this post and want to tell me how to get mysql and apache auto loading, it would be great if you could drop a hint about how to make mysql exit gracefully as well, because it sure seems like it did not do that this evening.


Update: Developing... it looks like to make apache and mysql load on boot, I need to put them in /etc/rc.d/rc.local. Now, my computer has no such directory; but it does have rc?.d where ? is a number from 0 to 6 or the letter S. There is also etc/init.d. I should be able to figure this out...

posted evening of November 9th, 2007: Respond

More posts about The site
Archives

Drop me a line! or, sign my Guestbook.
    •
Check out Ellen's writing at Patch.com.

Where to go from here...

Friends and Family
Programming
Texts
Music
Woodworking
Comix
Blogs
South Orange
readincategory