Elliott C. Back: In Aere Aedificare

Shure E4c-n / SE420 Review

Posted in Music, iPod, iPod Shuffle, Hardware, iPhone by Elliott Back on February 19th, 2008.

I bought a pair of Shure E4c-n earphones about 6 months ago from Amazon, and I have to say they are the best I’ve ever owned. They have a 4/5 star review on Amazon with 50 reviews; their newer cousin the SE420 has similar reviews. Here’s what they look like:

shure-e4c-n.jpg

The sound isolation is orders better than any other headphones I’ve tried, and the frequency response is excellent. My coworkers, two of whom bought similar or identical Shure earphones, also swear by them. You can be sitting on the worst part of the NYC subway line with them on, and not hear the pain of the wheels screeching on ill fitted metal tracks.

A reviewer on Amazon praises the sound quality better than I can:

These IEMs sound absolutely incredible. They sound is so clear and detailed that I notice new details in songs that I had listened to dozens if not hundreds of time. In a complex musical passage it is easy to follow every note of a single instrument which is not an easy feat with most headphones.

As for Customer Service, it’s the best. My earphones started wearing out in 6 months at the cord junction where it meets the plug, and they are sending me an advance replacement (against my CC) of the SE420s. When I get them I’ll send back the defectives to the Customer rep who took my warranty replacement and they’ll reverse the charge. Another customer had a similar, great experience:

As for Shure customer service–I had a suspected loose wire in one of the E3 earphones (used for 8 months) leading to dropouts when I would move my head. I got a return form off the Shure website–filled it out and sent it along with a copy of my receipt to Shure. Within 10 days, they had sent out a completely new pair at no charge.

Even Apple doesn’t offer this level of personalized customer service. I’m extremely impressed, and with their 2 year warranty, I’ll definitely buy again!

Plane on a Conveyor Belt Interview Question

Posted in Science, Airplane by Elliott Back on February 9th, 2008.

I saw this physics interview question pop up on the internet, and thought it might be worth discussing:

A plane is standing on a runway that can move (some sort of band conveyer). The plane moves in one direction, while the conveyer moves in the opposite direction. This conveyer has a control system that tracks the plane speed and tunes the speed of the conveyer to be exactly the same (but in the opposite direction). Can the plane take off?

plane.jpg

There are a number of forces here that apply: gravity, the force of the engines / airspeed / lift, and the drag of the wheels against the conveyor / the speed of conveyor. However, the wheels provide essentially a frictionless boundary between plane and ground; unlike car wheels, the wheels of an airplane spin freely in place. So, as the conveyor belt speeds up, the airplane stays in place, but its wheels spin at the same velocity. Furthermore, the lift of the airplane is relative to its airspeed, and its engines push against air. So, the airplane will accelerate forward and take off as normal.

The commenter “Max” has a nice summary as well: “A comparable example in my mind would be a car on a treadmill. If the car is being pulled along by a winch and the wheels are turning freely then the car is going to be pulled at an identical rate whether or not the treadmill is there or not (assuming as you did that the treadmill’s speed is inverse to that of the car).”

Smoking

Posted in Me by Elliott Back on February 4th, 2008.

So the tenant downstairs is smoking. The smoke wafts up a ventilation duct from his bathroom and into mine. Making my room smoking. Now, I love a good smoke like the next man, but when smoke comes uninvited, I get annoyed. So I went down to ask him to stop, knocked on the door, heard the tv and him get up, come to the door, and then … nothing. I kept knocking for a while, but you can’t fight passive aggressive, so I left. My game plan is to:

  • Come back randomly until I get ahold of them
  • Rat them out to the landlady
  • Get an anti smoking injunction

Fortunately, the “no smoking” thing is in my lease, so if they don’t stop / aren’t force to stop, I can just recover my deposit and leave, since my lease has been breached.

How many users does DIGG have?

Posted in Blogging, Science, Web 2.0, Scalability, Quantitative by Elliott Back on February 3rd, 2008.

When John Graham-Cumming asked the question How Many Users Does Digg Have?, there were a few things he couldn’t tell you, since his data consisted of randomly self-sampled users. Well, with the power of two PHP scripts, we can pull large amounts of user data and form queries. Our first question is how has DIGG grown over time?

digg-users-over-time.png
A graph of 187,054 digg users, randomly plotted against when they joined

This doesn’t tell us much, though, about how many DIGG users there actually are, or how active they are, so I plotted a histogram of the number of times these 200k users’ profiles had been viewed; the answer, unsurprisingly, is not very often in most cases:

digg-profile-views-histogram.png
83% of users had less than 50 profile views

And what about users who are active? How many people are digging stories every day? The answer is very few. I took a sample of 29,225 users from the previous sample (randomly) and used the DIGG API to query for their last digg. It turns out 31% (9125) had never dugg anything! After I removed those, here is the histogram I got:

digg-last-dugg.png
About 15% of Digg users dugg a story in the last week

Concluding thoughts

Digg boasts an official tally of 2.2M users, but at most 20% of them can be considered real, active users. That would bring their user count down to 440,000, far far less than a popular web 2.0 boom child can boast about, and significantly hurting that $300M (or ~$700 a user) valuation that they keep trying to get.

Code Appendix

The {digg user, time joined, digg id, profile page views} information was gathered by the following script:

<?php
    error_reporting
(E_ALL);
    
ini_set(‘user_agent’‘My-Application/2.5′);
    
ini_set(“include_path”“.:/usr/share/pear”);
    require_once 
‘Services/Digg.php’;
    require_once 
‘Services/Digg/Response/php.php’;

    $base ‘http://services.digg.com/users/?appkey=http://example.com&type=php’;
    
$data unserialize(file_get_contents($base.‘&count=0′));
    
    
$total $data->total;
    echo 
“There are $total total users\n”;
    echo 
“ID,Number,Name,Date,Views\n”;

    for($i 0$i 1000$i++){
        
$offset rand(0$total 100);
        
$data unserialize(@file_get_contents($base.‘&count=100&offset=’.$offset));

        $j 0;
        foreach(
$data->users as $user){
            
$page = @file_get_contents(‘http://digg.com/users/’.$user->name.‘/’);

            if(!$page)
                continue;

            preg_match(‘/id=”userid” value=”(\d+)”/i’$page$matches);
            echo 
$matches[1] . “,”;
            echo (
$offset $j++) . “,”
            echo 
$user->name “,”;
            echo 
$user->registered “,”;
            echo 
$user->profileviews .“\n”;
        }
    }
?>

Java Memory Leaks w/ Finalize Examples

Posted in Code, Java by Elliott Back on February 3rd, 2008.

Most people think Java cannot leak memory, but actually that’s not true. Java, unlike languages such as C or Javascript, can have two kinds of memory leaks:

  • True leaks - unreferenced, unrecoverable segments of memory
  • Soft leaks - memory that could be garbage collected, but is “accidentally” referenced

The first kind of memory leak, the true leak, is common to C. It’s trivially easy to write a C program which leaks memory like a sieve by simple putting a call to malloc(…) inside a tight loop. This creates unbounded amounts of heap memory and eventually runs out of space. Additionally, the memory is lost if you don’t save a pointer to it. However, the same program in Java will not run out of memory:

public class finalizer {
  public static void main(String[] args) {
    while (true) {
      finalizer f = new finalizer();
      System.out.println("" + Runtime.getRuntime().freeMemory() + " bytes free!");
    }
  }
}

The output looks similar to this:

15757280 bytes free!
15965176 bytes free!
16274928 bytes free!
16584368 bytes free!
15770768 bytes free!

As you can see, since the object we create are unreferenced, the garbage collector can clean them up. Circular references are also no problem for the Java garbage collector, which uses a generational mark-and-sweep algorithm, as demonstrated by this example:

import java.util.LinkedList;
import java.util.List;
 
public class finalizer {
  protected Object ref;
  
  public finalizer(Object ref){
    this.ref = ref;
  }
  
  public static void main(String[] args) {
    while (true) {
      List x = new LinkedList();
      
      for (int i = 0; i < 100000; i++) {
        x.add(new finalizer(x));
      }
      
      x = null;
 
      System.out.println("" + Runtime.getRuntime().freeMemory() + " bytes free!");
    }
  }
}

This creates a linked list in which every element also contains a reference to the list, then blows away the scope of the list entirely by dereferencing x and moving into a new loop scope. This leaves all the elements we just allocated floating in memory and all pointing at each other, but not pointed to by our active memory graph. The output shows that this memory is reclaimed:

12601488 bytes free!
8597784 bytes free!
4584656 bytes free!
12596808 bytes free!

Unfortunately, though, there is a way to create true memory leaks in java, and that is with a poor implementation of the finalize method, which is described in the Java 6 docs as:

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized.

The finalize method exists on every Object and is called by the garbage collector’s thread before it reclaims that memory. So, the simplest thing we can do to prevent the garbage collector from reclaiming it is to yield execution:

public class finalizer {
  @Override
  protected void finalize() throws Throwable {
    while (true) {
      Thread.yield();
    }
  }
 
  public static void main(String[] args) {
    while (true) {
      for (int i = 0; i < 100000; i++) {
        finalizer f = new finalizer();
      }
 
      System.out.println("" + Runtime.getRuntime().freeMemory()
          + " bytes free!");
    }
  }
}

This produces a quick memory leak and Out of Memory Exception:

12591736 bytes free!
8599816 bytes free!
4584576 bytes free!
602496 bytes free!
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Throwing any kind of Exception or Error from finalize() also prevents the garbage collector from reclaiming the memory:

public class finalizer {
  @Override
  protected void finalize() throws Throwable {
    throw new Exception("x");
  }
 
  public static void main(String[] args) {
    while (true) {
      for (int i = 0; i < 100000; i++)
        new finalizer();
 
      System.out.println("" + Runtime.getRuntime().freeMemory()
          + " bytes free!");
    }
  }
}

12380920 bytes free!
8687296 bytes free!
5608880 bytes free!
1796496 bytes free!
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Abuse of the Object.finalize(…) contract is the only way I know of in pure Java to create a true memory leak. If you widen the scope to include JNI (Java Native Interface), you can bind to an object which leaks memory in native code, but inside the process space of your Java application.

« Previous Page