Archive for category General

Ground control to major Tom


This could be you!

Who hasn’t dreamed of becoming an astronaut? Well, now you can. The NASA has an open position for an “Astronaut Candidate” for the International Space Station in Houston, TX. The requirements are pretty interesting.

The training will take two to three years and will require a lot of traveling, probably mostly to Russia, since they will be using Soyuz to travel to and from the ISS. The required education is fairly broad, and more interestingly, the list of degrees that are not applicable is fairly short (technology, psychology, nursing(!), etc…). It looks like a CS degree is good enough, and you can make up for the lack of flying experience with an MS or better, a PhD.

“Correctable” 20/20 eyesight is required, which means that contact lenses and Lasik are accepted (I wonder how hard it is to put contact lenses on in zero gravity…). The ad also takes the time to explain each jargon occurrence: “Extravehicular Activities (space walks)”, “the extravehicular activity mobility unit (space suit)”.

Although the ad will only be open for the next couple of months, the selection process takes a while since the selection will be announced in the spring of 2013.

I was fortunate to be able to experience a Zero-G flight a few years ago, I can’t say I’m not tempted to apply :-)

Table of contents in Javascript

This is my week end project: a table of contents generator. Well, technically, it’s more like a two hour project interrupted four times over the course of a Saturday but I guess it still qualifies as a week end project.

I got tired of managing the table of contents of my documentations manually and in particular, of having to modify all the section numbers by hand whenever I moved things around. This short Javascript program now automatically takes care of it for me. Here is the quick documentation:

// A simple HTML "table of contents" generator.
//
// 1) Include toc.js in your HTML file:
//          <script type="text/javascript" src="toc.js"></script>
//
// 2) Call generateToc() in your onLoad() method:
//           <body onLoad="generateToc();">
//
// 3) Declare a div with the id "table-of-contents" where you want
// your table of contents:
//           <div id="table-of-contents"></div>
//
// 4) Put each of your sections in an <a> tag with class "section",
// specifying an "indent" representing the indentation of that section.
// Only the length of the indent matters, now its content. If no indent
// is found, a string of size 1 is the default.
//
// Example:
// <a class="section" name="Section 1">Section 1</a>
// <a class="section" indent=".." name="Section 1a">Section 1a</a>
// <a class="section" name="Section 2">Section 2</a>

This script now powers both testng.org and jcommander.org, go take a look there if you want to see what it looks like.

Ideas for potential improvements:

  • Make the numbering optional or configurable.
  • Have the script add CSS classes to the sections for easier styling (“section1″, “section2″, etc…), since the indenting is pretty crude right now.

JCommander 1.20

I just released JCommander 1.20. The main new feature is “parameter delegates”:

Parameter delegates

If you are writing many different tools in the same project, you will probably find that most of these tools can share configurations. While you can use inheritance with your objects to avoid repeating this code, the restriction to single inheritance of implementation might limit your flexibility. To address this problem, JCommander supports parameter delegates.

When JCommander encounters an object annotated with @ParameterDelegate in one of your objects, it acts as if this object had been added as a description object itself:

class Delegate {
  @Parameter(names = "-port")
  public int port;
}

class MainParams {
  @Parameter(names = "-v")
  public boolean verbose;

  @ParametersDelegate
  public Delegate delegate = new Delegate();
}

The example above specifies a delegate parameter Delegate which is then referenced in MainParams. You only need to add a MainParams object to your JCommander configuration in order to use the delegate:

MainParams p = new MainParams();
new JCommander(p).parse("-v", "-port", "1234");
Assert.assertTrue(p.isVerbose);
Assert.assertEquals(p.delegate.port, 1234);

Change log for 1.20

  • Added: Support for delegating parameter definitions to child classes (rodionmoiseev)
  • Added: @Parameter(commandNames) so that command names can be specified with annotations
  • Added: Support for enums (Adrian Muraru)
  • Fixed: Throw if an unknown option is found
  • Fixed: Main parameters are now validated as well (Connor Mullen)

  • Doom 3 source code

    Browsing the source code of Doom 3 comforts me in my belief that I’m simply not cut out for graphic programming.

    The new Google Reader

    Count me as one more Google Reader faithful user who really doesn’t like the new look.

    Google, don’t make the mistake of dismissing all the criticism as “They’re complaining because it’s different, they’ll get used to it, we just to wait them out” and take the time to ponder the new look.

    It’s basically black and white, with a lot (a lot) of empty space and a selection that turns the foreground (yes, the foreground, and the foreground only) of the font to red:

    I mean, the whole page seems to be using five colors total. Surely it’s possible to make a better use of colors without going all psychedelic on us?

    Any default theme of WordPress looks ten times better than Reader right now.

    Come on, Google, you can do better than this.

    A new coding challenge

    It’s been a while since I offered a coding challenge, so let’s remedy this.

    This one comes from this week’s Car Talk’s puzzler. Here is the short version of it:

    A farmer has a forty pound stone that he uses to weigh food for his animals on a scale. One day, he loans the stone to his neighbor. A few days later, the neighbor returns the stone and apologizes to the farmer because his stone is now broken in four pieces. The farmer responds “Please don’t apologize, you have actually made my life easier because with these four pieces, I can now measure any weight between one and forty pounds”.

    The question is: how much do these four individual pieces weigh?

    I’m adding a few clarifications, which are not necessarily what the Car Talk guys meant (I don’t have the solution and I haven’t looked at any discussion on the subject):

    • The four weights are integers.
    • The weights we can measure between one and forty pounds are in one pound increment.
    • They are measured in one session (otherwise, you could measure forty pounds with a one pound stone by performing forty measurements).
    • If there is no solution (the farmer might be bad at math), show the four weights that allow to measure the most weights between one and forty pounds.

    The challenge? Write a brute force solution to this puzzler in any language that you want. I don’t care if your solution is slow, fast, ugly or elegant as long as it works, and I suspect that certain languages will be very good for this puzzler

    Bonus questions:

    • Your solution should explain how exactly you use the stone pieces to measure each weight.
    • Is there a formal way to solve this problem without using brute force?

    Solution to the quiz

    Wow, my little quiz received a lot more attention than I thought it would. Surprisingly, of all the answers that I have read so far (over 150 between the comments on my blog and Google+), I only spotted three that match exactly my reasoning, which in itself, has to be a statistical anomaly.

    Anyway, enough waiting, here is my interpretation of the puzzler.

    This is a meta quiz: a question about a question. The first step to figure it out is to solve the “inner” question, which is determining what “right answer” or means. In other words, we need to answer “If you have a choice between four options and you pick randomly, what are the odds you’ll get the right answer?”.

    This is a very general question that can be answered easily: 1 in 4. 25%.

    Armed with this knowledge, we now focus on the “outer” question, which we can rephrase as follows:

    If you choose an answer to this question at random, what is the chance you will pick 25%?

    Looking at the choices, we notice that 25% appears twice among four choices, so you will be right 50% of the time.

    Therefore, the answer is 50%, right?

    Wrong!

    It’s B! You’re asked to pick a choice between A, B, C and D, not a percentage. Some teachers will actually fail you if your answer doesn’t typecheck :-)

    I think this is the answer that the creator of this quiz expected, however, the more I thought about it, the more I started to realize that there was a crack in the reasoning. Can you spot it?

    It’s the answer to the question above:

    If you have a choice between four options and you pick randomly, what are the odds you’ll get the right answer?

    The answer will be 25% only if the answer is present exactly once among the options. Not zero, not two, three or four.

    Do you think the meta quiz obeys this constraint? After all, 25% appears twice in the options, right? Yes, except that the correct answer is not 25% but 50%, which appears exactly once, so the quiz seems to be consistent with this caveat.

    Exercise left to the reader: can you rephrase the original quiz to close this loophole?

    Probability quiz



    Link to the discussion on Google+.

    Goodbye, old friend

    Yesterday, I received my Galaxy S II and it’s now time to say goodbye to my trusty Nexus One.

    I’ve had it for over two years and it is by far the best phone that I’ve ever owned. Even today, I still think it looks absolutely gorgeous. If you’ve never held one in your hands, you are missing out. It managed to run all of the applications that I’ve installed very well, even compared to more modern phones.

    As for the Galaxy S II, it’s quite a formidable phone and I have a lot of things to say about it after only twenty-four hours, but I’ll save this for a future post.

    Halloween

    How about a scary comic to get in the mood for Halloween?