Water’s series, using producing

Posting for the memory book.  Appendix A in the Common Lisp manual is a package Richard Water’s created known as series.  A series is a kind of hybrid between sequences (think lists) and streams.  They are cool because the resulting code is damn fast; usually compiling down to raw loops.  In anycase I had more trouble writing the following than I expected.  I kept writing setf rather than setq; which creates some bizarre errors.  Errors printing results actually.  It would also be good if I’d actually read the doc for producing, rather than just skimming it, for any given FOO or BAR the (next-in FOO ...) and (next-out BAR ...) forms should appear once and only once.    You get extra points if they appear at the start or tail of the tagbody respectively.

In this example we want to inhale two series nibbling off one or the other as appropriate.  Series a pain to use when doing this kind of mingling; but mostly because they don’t have a way to seek forward more rapidly than pulling items off the inputs one at a time.  What also makes them painful to use at this level is that you have to write at a level that is enjoyably only because it invokes a nostalgia for assembler language.  No doubt it one was writing a lot of his kind of code then you’d make a micro language that compiles into this pseudo assembler.  The series sources do something along those lines; making them wonderfully hard to read.

I’m really not fluent in using this package, so critiques from more expert users would be welcome.


(defun union-integer-series (s1 s2)
  "Given two ascending series of integers return a series of those integers
    which appear in both."
  (declare (optimizable-series-function)
                    (series s1 s2))
  (producing (items) ((g1 s1) (g2 s2) i1 (i1-ok nil) i2 (i2-ok nil))
      (loop
            (tagbody
                  --TOP--

                  (if i1-ok (go --I1-OK--))
                  (setq i1 (next-in g1 (terminate-producing)))
                  (setf i1-ok t)
                  --I1-OK--

                  (if i2-ok (go --I2-OK--))
                  (setq i2 (next-in g2 (terminate-producing)))
                  (setf i2-ok t)
                  --I2-OK--

                  (unless (= i1 i2)
                      (cond
                          ((< i1 i2)
                            (setq i1-ok nil))
                          (t
                            (setq i2-ok nil)))
                      (go --TOP--))

                  (setq i1-ok nil)
                  (setq i2-ok nil)
                  (next-out items i1)
                ))))

By example

> (setf *print-length* 7)
7
> (scan-range :from 5)
#Z(5 6 7 8 9 10 11 ...)
> (scan-range :upto 9)
#Z(0 1 2 3 4 5 6 ...)
> (union-integer-series * **)
#Z(5 6 7 8 9)
> 

Cost of Heating

Any  amateur  economist knows that if two goods can substitute for each other they will, overtime, adjust their prices to about the same level.  So obviously the choice between oil or gas for heating your home shouldn’t be a matter of price.  So, being a gadfly, I found myself taking the contrarian point of view in an  argument  last fall.  At the time it was much cheaper to heat your house with gas, and it has only gotten worse.  This is, of course,  bizarre.  But as this chart shows it’s been true for years and years.

Those are US Department of Energy forecast numbers.  They are published annually, for example here are the recently released 2008 numbers.  That link is a good place to get a sense of what the numbers mean.  I drew the numbers for the other years from this page.  Even amateur economists are right some of the time.  I can’t believe that’s stable.  Maybe I should be trying to lock in my natural gas fuel price for next winter.

Mindreading webpages!

Ben Adida brings our attention to this cool, but evil, hack for seeing into your visitor’s minds!

Aza Raskin’s hack is a bit of java script that lets you adjust the web page based on the user’s browsing history, say to show the bookmarking links that this user actually uses.  I was quite amused at Aza’s use of the term village bicycle  to describe a page that links indiscriminately to dozens of 3rd party sites; it reminded me of the term link slut.  This technique works because you can put a few dozen links on your web page and then using java script the page can glean out which ones the visitor has previously visited; using that data the javascript can then customize the page.

But now I’m fascinated by the idea that you could build pages using this technique that glean estimates of various attributes about the visitor.  For example say you put a few dozen each of left wing and right wing political sites and then compute a score for where on the political spectrum the visitor is.  It would be fun to make a bunch of examples.  Age, sex, politics, income, etc.  Each one of these could be distilled down to a single Javascript widget, it might display a badge.  An exercise for and upon the reader.

This is a perfect example of the kind of thing which Caja[1,2,3] is meant to fix.  We should all send positive thoughts in that projects direction at regular intervals.

Boffins look to brain scans to breath life into Web Frankenstein!

The World Wide Web Consortium’s offices are in the world’s most marvelously silly building, the cartoon like Stata Center. Among these boffins are a few working to bring the Semantic Web to life.  Nearby other experts labors away on computer science’s more esoteric arts: robotics, origami, cryptography, even user interface!

Surrounding the Stata Center are larger less fanciful buildings full of wetter sciences: brain sciences, genetics, and such.  More of the bland massive buildings are going up all the time.

The Brian Sciences center looms outside the windows of the folks working on the Semantic Web.  Over the last few years I’ve often wondered if that was a little joke on somebodies part, the Gods possibly.  Or that God of campus life, the facilities manager.  This kind of thinking afflicts my brain.  Put two random things in and I start finding amusing associations.  It is often a kind of a buzzword bingo in here.

So I was delighted to encounter this article in Ars Technica, which garners a very high scoring round at buzz word bingo. “The Semantic Web gets a boost from functional MRIs.”    The author must have been giggling!  I think his headline writer let him down, I like my headline better.

Cities

Paul Graham writes about ambition and cities.  Paul seems quite concerned about ambition, status, but yet I really like this essay.  It’s a nice variant on the well studied theme of specialization in cities.  Regions specialize, for example Hartford in insurance and guns, and so it’s natural that each region’s alpha-males would be drawn into that specialization.  Those who particularly aspire to ladder climbing will then strive that way.

The other thing I like about Paul’s essay is how, no doubt, natives of each venue he passes over will be offended.  He is, of course, making quick cartoon versions of each town and cartoons always offend somebody.

The New York City he describes is not the NYC of my youth.  More than anything else the NYC of my youth was about diversity.  So many many things packed together into one space.  It was, it seemed to me then, impossible to climb to the top of that pile.  There were so many distinct piles, all running off in different directions.  I can certainly feel that same way about NYC these days, but yet his  caricature  of NYC as a place where the ambition is all about wealth rings true, about  Manhattan.  So much of Manhattan  seems more like a odd walled community of the rich built out  remnants  of the more authentic city that was there before.

He allows that Silicon Valley is about power.  Sure that’s true, but it would not be at the top of my list.  At the top is a pervasive engagement with building things.  Usually via  entrepreneurial  activity.  While I have hung out in lots of places where people talk about it, the Valley is the only place were it was in the water.  And there it was a form of play; like football or dancing.  People who love to do create firms that do something new everywhere you turn.  If that’s your kind of fun then that’s the place to live, just as if you love playing in a good  intellectual  thicket living in Cambridge you will find it easy to find other playmates.  What he says about power, it’s true.  It’s something that the guys that came and had a lot of fun building things come to learn, but they all seem sad about.

He seems to be describing smaller cities, like the one Hammett  sited Red Harvest in, where the whole place’s workings could be revealed by throwing one or two well aimed spanners into the works.  Cities over a certain scale ought to be able to be about many things, not one, and so they shouldn’t by default drag all their strivers into a single pattern.  I don’t know, maybe globalization has made that something of a  nostalgic  fantasy.

Example random icons

Here are random icons generated from the entries on my PGP/GPG keyring; i.e. I grep’d out the fingerprints, jumbled them a bit for privacy, and then gin’d up identicons and wavitars for them.

Meanwhile, here’s another scheme to gin up images from random numbers; in this case the numbers are slightly less than random, e.g. barcodes. Barcode Plantage. It would be fun to have one that was based on a tangle of string, or a knot. This fun hack wordle could be repurposed for this as well.

Negative Energy

I have sighted a new urban myth: Electric heating is cheaper than oil heat! Here in Boston people heat with both gas and oil, and the cost per unit of heat between the two has diverged rapidly over the last few years. Those who heat with oil are looking for ways out of their plight. Apparently the rumor making the rounds that it is cheaper to use electric. That’s not true.

In related news Martin  brings my attention to a company EnerNoc that sells negative energy, i.e. load shedding, to the utilities. They use telecom and widgets to shift power consumption from high demand time periods into low demand time periods. Martian’s example is the fridge. You chill when power is plentiful and let it coast when others are paying higher prices.

I assume that EnerNoc’s role in all this is to aggregate small power users into a large enough pool to be worthy of selling to the utilities. It’s a interesting example of a coordination problem. There are of course other ways to approach the problem; ones that are less dependent on a thicket of contracts and ongoing coordination signals controlled by a middleman and enabled, as Martian, points out by the telecom infrastructure.

The obvious alternative is to just broadcast signal; and let the demand side react to the signal by selling some simple technology that responds to the signal in reasonably simple ways. That alone would enable substantial contributions from the demand side. But you can improve the incentive structure either thru regulation or by using statistical sampling to tell which customers have gotten with program; and then reduce their tariffs.

The amount of signal that needs to flow from the grid operators to the consumers is small, in the sense that you can broadcast it. A signal only needs to flow back the other way sufficient to assure that the incentives play out right. It is stupid to presume that the only incentives that are available are monetary or that they need to be executed with fastidious accounting. Most social systems have very fuzzy accounting and they work just fine, thank you!

The puzzle to be solved here is how to draw more of the peripheral demand into a load balancing system. Reading about EnerNoc’s approach isn’t the first time I’ve seen discussion of this. For example Bruce Schneier mentioned a regulatory attempt at something similar. I liked that one a lot, it provided a way to signal household thermostats. He was concerned that the resulting system would attract hackers. I presume he’d be just as sanguine about the security of the EnerNoc system; probably more so since it’s a closed system.

Such concerns are appropriate, but for heaven sakes I wish smart people like Bruce would stop pretending that these cases are somehow unique. It is the very rare large scale system that doesn’t have vunerable choke points. Hubs who’s failure can bring the entire system to it’s knees. Telling designers not to build large systems because of those risks is lame. Helping them know how to build them so they are safe and robust is hard, yes. But these systems get built because they generate mind boggling amounts of value. So it’s better to do the hard job and forgo the short term pleasure of a bit of hysteria.

Speaking of load shedding: turning your car’s engine off when you stop is more efficient than you thought.

Icons

Icons have a long history running thru hobo marks, trademarks, and of course the icons seen in Xerox, Lisa, and Mac software.  The image at right is from a beautiful collection of icons drawn by Gerd Arntz, though he adopted the term isotypes (International System of Typographic Picture Education) for his.  There is an venerable collection of tiny icons,  picons,  at the university of Indiana which were collected from contributions and, I assume, the x-face mime headers in usenet postings.  For example here is the one I used for years.  That collection is interesting since it includes icons for objects other than people, including websites.  Favicons might have leveraged picons.  But Microsoft, what can you do?

There are some fun hacks to generate arbitrary icons for a object; these mostly work by computing some value based on the object’s description (a hash say) and then using the digits you get to guide the generation of a drawing.  For example this number  a81e249865bc3d694fd0ab99e6e69f453213967e denotes a body of code stored in a repository.  We can map that into assorted icons as so:

Those examples are a wavatar, an identicon, a monsterid, a barcode, and a qr-code respectively, and if you poke around it’s not hard to find code and webservices that will generate these for you.

You can use these to put eye candy all over you user interface.  You could give every blog posting a icon, every blog, every user, every paragraph…  For example, it would be nice if the git browsers showed one of these along with the harder to recognize hash codes.  Obviously there is lots of fun to be had inventing additional icon generators.  For example it would be cool to have one that uses one of those plant growing  algorithms; that could then be used to create a series of icons effected by the deltas done to document or source code repository.  You could pluck  your object icons from a large collection of icons.  There are quite a few large public collections out there.  You could also pluck random bits out of larger photos or illustrations.

Icons are just another kind of metadata and there are some fun things that could be done, say with distributed hash tables, to create global repositories for iconic representations for URI.  Managing the rights to set these would be entertaining.

Gravatar & WordPress

My fresh WordPress upgrade now infected my blog with 3rd party content; how offensive.

One of the ‘features’ in WordPress now that folks who read my blog and leave comments get avatars.  Well the would, except I turned it off.  These avatars are injected into the page from a gravatars.com.  Gravatars is a divisiton of  Automattic, i.e. the WordPress company.

These avatars have assorted problems.  First off they let Automattic track my users.  Argh.  Secondly the design for gravatars makes only a slight effort to maintain the privacy of the users.  The avatars are indexed by taking the user’s email address and jumbling it.  So  ihavean@email.com becomes  3b3be63a4c2a439b013787725dfce802.  That’s bad.  It’s not particularly secure; with a good dictionary of email addresses you can recover the user’s email address.

That’s also a globally unique identifier for the user; enabling anybody with access to a good web crawl to find other places the same user has left comments.  Bleck.

The privacy policy at gravatars.com is joke.  Note how it doesn’t say anything about reselling the tracking information they are collecting to third parties.  WordPress hasn’t exactly been well behaved in the past.

 

Annoying Companies

via Tim Oren:

Now there’s an investing theory. Let’s have all the annoying companies buy each other.Comcast acquires Plaxo.

Acquisitions are easier if the two firms are entangled in similar ways; similar software platforms, similar open source licensing practices, similar unions, similar distribution channels, similar management fad.  No doubt, two firms with similar annoying  privacy  policies are a natural fit.