Interactive diagrams #
Five years ago I got interested in interactive diagrams and made a few, but then got distracted by other things. I wrote a blog post about why I was interested in them. I've recently become interested in them again. Back then, I used Flash, but these days I think HTML5 is a good option. I generally make better progress by starting small, so I've started working on something fairly simple: a diagram showing where the “blind spots” are when driving a car.
(click through to try it)
It's not yet complete but I've already learned some things:
- If you have your seat forward the blind spots are smaller than if you have your seat back.
- The right side mirror shows much less area than the left side mirror. To see a larger area you need to distort the area, which causes things to look smaller. This is why you see “Objects are closer than they appear” on the right mirror but not the left mirror.
In retrospect, these should've been obvious, but the diagram is what made it clear to me. It also became clear that the diagram needs more work. I need to add an option to make the right side mirror curved (I'm not sure what the typical curvature is). I might need to calculate the effect of someone rotating their head. I should measure car mirrors and the driver position inside the car.
It's been a fun little project. I learned some Javascript and SVG, and I got to play with Mike Bostock's d3 library, even though it's overkill for a diagram like this. The process of working on the diagram helped me understand things and motivated me to learn more. I'd like to work on several more interactive diagrams to see if the car diagram is a special case or if interactive diagrams are generally useful for me.
Labels: project
Playing with Amazon EC2 and S3 #
I've been playing with Amazon's S3 and EC2, and they look potentially useful. S3 is the storage system. You pay for storage and transfers. EC2 is the computation system. You pay for virtual computers. Their Getting Started Guide for EC2 is pretty good. It describes step by step how to set up your development environment, then gives you a starter virtual machine to play with. I followed the instructions and got Apache and SSH.
The big advantage of EC2 over running your own servers is that you can get more capacity quickly. In fact it's called Elastic Cloud for that reason. If you're running a web service on a conventional hosting system and then are mentioned on Digg, you're either going to run out of capacity, or you're paying for extra capacity that you're not using most of the time. With EC2, you can monitor for the Digg Effect and add more virtual machines to handle the extra traffic, then release them when the Diggers move on. You only pay when you use the machines.
For my own projects though, I'm never going to get hit by Digg. I was hoping to use EC2 as a cheap low-capacity server. I misunderstood the pricing though. I thought it was $0.10/CPU-hour, but it's actually $0.10/clock-hour. When my server is sitting idle, I'm still getting charged. At $0.10/hour, that's over $70/month, and that's a bit too much to pay for an idle server. I'll instead use my Mac Mini at home.
I might still use S3 for off-site backup. I have regular backups at home, but all the backups are … at home. If anything happens to my home, I lose all copies of all my data. S3 charges for storage, uploads, and downloads, and I estimate that after I upload all my photos, I'd pay $4.50/month. That's pretty reasonable for off-site backup. I haven't investigated whether there are off-the-shelf backup solutions for S3. I want something portable (Linux, Windows, Mac) and command line (so I can automate it). I might end up writing my own quick&dirty scripts for this.
If you're starting a web service, you should definitely take a look at S3 and EC2. They're fairly cheap, and the reliability and flexibility may be worth a lot to your company.
Comics #
I believe in coincidences, but this is a bit strange:
- A few months ago someone recommended I read Understanding Comics by Scott McCloud, not for the comics part of it, but for the ideas about storytelling. I read it a few weeks ago.
- I've been watching Heroes, which is a TV show that works like a comic book story.
- For Christmas I received a Wacom Drawing Tablet, and I've started to learn how to draw.
- I've been playing the demo of Silverfall, which is a game that has hand-drawn art with black outlines around the characters that reminds me a little of comic strips.
- I found out that my Mac comes with a program called Comic Life, which lets me assemble individual drawings into a comic strip with speech bubbles.
Is the universe trying to tell me something? Maybe I should try making some comic strips…
Labels: project
New site redesign notes #
In my last post, I described the new implementation of my web pages and hinted that there was a new design as well. You can compare the old design to the new design to see:
- There's a lot less color. This is probably the biggest change. I like bold colors, but it was too much; it overwhelmed the page and made the headers (which also used the same color) harder to pick out. Section headers are now black (with just a small square of color); the page border is now subdued.
- The text is more tightly packed. (I changed the leading from 1.5 to 1.25.) I have mixed feelings about this; I may change it back.
- Text matches the line spacing of the main text as much as possible. I'm a little skeptical of this rule, as it seems to result from limitations in printing presses, but a friend of mine who really knows his typography recommends it.
- There's a print-friendly version of the style using
@media screenstyle rules to enclose sections designed for regular screens and@media printstyle rules to enclose sections designed for printing. The navigation bar, sans-serif body font, shadows, and colored backgrounds are removed for printing. I didn't write any rules for other media types. - There's more whitespace on the left, except to the left of headings.* This makes headings a little easier to pick out.
- The page contents have a soft shadow around them; preformatted text has a soft shadow inside.*
The items with a * are enabled by the implementation; they were not something I could easily do with CSS alone. Each section is now a container with both a title and contents:
<x:section title="Header">
<p>
Paragraph 1.
</p>
<p>
Paragraph 2.
</p>
</x:section>
In HTML, the sections are implicit—they are whatever occurs between headers. In the my XML content, the sections are explicit. That way I can apply a style to the section, such as adding a margin to the left. This is something I've long wanted through various redesigns. Sometimes I want a border; sometimes I want a horizontal line separating sections; sometimes I want them to be a different color. Now that I have each section marked, I can choose a combination of HTML tags and CSS rules to achieve the effect I want.
I treated the document in the same way as the sections. In HTML, the header and footer are inside the document body. This means any style rules that apply to the body contents (such as margins) also apply to the header and footer. I often want the header and footer to span the entire width of the document, so this makes the HTML messier. With XSLT, I can create a new document body (with <div>) and move the header and footer outside of it. To get the shadow effect, I use three divs, each with a different border color. Preformatted text gets surrounded by three divs as well. XSLT lets me inject new elements that are used purely for formatting.
I tried using serifs for the body font but it was too much of a change for me, and it doesn't work as well on lower dpi screens. There are still a few things to clean up, including the rendering in Internet Explorer, but overall I'm pretty happy with the style.
Labels: project
New site design and implementation #
As long as I've been writing web pages, I've experimented with ways to manage them. Long ago I used the C preprocessor to give me server-side includes and simple macros. It was a mess, since the C preprocessor parses single quotes and double slashes (for C character constants and C++ comments), and both of those occur in other contexts in web pages. Later on I built something that could automatically build navigation trees for each page. I also experimented with but never fully adopted a system that would let me write HTML in a simpler syntax. I built tools that would take multiple text files and assemble them into a larger page. I also tried using third party tools, like LaTeX2HTML. I eventually abandoned all of these systems. They were too complex and introduced dependencies between input files, and I then had to manage those dependencies.
The last time I had the web page management itch, I wrote down what I wanted out of any new system I set up:
- Portable. I want to depend on as few external tools as possible, so that I could run this on a variety of systems, including Windows, Linux, Mac, and the restricted environment where my web pages are hosted.
- Straightforward. I had abandoned several of my previous systems because they imposed restrictions on what I could put into my document. I'm comfortable with HTML, and I'd like to just write HTML as much as possible. The more abstractions I put in between my system and the final output, the more restrictive and complex it will be.
- Fast. Several of my previous systems had to analyze all of my documents in order to rebuild any of them. In particular, navigation trees require analyzing other nodes in order to create the links. If I only edit one document, I want my system to regenerate only one HTML file. Therefore this rule requires that I do not put in navigation trees.
- Simple. I'm lazy. I don't want to write a complicated system to manage my pages. I just want to get the low hanging fruit and not worry about solving all the problems.
- Static. I have to produce static HTML; I don't have a web host where I can run web apps or CGI scripts.
I ended up learning and using XSLT. I do not particularly like XSLT, but it's a reasonable tool to start with. When HTML and XML documents are viewed as trees, XSLT is used to transform (rearrange, erase, and add) tree nodes.
The first step was to extract the content out of my existing web pages. Each page has a mix of template and content. The extrator separated them. I had written these pages in different styles over a period of ten years, so the headers, navigation, HTML style, etc. are not consistent. Some of the pages were generated by other tools I had used. While looking at the old HTML, I decided that I would not be able to treat them uniformly. I added to my requirements:
- Optional. Some pages will use the new system and some pages will not. I will not migrate everything at once.
I wrote XSLT to extract content out of some of my web pages. I grouped the pages by their implementation and style. I handled the extraction in four ways:
- If the page already fit my extractor, I left it alone.
- If the page with some minor changes would fit my extractor, I made those changes to the page.
- If the page would fit the extractor with minor changes, I made those changes to the extractor.
- If the page would require major changes to either it or the extractor, I excluded it.
I thus had a set of pages (some modified), a set of pages to exclude, and an extractor. The extracted content was in the form of XML files (which were mostly HTML, with some XML meta information.) I tested them by inspection; it was hard to tell whether I got things right until the second step: injection. In the second step, I combined the content of each page and a new template I had written, producing HTML. I then compared the new pages with the old pages, side by side, in several browsers, until I was reasonably happy with the results. I rapidly iterated, each time fixing the extactor, the injector, or the old HTML (so that it'd extract better). Any pages I couldn't fix at this step I wrote down for later fixing.
To summarize, during this stage of development I had old pages, an extractor, a set of content pages (the results of the extractor), an injector, and new pages (the results of the injector). Some pages I had excluded from the entire process, and others I had marked as needing repair. I also had a set of things I'd like to do that XSLT couldn't handle.
After testing the output extensively, I was finally ready to make the switch. Tonight I replaced the old pages with the new ones. I no longer run the extractor. This means the content pages are no longer being overwritten, so I can now edit those pages instead of the old web pages. I went through the list of pages that needed repairs and fixed them. I tested every page on the new site, fixed up a few minor leftover problems, and pushed the pages to the live site.
I'm much happier with the new system. It's not a series of hacks and it's not custom code. It's using XML and a very simple shell script. It runs on Windows, Mac, and Linux. There is still more to do though. Not all of my pages use the new system or my new style sheet. Some parts of my site, including the blog, will continue to use an external content management system, so I will apply my new stylesheet and template without using the XML injector. There are a few more minor features that I want to implement, and there are more pages to clean up. I'm not in a rush to do any of this; it'll probably take a month or two. I've also been reluctant to edit my pages until now, because any changes I made had to be duplicated on the development pages (which I had modified to make the extractor work). Now that the new pages are up, I can resume working on the content of my pages.
I do recommend that people look into XSLT, but I think it's not sufficient for most needs. It does handle a large set of simple cases though; I'll fill in the gaps with some Python or Ruby scripts. If you find things on my site that don't work properly, let me know; I'm sure there are bugs remaining.
Labels: project
Paint.NET is nice #
I usually use The Gimp for image manipulation. It's like Photoshop in that it's a complex interface designed for complex tasks. Most of my needs are simple though. They're more complex than what Microsoft Paint can handle but nowhere near what Gimp can handle. I recently tried Paint.NET after reading some good reviews, and I'm really happy with it. It's very easy to use and has a nice interface. All I've done so far is cropping, working with layers, painting in various colors, and adding text. Next time I need to manipulate an image, I'll likely to use Paint.NET instead of Gimp.
Labels: project
Yapps 3.0 #
[Update: I abandoned this project for several reasons, the main one being that I didn't have an immediate use for a parser system at the time.]
I've been working on a major upgrade to Yapps (Yet Another Python Parser System). Yapps was designed with two things in mind: it should be easy to use and it should be easy to understand output. I think I got those two pretty well. However, as I try to push the system to do more, I'm finding that easy to use and easy to understand output are coming into conflict:
- LL(1) recursive descent parsers are easy to understand. But they make it harder to write grammars, because you have to manually left-factor.
- Better error messages would make Yapps easier to use. But tracking the information needed for better error messages clutters up the parser, making it harder to understand.
So far, I've been leaning towards more ease of use and less readable parsers. Some more things I want to implement towards that goal:
- Abstract rules: a way to reuse common patterns used in writing rules.
If you want to parse a comma-separated list of numbers in Yapps 2, you'd write a rule like this:
rule number_list: {{ numbers = [] }} ( number {{ numbers.append(number) }} ( ',' number {{ numbers.append(number) }} )* )? {{ return numbers }}If you then want to parse a colon-separated list of strings, you have to write a very similar rule with a different delimiter and pattern. When you need to parse a semicolon-separated list of statements, you may be wondering how you can avoid writing this pattern repeatedly.
Abstract rules are rules that have named placeholders. For the above rule, you'd write
rule delimiter_separated_list[delimiter][element]: {{ results = [] }} ( element {{ results.append(element) }} ( delimiter element {{ results.append(element) }} )* )? {{ return results }}You'd then be able to invoke that rule with
delimiter_separated_list[','][number],delimiter_separated_list[':'][string], anddelimiter_separated_list[';'][statement]. I'm running out of delimiters, though. I've already used[ A B C ]for optional matches. I'll probably switch to the standard EBNF form for optional matches,(A B C)?, to free up brackets for something else. - Inheritance of Parsers: the ability to reuse an existing parser's rules when defining a new parser.
In Yapps 2, I find that I often copy and paste tokens and rules from one parser to another. The most common ones are strings, numbers, identifiers, and delimiter-separated lists. I'd like to be able to define these in one place and then inherit them in the parsers I'm writing.
To implement this, Yapps needs to be able to decipher an existing parser's First and Follow sets. I can either do this via reflection at the Python class level or I can implement inheritance directly at the grammar level. Either way, parsers would be more useful if you could reuse them in larger parsers.
I've also been thinking about some more radical changes to Yapps:
- Backtracking: abandoning the LL(1) restriction.
The Toy Parser Generator (don't be fooled by the name -- it's quite powerful!) supports full backtracking. You don't have to worry about whether your grammar is LL(1) or not; you can write it in a more natural style. However, I'm not sure how backtracking interacts with imperative actions. I've thought about using something like Haskell monads, but without decent support for blocks, it's hard to do this properly in Python. I might be able to delay all the actions by constructing a string at parse time and then using
execwhen the parser is complete. However, that has the disadvantage that the actions can't influence the parser. (On the other hand, without backtracking, the actions can't meaningfully influence the parser anyway.) - Run Time Parser Generation: abandoning the model of generating a Python source file.
One annoying feature of most parser generators is that they generate source code, which then has to be compiled/run in a separate process. It'd be much nicer to build a parser within a running program. With Python, this doesn't seem hard to do. Even in the most static of languages -- C++ -- you can generate parsers without creating a separate source file, using the Spirit parser library.
I'm not yet sure whether I'll implement the more radical changes.
Labels: project