Ikea obeys local labor laws, how outrageous

The LA Times wrote an article that was later picked up by a bunch of blogs about an Ikea factory in Virginia that pays workers minimum wage, gives them minimal vacation and tries to prevent them unionizing.

Laborers in Swedwood plants in Sweden produce bookcases and tables similar to those manufactured in Danville. The big difference is that the Europeans enjoy a minimum wage of about $19 an hour and a government-mandated five weeks of paid vacation. Full-time employees in Danville start at $8 an hour with 12 vacation days — eight of them on dates determined by the company.

I find it somewhere between sad and funny that instead of arguing for improvements in US labor laws the LA Times and the usual left-libertarian blogs complain about a company maximizing profit within the legal constraints imposed by the society. If we want better working conditions we need to make it part of the political discourse, not just whine about companies following the law.

A Modest Proposal regarding littering and the homeless

In SFist I read that Scott Weiner, my district supervisor wants to give our San Francisco homeless brethren food stamps instead of cash when they bring bottles and cans in for recycling. I think he’s thinking about it all wrong. What we should do is deputize all of our homeless so that they can issue littering fines. Pay them a small percentage of the fine as a bounty. Give them cheap video recorders to collect the evidence. It would solve our littering enforcement problem and help address the poverty of some of the poorest members of our society.

My own URL shortener

So I guess the modern equivalent of the vanity email address is the vanity URL shortener. I registered ian.lc because it was available and cheapish and because bit.ly’s links keep getting longer and longer.

I tried both Google’s and Bit.ly’s BYO domain shorteners and didn’t like them at all. Google forces you to use a subdomain and Bit.ly uses the same namespace for all shortening domains, so all it really offered was vanity, not improved shortness.

After a couple of wisely aborted efforts to write my own I just installed YOURLS, a simple, straight-forward, extensible URL shortener. Like all useful internet software it’s all PHP and MySQL so it took virtually no time to deploy – unzip, create database, edit config file, reload.

There’s a pretty good WordPress plugin that shortens a link and then posts to twitter that I’m experimenting with as a way to encourage myself to make longer than 140 character posts. Let’s see how that goes.

HDCP’s real purpose

The recent leak or crack of the HDCP key has mostly been discussed in terms media piracy. There is already plenty of Blu-Ray piracy – nobody’s going to bother capturing raw HDMI traffic and re-encode it when they can easily buy a ripper. What this will do is make it possible for more small chinese manufacturers to get in on the HD television manufacturing game. HDCP provided a high barrier to entry for manufacturers so we haven’t seen the proliferation of TV manufacturers that we’ve seen in virtually every other kind of electronics. I expect that to change. I’m looking forward to buying sketchy HDTVs in chinatown super cheap.

The genetic inferiority of stupid people

Sharon sent me Jill Filipovic’s blog post about Stephanie Grace’s “racist email” that seems to be doing the rounds of the angry internet. First of all Stephanie Grace’s email was kind of racist. Not Arizona racist, but it definitely had a racist subtext. She doesn’t state that she believes that African Americans are genetically predisposed to be less intelligent than the rest of the US population, but by raising the suggestion she… raises the suggestion. It’s kind of like me pointing out that Glenn Beck has never provided evidence that he didn’t rape and murder a young girl in 1990.

Personally I think that it’s an entirely reasonable belief that more closely related groups (for example Americans whose ancestors largely originated in the Twi-speaking tribes of West Africa, or Americans whose ancestors originated from small towns in Scandinavia) will share physical traits. We’ve spent the past year travelling the world and people in different places look different. They have significantly different features, often adapted to their environment. If we connect the fact that genes can determine traits and closely related groups of people tend to share genes it’s obvious that closely related people tend to share some traits. I really don’t think that’s a racist concept.

What is racist is attaching moral value to traits associated with groups of people.

I don’t have any reason to believe African Americans are less intelligent than the rest of the population. Any difference in performance at school or income levels or incarceration rates are easily attributable to the class issues that Americans are so afraid of talking about. I think Stephanie Grace’s suggestion that their might be a genetic predisposition to lower than average intelligence among African Americans isn’t a particularly sound or even interesting suggestion, but she didn’t directly suggest that lower intelligence lowers the worth of individuals or groups. That all came from Jill Filipovic. It was Filipovic who used took a discussion of different traits and applied language like “genetically inferior”.

To equate intelligence with value (which is what Jill Filipovic does in her post) is where I have the problem. I’m happy to assume (as Filipovic does) that Stephanie Grace also equates intelligence with value or “superiority” but that’s not what the blog post was about. It was about arguing that intelligence is the key factor in determining the value of a person in society, and in the legal system in particular.

Antidepressants and the placebo effect

I’m starting to shift the content of the blog beyond simple technical issues. My use of LiveJournal has diminished as everyone elses’ has. I’ll keep posting personal stuff there but more general stuff will end up here.

By Flickr user ~!. Used under A CC license.

Over the past few years I’ve heard rumors of studies that showed a negligible difference between the effectiveness of antidepressants and placebos at treating depression. Now one of the main researchers looking at this, Irving Kirsch, has published a book, The Emperor’s New Drugs: Exploding the Antidepressant Myth, so there’s more press around the question.

While Mark Morford’s take on the issue in SFGate is (as usual) hilarious yet mildly insightful, the Newsweek article it references is where the really interesting information lies.

Basically Kirsch’s research shows that antidepressants have little better than placebo effect for depression (not anxiety, bi-polar or other disorders) in people with mild to moderate symptoms. He based these conclusions on the studies that the drug companies themselves conducted in order to have the drugs approved by the FDA. Initially he used the studies published by the drug companies, but then using freedom of information laws got access to the rest of the studies. Since FDA approval only requires two positive studies (from any number of unsuccessful studies) and statistically significant benefits over placebo treatments it’s fairly straightforward to run a lot of studies and choose the favorable ones when seeking approval.

“By and large,” says Kirsch, “the unpublished studies were those that had failed to show a significant benefit from taking the actual drug.”

In just over half of the published and unpublished studies, he and colleagues reported in 2002, the drug alleviated depression no better than a placebo. “And the extra benefit of antidepressants was even less than we saw when we analyzed only published studies,”

About 82 percent of the response to antidepressants—not the 75 percent he had calculated from examining only published studies—had also been achieved by a dummy pill.

That’s pretty terrible, especially since the frequently significant side effects of antidepressant medication can actually aid their placebo effect:

That matters because belief in the power of a medical treatment can be self-fulfilling (that’s the basis of the placebo effect). The patients who correctly guess that they’re getting the real drug therefore experience a stronger placebo effect than those who get the dummy pill, experience no side effects, and are therefore disappointed. That might account for antidepressants’ slight edge in effectiveness compared with a placebo, an edge that derives not from the drugs’ molecules but from the hopes and expectations that patients in studies feel when they figure out they’re receiving the real drug.

All of this flies in the face of the common understanding of how and why antidepressants work. Our amateur brain chemistry knowledge tells us that serotonin is the chemical that triggers happiness in the brain. Its receptors are what drugs like ecstasy, cocaine and speed target, and the popular SSRI family of antidepressants (such as Celexa, Prozac, Paxil and Zoloft) act to keep brain serotonin levels higher than they would otherwise be, “fixing the chemical imbalance”. But between research that dismisses those effects (and suggests other theories for the effectiveness of SSRIs) and evidence that SSREs (which reduce serotonin levels) are also effective as antidepressants it seems like the science to explain the actions of antidepressants is at best really weak.

The other side of this story is that antidepressants help people. I have plenty of friends who’ve had their lives significantly improved when they began taking antidepressant medication. Are they just getting a placebo effect? Does it matter if they are?

Well, the side effects of SSRIs can be fairly severe. And they’re quite expensive – Prozac is $12 per dose (or $1.40 in generic). But the problem with prescribing sugar pills is that they’re only effective when patients believe them to be an expensive, dangerous drug. I’d personally prefer for people with mild forms of depression to receive non-drug therapy initially (as the NHS in the UK now recommends). If 80% of patients aren’t getting a chemical effect, but a psychological (placebo) effect then we should be able to help them equivalently with other non-chemical methods like therapy. Of course, even at $12 a pill, using antidepressants for their placebo effect is probably cheaper than using trained therapists.

Go read the Newsweek article. It’s really good!

Travel Tips

The wife and I have been travelling for the past year or so on a fourteen month trip around the world. I was just reading Nat Friedman’s travel tips so I was inspired to add a few of my own more back-packer-y tips.

  1. For long trips use small bags within your luggage. We used Eagle Creek Pack-It Cubes. It makes it so much easier to keep your luggage organized as you move about. Repacking becomes a 30 second effort.
  2. For power bring a single adapter (I’ve been using a universal adapter similar to this one) and then a multi-adapter from your home country. I picked up a tiny triple adapter like this one. That way I can charge two computers and a phone with a single (often scarce) wall outlet and a single adapter.
  3. An unlocked GSM phone plus a cheap local SIM card is really handy if you’re going to be in  a country for more than a week or so. You can buy a low-end Nokia that can still browse the web (poorly, but enough to check your email) for about US$30. We put our temporary numbers on Facebook so that friends and family could call us, but mostly we needed phones to call ahead to hostels and locals. Also, if you’re used to paying for phone service in North America you’ll be pleasantly amazed by how cheap it is in much of the world.
  4. If you have to pay for wifi, but have two computers then an ethernet cable plus internet sharing halves your costs. NetworkManager does the internet sharing stuff trivially, I’ve rarely gotten it to work through Windows and MacOS though.
  5. AirCrack-NG is your friend. Learn its quirks. Use it wisely. The documentation that comes in the Debian / Ubuntu package probably isn’t quite enough to get it working so you should practice somewhere where you already have access to the Internet.
  6. A travel clothesline can be invaluable in extending the length of your wardrobe. Pick up some hand laundry soap and you’ll be able to wash shirts, socks and underwear pretty easily. We found larger things like jeans harder to wash in hostel sinks, but if you can visit a laundromat a couple of time a month and wash the rest of your stuff a couple of times a week in your hotel or hostel you’ll have more time and money for fun while not turning into a completely stinky hippie.

Detecting advanced CSS features

I decided to do some fancy typography in my résumé, but I wanted to have a sane fallback for browsers that don’t support the latest features. I have my name rotated 90 degrees using CSS3 transforms, but simply applying the transform: rotate(-90deg) CSS property isn’t enough to get the effect I want. To make it look right I also need to measure the text (since its dimensions will change depending on the viewer’s fonts) and absolutely position it based on that. Standard CSS fallback (where unrecognized rules are ignored) doesn’t give a good result. At all.

After a bunch of fiddling and cross-browser testing I found that testing the existence (!==undefined) of properties on element.style worked well. So I put all of my rotation rules in a CSS class that’s applied only if the style properties exist.

<style type="text/css">
  h1.rotated {
    -webkit-transform-origin: left bottom;
    -moz-transform-origin: left bottom;
    -o-transform-origin: left bottom;
    transform-origin: left bottom;

    -webkit-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    transform: rotate(-90deg);

    position: absolute;
    left: 0px;
    top: 0px;
    margin-top: 16px;
  }
</style>
<script type="text/javascript">
    // rotate the title, if that's even possible
    var h1 = document.getElementsByTagName('h1')[0];
    var s = document.body.style;

    // test for the presence of CSS3 transform properties
    if (s.transform !== undefined ||
        s.WebkitTransform !== undefined ||
        s.MozTransform !== undefined ||
        s.OTransform !== undefined) {
      // move
      h1.setAttribute('style',
          'top:' + ( h1.offsetWidth - h1.offsetHeight) + 'px');
      // and rotate
      h1.setAttribute('class', 'rotated');
    }
</script>

Of course, if I could just check for transform: support rather than -webkit-transform:, -moz-transform: and -o-transform: but we’re not there yet. Anyway, based on browsershots.org it seems to do the right thing on every known browser. It shows rotated text in very recent Webkit and Gecko browsers, and in Opera nightlies, and unrotated, correctly text everywhere else.

Implementing Information Retrieval Systems

I believe that it’s valuable to implement software components that you use from scratch merely to gain a better understanding of the systems you use. I’ve never implemented an operating system from scratch or designed and implemented a programming language like many of my friends but I’d really like to one day. Part of the problem is that looking at a large, complicated, system from the outside is intimidating.

A couple of years ago I spent many months working with CLucene, the C++ port of the Lucene IR (full text search). Both CLucene and Lucene are huge, complicated and often appear to be buggy. While learning about the Lucenes I did a bunch of reading about full text search theory. It never seemed that complicated, but all of the implementations I came across clearly were.

A basic full text search engine works like this:

  • collect all of the words in the input documents
  • simplify the words so that similar ones are the same, so I can search for “look” and get “looked”, “looking” and “looker”
  • organize the words in a special tree data structure called a trie that lets you look up the words in linear time, the leaves of the trie for each word indicate which documents it’s present in
  • to search for a word you walk the trie and get the list of documents

Yesterday I spent a couple of hours walking (Tel Aviv public transport was failing me) and I worked through most of how to implement this in my head. I also thought about how to implement phrase matching. I’m not really sure how phrase matching works in other systems (like I said, they’re too complicated for me to understand easily) but I represent each instance of a word in a document and then link from one instance to the instance of the next word in the document. That way after walking down the trie to find the first word in the phrase I can walk along each word in the phrase, comparing it to the next word in the document.

Last night I implemented it in Python. I called it Tripe and it’s less than 250 lines of Python. It doesn’t have a stemmer worth talking about and it’s pretty space inefficient but it seems to generally work. There’s a library file called tripe.py and then some test utilities: tripe_add.py (add documents), tripe_search.py (search the index), tripe_dot.py (visualize the index with Graphviz). Take a look:

% echo "The cat sat on the mat." | ./tripe_add.py test.tripe 1
% ./tripe_dot.py test.tripe|dot -Tpng -o test1.png

% echo "The quick brown fox..." | ./tripe_add.py test.tripe 2
% ./tripe_dot.py test.tripe|dot -Tpng -o test2.png

% echo "There is a light that never goes out." | ./tripe_add.py test.tripe 3
% ./tripe_dot.py test.tripe|dot -Tpng -o test3.png

% ./tripe_search.py test.tripe the
matched in document 1 at 15
matched in document 1 at 0
matched in document 2 at 0
% ./tripe_search.py test.tripe cat
matched in document 1 at 4

I first implemented this as a tree in memory, but I found that implementing persistent storage was really easy too. I’ve always been hesitant to implement structured binary file formats, and I know that efficient implementation can be really complicated, but a naive implementation like I did was relatively straight-forward.

So now what? There are already a bunch of full-text search engines out there, but they all seem relatively complicated. I wonder if it’s worth tidying up what I have, extending it enough to be useful for site search applications and publishing it. In the meantime it’s on github.

Flipy, a new Python library for Flickr

In the past day or so I’ve written a new Python library for Flickr. It came from some frustration using other Python libraries. They’re all great, but none of them work quite how I want.

My goal was to have a library that feels like Python and the Flickr API at the same time. I think it’s worked out pretty well so far. You can make calls using the standard Flickr API calls as documented on the Flickr site, but the response objects feel like normal Python objects. For example you can do something like this:

from flipy import Flipy
flickr = Flipy(MY_API_KEY)
me = flickr.people.findByUsername(username='ianloic')
me_info = flickr.people.getInfo(user_id=me.nsid)
print 'My name is %s. I have %s photos at %s.' % (me_info.realname, me_info.photos.count, me_info.photosurl)

I’ve put more details about the mapping in the README.

Beyond simple mapping of methods to responses I’m working on decorating certain important response objects such as users and photos with more object oriented methods. For example right now if you have a user object you can call user.photos() and get a iterator for of a user’s photos. My code takes care of all of the paging behind the scenes.

Since I haven’t implemented authentication or uploading yet so right now it’s mostly useful for simple mashup-style applications, but I’ll get uploads and authentication complete when I get back from Jordan next week.

Check out the code on github and let me know what you think.