Thinking

My mind works in strange ways sometimes. Read and think about each of the following statements:

  • I was cooking a pizza in the oven at 250 degrees, but I was in a big hurry, so I doubled the temperature to 500 degrees.
  • I miss the summer days when it was 80 degrees, and, over night, the temperature would be halved to 40 degrees.
  • It was ten degrees the other morning, and tripled to thirty by noon.
  • It was 0.1 the morning before that, and had risen three-hundred times to 30 degrees by noon.
  • It was -1 before I woke up that morning, so it was -30 times as warm by noon.

To me, it makes progressively less and less sense. But I’m trying to think of why. It’s clearly asymptotic at 0 degrees: if it’s exactly 0 degrees and grows to 0.1 degrees, it’s “infinitely warmer.” Of course, most people wouldn’t notice the tenth of a degree increase, and my concept of “infinitely warmer” is something significantly warmer than 0.1. And it doesn’t make any sense when you go into negatives. I think another part of the problem is that “zero” degrees doesn’t mean “zero warmth,” since it doesn’t make sense to have a negative amount of warmth. (Assuming that “no warmth” isn’t neutral, but is absolute zero.) Of course, Fahrenheit and Celsius don’t even grow at the same rate, compounding things further.

YouTube

One of the many things I try to shy away from is making generalizations. They’re often harmful and downright inaccurate.

But one generalization I do feel comfortable making is that the comments on YouTube are among the worst I’ve ever seen. Even the few that are coherent tend to contain egregious grammar problems. I’m not talking about a missing comma. im talkin about like riteing like this i mean its so dummm why do they do this its like their never lurnd 2 right

Those are the good ones. The bad ones are offensive, pointless (“i like this video so much1!111”), or just downright bizarre. (In the video to one of my favorite songs, you barely see The Killers at all, yet someone left a comment that they love videos like this one where you can see the band playing the whole time.)

I want to know why this is the case. There are some sites (Digg, Slashdot) where there are some dumb comments. But YouTube is notoriously bad. Hilariously so. Except it’s gone way past hilarious, to the point of being irritating and kind of depressing. Is it a demographic thing? Is it swamped by 13-year-olds? (With apologies to 13-year-olds, who probably far exceed the average commenter on YouTube.) Is it a broken windows type thing, where people leave stupid comments because everyone else does?

YouTube recently implemented a rating system, where you can give a thumbs-up or thumbs-down to comments. Good idea. Except it really doesn’t work! For one, they made my classic mistake, but in reverse: they clearly never tested in Firefox (well, Flock or Firefox 3, but Flock is basically Firefox with some more addons and a fancy theme). But that’s not my point. A comment might voted up or down a couple points, but that’s all. There’s no suppression of comments, and the comments remain in chronological order, so comment moderation is pretty pointless.

9/11

While I don’t believe Rudy is going to make it far in the campaign, and while I really don’t like the attack ad element of politics, I’m frankly pretty appalled with Rudy Giuliani. I think it’s immoral to try to use 9/11 to your advantage. But Rudy’s use seems particularly insidious. He keeps suggesting that we need to vote for him if we want to be safe from terrorists. Besides the fact that his is creepy fear-mongering, what bothers me most is that there’s an unspoken (in this ad) implication that his leadership on 9/11 is what qualifies him.

It was a really crass comment, but a political commentator someone said something to the effect of, “Giuliani is an expert on terrorism just like the mayor of New Orleans is an expert on flood prevention.” While it maybe goes a bit too far, the point remains the same: what, precisely, about 9/11 makes him a qualified leader?

The IAFF (firefighter’s union) asking the same question. And if there’s anyone people respect because of 9/11, it’s FDNY. The IAFF essentially blasts Rudy for mis-handling things. One big problem I’d forgotten all about was the radio failures. They knew since the 90’s that their radios didn’t work inside the WTC, but repeated attempts to get it fixed never occurred. (They mention an “upgrade” that was actually so bad that they went back to their old radios, which is what they used on 9/11.) Tragically, more than 100 firefighters, because of these communication failures, never got the signal to evacuate WTC and ended up losing their lives because of it.

Some have also criticized Rudy for his decision to locate much of the city’s emergency communications infrastructure in the World Trade Center. Even if his common sense / expertise on terrorism didn’t tell him that this was an intuitively bad idea, previous attempts by al Queda to blow it up might have.

And if you’re not offended enough, give this a watch. I keep wanting to believe that this is a farce, with a look-alike mocking him. Except that all indications are that this is real. A Parkinson’s victim calls into a program Rudy’s doing on the radio to ask him why he took his food stamps and Medicaid away. Rudy cracks up laughing, mocks him, and offers to send him psychiatric help “because [he] clearly need it.” While Rudy surely didn’t know he was mocking a Parkinson’s victim, why would he treat anyone that way?!

Moral of the story: if you’re going to try to exploit 9/11 to win an election, you’d better make sure your botched leadership didn’t kill our firefighters. And you might want to refrain from going on public radio and cracking up laughing, and subsequently mocking, people who call in to say they have Parkinson’s and can’t afford their medication. But that’s just my opinion. I’m no political consultant or anything.

Update: For those that don’t read the comments, you should at least check out the link in this one for more of Rudy’s radio program.

Geekostat

Disclaimer: I can tell right now that this is one of those late-night posts where I should be sleeping, not posting about a technical topic. But these not-entirely-lucid ones are sometimes the most fun to read.

I consider myself extremely tech-savvy. I can build a computer from parts, make my own Ethernet cables, run some performance tuning on interactive websites, write applications in numerous programming languages (as well as SQL and HTML), and much more.

But I still don’t get our digital thermostat. They’re programmed to go down to 58 at night, come up to 67 on weekends and from something like 6 to 9 a.m., and 3 to 9 p.m. on weekdays. In other words, when people are home.

Of course, me being home on vacation isn’t quite compatible with this. There’s a simple override, where you can hit the up or down arrows to set it to a temperature. While I use (and appreciate!) this, it’s also a pain. It’s really no fun waking up and having it be 58. I’d really like to reprogram it to automatically come up to 63 or so around 10:30.

I still don’t get why the whole thing isn’t on the LAN. This would have two obvious benefits right out of the gate–it’d be much easier to configure (even if you let someone with no clue about usability design the GUI, it’ll be better than the myriad knobs, switches, and buttons on our thermostat!), and it’d be more convenient in many cases to pull up a new tab in your web browser than to walk down the hall to the thermostat. (Plus, the thermostat is in my parents’ bedroom. I’d have loved to have turned the heat up a few degrees around 11 tonight, since it’s 9 outside and almost as cold inside. But something tells me they really wouldn’t have appreciated it.)

I’m also not sure that the ‘simple’ thermostat algorithm is that efficient. You figure it works something like:

while(1) { $temp = getTemperature(); $desired = readDial(); if($temp<$desired) furnace.enable; if($temp>$desired) furnace.disable; }

When we view it at ‘computer speed,’ I think we can see one of the basic problems: in theory, the furnace could start flapping, where on one loop iteration it turns the furnace on, and just a fraction of a second later, it turns it off. I don’t profess to know a lot about the overhead in starting a furnace, but I’d imagine that it’s most efficient to let it run for a few minutes.

I think a much better system would be to have a programmed minimum run time: if the furnace is turned on, we should run it for at least 5 minutes. After 5 minutes, we again evaluate the temperature: if it’s at the target, we turn it off. If not, we drop into a quicker polling, maybe once every minute. Incidentally, this is much better for the thermostat’s processor, but if its sole purpose is determining whether to turn something on or off, no one really cares about minimizing overhead.

So you give it a secondary purpose: handling a TCP/IP stack and a basic webserver! All of a sudden, instead of an infinite loop, you run a tiny bit of code every 30 seconds.

You can also generate some interesting statistics. For example, how long does the furnace need to run to raise the temperature one degree? How does this scale–if you want to raise it three degrees, does it take three times as long? How does the temperature of my house look when graphed across a day? How about telling me how long the furnace ran yesterday? And, given information about my furnace’s oil consumption and our fuel costs, it’d be cool to see how much it’s costing. And it could give us suggestions: “If you drop the temperature from 68 to 67, you’ll save $13.50 a month,” or such. This would require some storage, but a gig of solid-state media (e.g., a camera’s SD or CF card) is around $10-20 now. Plus, with the advent of AJAX, you can push some of the processing off to the client–let the client use a Flash applet or some good Javascript to draw the graphs if the thermostat is underpowered!

In conclusion, I’m freezing.

Advice

I learned two valuable lessons today:

  • Don’t ever create a 500GB FAT partition. No matter how good of an idea it seems, don’t do it. (Not terribly different is the advice, “Don’t ever create one big 500GB partition.”)
  • Mounting a filesystem as “msdos” is not the same as mounting it as “vfat” in Linux. msdos is still constrained by the 8.3 naming system. vfat is not. Unless the disk was literally written with MS DOS, don’t use msdos. It’ll work okay, but boy are you screwing yourself if you make backups with it mounted as msdos. (Fortunately, I realized this before wiping the drive.)

Qqueue!

So I’m a huge fan of Ask Metafilter. The basic premise is simple: you ask a question and lots of people answer. But Ask MeFi rocks because they maintain high standards. So you actually get really good answers. It costs $5 to join, which is done to pay for the servers but, frankly, seems like a good way for keeping crap out, too.  You’re allowed one question a week, so I try to make it good. But oftentimes, I put it off for several weeks for want of something worthy of using up my question.

So I started a list. And I figured I’d allowed voting and comments. And before I knew it, I had this monstrosity. It was actually extraordinarily simple to code, too. I hope to add better questions over time: these are the ones that were on my mind at the time. You can vote (the + and – buttons), and leave comments. Feel free to do so. (I’m not taking question ideas: get your own account if that’s what you want!)

Coding Malpractice

I just wrote the following line of code. And it’s no mistake: it functions perfectly and does exactly what I wanted it to do:

$count += 0;

This is surely poor programming practice, essentially implicitly recasting a variable as an integer. But it’s simple and it works flawlessly. (The context: I run an SQL query saying SELECT SUM(votes)..., which makes the tabulation of all the entries MySQL’s problem, not mine. The one ‘flaw’ is that the sum of no votes isn’t 0, but NULL. This becomes a very important distinction when you’re trying to display a number: “0 votes” isn’t the same as ” votes.”)

Since we all know that NULL + 0 = 0 (and, of course, integer + 0 = integer), adding 0 works flawlessly. Could I just convert it to an integer? Probably. But I haven’t done that stuff in a while, and I was far too lazy to pull up the documentation. And incrementing a variable by 0 is way more fun.

Subtly Bad Code

Alright, let’s have a little fun… I just added a new blog and went to include it on the main page, but my code failed citing the database throwing errors. It took me forever to find. I’m curious if others can find it.

I was further confused because the code worked fine until I added the new blog to the list of ones for it to use, and it was specifically built so that it wouldn’t matter how many blogs there were. It has a separate file that just lists blogs to include, and reads that file at runtime and builds a query to retrieve posts from all of them.

You need some background, first… All the posts are stored in a database, so each has its own table. I built this monster query, basically looking something like (Get most recent posts from blog 1) UNION (Get more recent posts from blog 2) UNION (…3…), and then tack an “ORDER BY…” onto the end. Credit for this idea goes to Andrew; I’d have never thought of it myself.

What the list includes is blog IDs in the database. They ranged from 2 to 9, skipping 8 (which isn’t used). After a bout of spam registrations, the numbers got run up, so when I included the new one, it was numbered 51.

The below code (in PHP) calls some custom-rolled functions, but I’ll just say up front that the error does not depend on understanding how they work. Similarly, the answer does not have to do with caching in any way, so don’t get too hung up on the amount of code devoted to working with the cache. (And finally, I’m building one huge variable called $query the whole time, and then return that variable… This isn’t a crucial thing to understand either, I just wanted to explain it since it’s somewhat of a bizarre practice. .= is the PHP variable concatenation method.)

// $count is the number of blogs to pull out
function genRPQuery($count) {
  // Retrieve it from Memcache
  $query = getCachedObject("bigquery-$count");
  // It'll return NULL if it doesn't exist, so we check for that...
  if($query) return $query;

    // Since we're here, we didn't return, and
    // thus didn't get it out of the cache

    // Next two lines read in the files. blogList()
    // returns a list of the blogs -- it's little more than a
    // file read with caching enabled.
    $blogs = explode(',', rtrim(blogList(),"n"));
    $fields = rtrim(cachedFile('./fields.inc',30), "n");

    foreach ($blogs as $i) {
      // We have a loop for each blog
      // For unfamiliar eyes, .= is PHP's means of variable concatenation
      // We're building a ridiculously-long query, each one a SELECT, encased in
      // parens, and we UNION them all together...
      $query .= "(SELECT $fields FROM wp_" . $i . "_posts WHERE post_status='publish' AND post_type='post' AND post_password='' ORDER BY post_date DESC LIMIT $count)n";
      // If we're not on the last one, insert a "UNION" in (see above)
      if($i

Remember, it worked fine when the list was blogs number "2,3,4,5,6,7,9" but the simple change to "2,3,4,5,6,7,9,51" causes it to blow up and try run a query with invalid syntax. This made no sense to me, since the code was built to not care about things like that. I eventually found it, and feel like an idiot.

I've posted a hint in the comments... It's in the interest of fairness because I turned on some debugging and got the information I share. But it also really narrows your attention to a couple of lines, so I don't want to include it in the main post.

Spam

My e-mail setup right now for n1zyy.com and ttwagner.com consists of just forwarding all e-mail to GMail. It works fine, and the spam filters there have been pretty much 100% effective. However, it bothers me that I’m forwarding dozens, if not hundreds, of e-mails just to have them ignored. Some basic spam filtering should really take place on my server.

I made a few basic configuration changes to Postfix, the MTA I run. In a nutshell, I tell it to require stricter compliance with e-mail RFCs: e-mails with HELO addresses that don’t exist (or just don’t make sense), and people sending multiple commands before the server replies to acknowledge them, for example, now results in mail delivery failing. The default configuration errs very much on the side of ‘safety’ in accepting mail, but the trick is to tighten it down enough that you’ll reject mail that’s egregious spam, but not reject anything that could be from a mailserver. And that’s where I’m at.

I also installed SpamAssassin. I’m currently using it in conjunction with procmail, and therefore wasn’t quite sure if it works. I set it up to make some changes to the headers, so that I can verify whether it’s working. But I ran into a problem I never thought I’d have: I’m not getting enough spam. I’m sitting here eagerly awaiting some to see what happens. And it’s just not coming.