Geek tip: Malloc debugging on OSX

I’ve been trying to chase down an annoying bug that I suspected to be a case of using uninitialized memory. The problem is, it only shows up about 1 in 30 times (I was lucky to notice it in the first place), and never in a debugger.

Fortunately I found that there’s a library on OSX that tweaks malloc() to help you debug:

DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib MallocPreScribble=1 ./myprogram

Or, to do this in LLDB, since due to System Integrity Protection, your linker-affecting environment variables get wiped when you execute a system program:

lldb -- ./myprogram
env DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib
env MallocPreScribble=1
run

This triggered the bug every time, both inside and outside the debugger.

For more information about what you can do with libgmalloc, see this documentation. It only tells how to use that facility in Xcode, though, so the above instructions should help if you’re on the command line.

Endless is Here

For the past 2.5 years I’ve been working at Endless Mobile on something that was mostly secret. You probably caught me being vague about “computers for developing countries.” Well, secret no longer. I am excited, proud, and honestly a bit relieved to be able to say that I can finally tell you what it’s all about.

“Tell you” is a bit of an exaggeration, I’ll let the videomaking skills of my coworker Taylor Morgan show you instead. The video is at the top of our Kickstarter campaign.

We’re launching our first product, via Kickstarter. It’s a computer that’s affordable for people in developing countries, and it looks like this:

Endless One

Alien Egg

I’ve been working on writing applications for this computer, and also contributing to some parts of the operating system. Some parts of this are open source, and you can view them on GitHub.

Also, I have colleagues who are really fun to work with. If you happen to like fun and are looking for a job, there are some positions open… (It’s at the bottom of that page.)

Update: Within only four days, the Kickstarter campaign hit the original goal of US$100 000. It’s incredible. My favorite part is that almost $30 000 of that money was donated by people paying to give a computer, rather than buy one for themselves. Enough people asked for the option to donate a computer directly, so it was added. Also you can now get the whole package for yourself: computer plus swag, because enough people asked for that too.

 

Wave at the camera

You have probably seen the fake advertisement for Wave, the new way of charging your iOS 8 phone in any standard household microwave. (Although I would venture that some of the responses with fried microwaves and phones are hoaxes as well.)

I admit I did giggle when I first read it — some chump microwaved their expensive phone and blew it up, funny, right? Only I realized that it’s not funny at all.

Why shouldn’t people believe that a new technology would allow them to charge their phone by microwaving it? It’s no more or less magical than any other new technology being invented every day. It just happens not to have been invented yet.

Yes, people need to think critically, check sources, use common sense, and become less science-illiterate. Is microwaving your phone a smart thing to do? No. Could the average person probably have known better? Yes. But if you are lucky enough to be in the minority for whom this is obvious, you don’t have any right to laugh at those for whom it is not.

Faster than a speeding bullet

Perhaps not the most wisely chosen title for this Scientific American newsbite, but very cool research: “Ultra High Speed Camera Records at Speed of Light

They have built a high-speed camera with a high-enough frame rate that they were able to watch a pulse of laser light traveling through a Coke bottle in slow motion. (Pause for a moment to watch this video, for it’s really impressive. I’ve linked to the juicy part.)

You should never read Youtube comments, but on this video, people are actually asking good questions, albeit with the usual Internet rudeness. There are two very confusing things said in the video and article which I think are putting people on the wrong track.

Velocity vs. rate

This can’t possibly be true! Nothing can move faster than the speed of light.

The camera does not record at the speed of light (slightly less than 300 000 000 meters per second, or 1 billion km/h). This confuses two common meanings of the word speed: ‘velocity’ and ‘rate’. It makes no sense to say that a camera records film frames at a particular velocity, much less the velocity of light; velocity means something is moving, and in this case nothing is moving fast at all. (Except for the light pulse itself, which of course travels at the velocity of light.)

Instead, by ‘recording speed’, it really means the camera is recording at the rate of 1 billion images per second (which is not the same thing as meters per second). There is a fundamental rule saying that no object can travel at a faster velocity than 300 million meters per second, but there is no such rule for rates.

(Although, if it were an old-fashioned film camera, the film would have to feed through the camera at a velocity faster than the speed of light, which would be impossible. So it’s lucky we live in the digital age.)

“We can see photons”

The other confusing thing is that the researcher says in the video that they can see photons moving through space — that’s strictly true, but not very helpful, since you are seeing photons moving through space right now too. That leads people to ask:

Hey, I thought you could only see light when it reflected off something into your eye! How can we see the photon moving through the bottle when it hasn’t hit anything yet?

Well, the thing we see moving through the bottle is a laser pulse – not one photon but a clump of trillions of them. Out of those trillions, some hit air molecules and fly off in all directions, and some of those happen to hit the camera. We say “the pulse scatters off the air.” So, it’s true, you can’t see photons directly unless they are flying right at you. What we’re actually watching is the air molecules lighting up as the laser pulse passes by.

None of this takes away from the fact that the front edge of that laser pulse travels with the speed of light — and we are watching that in slow motion! How cool is that?

Bibimbap for one (multiply for more)

Bibimbap is a Korean rice bowl. This is a fiddly recipe; not difficult at all, but it takes a lot of effort to put together. However, it looks awesome and contains all the flavors that characterize delicious Korean food: chili, garlic, sesame oil, and sweetness.

The very best bibimbap occurs when you heat up a serving-sized stone bowl, drizzle a little sesame oil in it, then put the rice in the bowl and let it sizzle and get crispy on the bottom while you put the rest of the ingredients on top. This is called dolsot bibimbap. However, if you’re making this at home for the first time, you likely won’t be able to do that on account of not having stone bowls. I certainly don’t, and so I enjoy it all the more when I go to a Korean restaurant where they do have stone bowls.


Bibimbap for one
All the amounts given here are for one person.
Since it’s really a bunch of tiny dishes all put together in one bowl for each person, it doesn’t really make sense to make enough for leftovers, because you’ll end up with a bunch of tiny containers in your refrigerator. Just multiply the amounts by the number of people you are feeding.

Buy gochujang, rice vinegar, sesame oil, soy sauce, and dried shiitake mushrooms at an Asian grocery store. (If you use dried mushrooms, don’t forget to soak them in water for eight hours before.)

Gochujang is chili paste that is usually sold in a red plastic container with a flip top (I call it a “treasure chest.”) That will be way more than you need for this recipe, but you can always use it up in tteokbokki.

Spicy sauce

  • 1 tbsp gochujang (Korean chili paste)
  • 2 tsp rice vinegar
  • ½ tsp honey
  • ¾ tsp sesame oil

Mix the ingredients together and let it sit while you prepare the rest of the meal.

Rice

  • ¾ cup water
  • ½ cup basmati rice (short-grain rice would be more authentic, but it’s more expensive where I live)

Boil the water in a pan. When it boils, add the rice. Lower the heat, cover, and leave, stirring occasionally, for 20 minutes while you prepare the rest of the meal. After 20 minutes, remove from heat.

Marinade

A note here: this is usually done with beef strips but, in a shocking departure from the usual, I actually prefer deep-fried tofu here, because it soaks up the flavors quite nicely, and most grocery-store beef is not good enough quality to be able to pull this off. If you use beef, make sure it’s good beef. You can get pre-fried tofu at an Asian grocery store, or deep-fry it yourself.

  • 1 garlic clove
  • 1 cm piece of ginger root
  • 2 tsp soy sauce
  • ½ tsp sugar
  • ¼ tsp toasted sesame seeds
  • ½ tsp sesame oil
  • ground black pepper
  • 40 g deep-fried tofu puffs or beef strips

Whack the garlic clove with the side of a knife blade and then chop it finely. Peel the ginger and grate it. Mix the garlic, ginger, soy sauce, sugar, sesame seeds, oil, and pepper in a bowl. Slice the tofu into strips and coat them in the sauce and leave it while you prepare the rest of the meal.

Raw vegetables

  • one-sixth large cucumber or ½ snack cucumber
  • ½ small carrot
  • 2 tsp powdered sugar
  • 2 tsp rice vinegar

Slice the cucumber very thinly. Slice the carrot into matchsticks. Put the carrots and cucumbers in a bowl, but don’t mix them together. Mix the sugar and vinegar and pour it over the vegetables. Leave it while you prepare the rest of the meal.

Mushrooms

  • 2 shiitake mushrooms
  • ½ tsp vegetable oil
  • pinch of salt
  • pinch of ground black pepper

Slice the mushroom into strips. Heat the oil in a frying pan. Fry the mushroom with the salt and pepper.

Sautéed vegetables

  • 1 tsp sesame oil
  • 1 tsp honey
  • 1 tsp soy sauce
  • 2 spring onions
  • 50 g spinach, washed and de-stemmed

Mix the oil, honey, and soy sauce. Chop the white and light green parts of the spring onions into thin slices, and chop the dark green parts into 3 cm sections. Fry the spinach until it just turns dark green, then add half the sauce mixture. Stir briefly and remove to a bowl. Put the chopped spring onions in the same pan and fry them, then add the rest of the mixture. Stir briefly and remove to another bowl.

Assembly

By this time the rice should be done. Put it in an individual-sized bowl, and arrange the cucumbers, mushrooms, spring onions, carrots, and spinach in pie-chart sections on top of it, leaving space for the marinated tofu (or beef). Stir-fry the tofu over medium heat for 2 minutes; if using beef, do it for 3 to 5 until the meat is brown. Put it on top of the rice.

Egg

  • 1 egg
  • ½ tsp toasted sesame seeds

Fry the egg until the white just starts to bubble. Flip it over and fry the other side, but not too long — the yolk should still be liquid inside. Put the egg on top of the ingredients in the bowl, in the center. Drizzle the spicy sauce on top. Sprinkle the sesame seeds on top.

It looks very aesthetically pleasing now, but to eat it, you should mix it all together, breaking the egg yolk and letting it coat everything. Eat it with kimchi on the side.

(Adapted from emagasia.com and a now-defunct recipe in The Independent.)

Nature, why?!

Scientific journals charge subscription fees in order to access their content. If you’re an employed scientist, the university or company where you work usually buys an institution-wide subscription to a journal. In that case you don’t have to log in to the journal website because it recognizes your IP address as belonging to a subscribing institution. In fact, you don’t even get an account on the journal website, because it’s impractical to issue an account to every single user at a university, for example.

So what do you do when you have to look up something when you’re away from your office? You use SSH with port forwarding to connect to work, then visit the website using a proxy server on that port. Since you are now browsing through a work computer, you can read the journal. There’s nothing wrong with this, because your employer has already paid for your access that content, but the barrier was simply the impracticality of issuing you an individual account.

So it’s really strange that Nature Publishing Group, which publishes the overrated Nature family of journals, seems to want to discourage this practice. If you visit the site of a Nature journal from a non-subscriber IP address, they set a cookie in your browser that says you are not a subscriber. So even when you turn on your proxy server and revisit the site, it still tells you you’re not a subscriber and can’t access the journal article. Luckily, it is easily remedied by erasing your browser’s cookies. (Easily done, that is, but not easily thought of. Hope this helps someone.)

Why, Nature, why? Why would you do this? Do you have scientists’ best interests at heart and you want to prevent them from working at home? Or do you hope that people are gullible enough to pay twice for the same content?

Faux Korean Noodles

In order to use up ingredients for Korean food, I improvised a hybrid of bibim guksu (spicy noodle salad) and japchae (stir-fried noodles) this evening. Unfortunately I forgot to take a picture, but you can catch a glance of very similar food at the 3:22 mark of Gangnam Style.

Vegetables

  • 1 tablespoon vegetable oil
  • 1 teaspoon sesame oil
  • 1 red onion, sliced
  • 4 small carrots or 1 large carrot, cut into matchsticks
  • leftover kimchi, chopped
  • lemongrass fake chicken leftover from who knows when, sliced (optional)
  • any other vegetables or meat you want to use up, sliced

First put a pot of water on to boil. In a wok, heat the oils. Fry the onion. When it starts to get translucent, then add the carrots. When they start to brown, add the kimchi and the fake chicken. Add any other ingredients at the appropriate times. When the vegetables are tender, turn down the burner until later.

Sauce

  • 2 cloves minced garlic
  • 1 teaspoon sugar
  • 2 teaspoons sesame oil
  • 2 teaspoons rice vinegar
  • 1 tablespoon toasted sesame seeds
  • 4 tablespoons liquid from kimchi
  • 8 tablespoons gochujang (red pepper paste that comes in a little plastic treasure chest thingy)
  • 1 tablespoon leftover bruschetta from an appetizer the other day (optional)

For the kimchi liquid, use the juice from whatever kimchi you used in the vegetables. If you don’t have enough, just make it up with water. Mix all ingredients together in a small bowl and set aside.

Garnishes

  • 2 eggs
  • 2 baby cucumbers, cut into matchsticks
  • 1 green onion, sliced coarsely
  • a few sprigs of cilantro, de-stemmed and chopped

By this time, the water should be boiling. Boil the eggs for 10 minutes. Meanwhile, chop the other ingredients and set aside. When the eggs are done, add the noodles (see below) to the pot immediately. Rinse the eggs with cold water, peel them, and cut them in half. Set aside.

Convergence

  • 250 g dangmyeon (sweet potato starch noodles)

Boil the noodles for 6 minutes, then drain and rinse thoroughly with cold water. Add the noodles to the wok, turn the heat up again, and stir-fry them for about 3 minutes, tossing them with the vegetables and/or meat. On each plate, put a helping of noodles, then garnish with the garnishes and spoon the sauce over the top.

Serves 3.

Adapted from Maangchi’s japchae and bibim guksu.