Metaclasses in Ruby


Well, I don't have any drawings of cartoon characters for you, but I do feel like making a post about Ruby.

I've been learning the Ruby programming language as I use it in some projects. So far, it's been a breath of fresh air after the rigidity of C++. Although C++ is very powerful, it can be kind of clumsy. I've been using a mixed approach in some projects, where Ruby code invokes C code.

Recently, I found myself playing in the deep end of the language. Every programming language has a deep end, whether or not it's advertised as a feature. With Ruby, the really hard part seems to be understanding the singletons.

Every object has a singleton which holds methods specific to that object. So the singleton can be viewed as sitting in between an object and its class. This is how you can add methods to an individual object.

In other words:
class C; def foo; puts "hi"; end; end
c = C.new
class <<c; def bar; puts "bar"; end; end
c.bar ==> "bar"

Even though the class of c was C, the singleton of c held a method called bar, which we could invoke. As Why the Lucky Stiff says, "the hidden singleton lurks behind everything."

Now the singleton is an object in its own right, and can even have its own singleton. Most people don't find this useful. One thing that people do find useful is pulling out the singleton from an object with a construct like
def get_singleton; class <<self; self; end; end

Of course, the real fun comes when you start playing with singletons of Classes. Since Classes are Objects in Ruby, they also have singletons. I can't say that I understand all the implications yet. But you sure can do some cool things.

Note: some people call singletons "metaclasses," but the language designer views that as a misnomer.


EU directive 2004/93/EC

Do most people know that most cosmetics sold in the US are completely untested?

This EU directive bans the use of know carcinogens, mutagens, and substances harmful to reproductive health in cosmetics. It went into force in September 2004. But the United States has nothing similar to that.

Over 1000 substances are banned for use in european cosmetics; in comparison, only two dozen are banned in the U.S.
That means that cosmetics in the US can contain things like lead and phthalates.

I think, knowing what I know now about cosmetics, I would advise all pregnant women to avoid them. And if at all possible, get your cosmetics from Europe, where they actually test them before putting them into use.

There has been a recent bill proposed which would fix some of these problems. Lets hope it's not a victim of the current legislative gridlock.


silly expressions that I like

I recently had to explain to someone what "jumped the shark" meant.

For those of you who don't know, when something used to be good, but later became bad, you say that it "jumped the shark." For example, someone might say that Star Trek jumped the shark after [insert your least favorite series here].

Then there's "phoning it in." This is another expression I really like. It means to do a poor job at something because you just don't care. For example, you might say that "the band played pretty well on Thursday, but on Friday I think they were just phoning it in."

When you take a sick day, you usually call up your employer to let him know. I think that's where "phoning it in" came from.

I guess this post is mostly content-free. I blame the weather. It's too nice for me to spend much time on reviewing a difficult technical article. I guess this blog jumped the shark after I started phoning it in, eh?



I know it's dorky, but I always thought that these electrocardiography input devices were cool.

Neural activity generates electrical potentials that are picked up by the three electrodes that are on the forehead of the user.The actuator then separates the electrical activities into three classes of neural and electromyographic signals. That is electro oculographic, electro encephalographic and electromyographic signals for those who are wondering!These signals are said to reflect the activities of the extraocular muscles, the brain, and the facial muscles.

These signals are then decoded and combined with each other to create unique commands based on the specific permutation of brain, eye and facial muscle activity.What's really weird about the technology is that it really does work! OCZ informed LR that the technology behind the neural impulse actuator is ready to go and they will be bringing the actuator to market. Unlike other products this device hooks into existing games now and allows you to play games like Unreal Tournament already. There is a learning curve to using one of these, but it's pretty easy and should take ~2 minutes to get the device working.

The device is cool because it allows you to control a computer with your thoughts. It's also an output-only device, which is reassuring. I guess it's kind of like a chord keyboard-- you have a few different binary outputs, and you combine them together to get 2^n possible output symbols.

It seems like they are targeting the gamer market. Will people be willing to buy this device-- and climb the substantial learning curve-- to get an edge in their favorite first-person-shooter game?

The biggest market for this device will be gamers as they will be able to use the neural impulse actuator in combination with the a mouse to control the shooting, jumping, running, etc. in FPS games. OCZ hopes to bring the actuator to market by year’s end and hope to bring it to market at around $300 USD.

It's an old idea. Atari produced such a device-- the Atari Mindlink. It was canned by Jack Tramiel when he took over the company. As the AtariMuseum site says:

A combination of headband with Infrared Transmitter and Infrared Receiver, the Atari Mindlink system could connect to your Atari VCS 2600, Atari 7800 and Atari Home Computers. Using specially written software you could control the action on the screen. The headband would read resistance from muscles in the users forehead and interpret them into commands on the screen. Although never released, feedback from Atari engineers and people who tested the Mindlink have commented that the time and effort put into the Mindlink system was wasted because the controllers did not perform well and gave people headaches from over concentration and constantly moving their eyebrows around to control the onscreen activities.

I wonder if OCZ's device will meet the same fate. I hope not. I'd love to have something like this for my laptop. I hate tiny laptop keyboards.



With the pace of technological change we are seeing today, there are a lot of new food products on the shelf. Unfortunately, the public has been the guinea pig for a lot of these products. Often, it takes a few years-- or even decades-- before the health risks of the new products are really known.

Unless you've been living under a rock, you probably already know that "trans" fat causes heart disease in otherwise healthy individuals. That's why Canda is considering banning it.

More recently, evidence has come to light suggesting that artificial sweeteners cause metabolic disorders.
Diet soda has been consistently correlated with obesity. My immediate reaction to this was to write it off as a simple "correlation without causation" scenario, but there are reasons to believe otherwise.

Excerpt from http://www.medicalnewstoday.com/articles/96849.php

The authors... measured changes in the core body temperature of the rats. Usually, when the body of an animal gets ready to eat, the "metabolic engine" revs up, which raises the core temperature of the body. But when they gave the rats fed on saccharin sweetened yogurt a new, sweet tasting, high calorie meal, their core body temperature did not go up as much as that of the rats who had been fed on yogurt sweetened with glucose.

Swithers and Davidson argued this was because the saccharin fed rats had a blunted response that had the double effect of making them eat more and making it harder for them to burn off calories.

If you're looking for a website with some good nutritional information, try out http://www.acaloriecounter.com/diet-guide.php This guy knows what he's talking about.


Back from the Dead!

It's been a while since I posted here. I didn't really mean to let it go this long. Anyway, since I last posted, I have:
  • moved from Pittsburgh to the San Francisco area
    • It's a lot warmer here, folks.
    • There are so many Asian and Indian immigrants out here! Not to mention Hispanics.
    • People love their food.
      • Which is likely to be seafood or vegetarian food
    • You can pay $5 for a gallon of non-organic, plain old milk at Target
  • gotten a new housemate
  • learned a lot about the mobile GPS unit industry, and the map data suppliers for the industry
  • figured out how to use Craigslist.org
    • you can buy a TV
    • or post in the personals section
  • made my first real investment (in a Certificate of Deposit)
  • Enrolled in a freehand drawing class
    • I know how to draw a vase now... mostly
What will the future hold? Well, possibly I will:
  • Endure the coming depression
    • Yahoo is about to disgorge many of its employees
    • Consumer confidence and inflation don't look good.
  • Invest in a mutual fund
    • Overseas investments look good right now; commodities too.
    • Better keep some money market funds around, though...
  • Start exercising more regularly
    • 3x a week
  • Get a new haircut
    • New idea: short hair
  • Download the Internet
    • this one is a "stretch goal"


Against Centralized Source Control

Linus Torvalds gave an hour-long talk about the Git source control system.
The talk was hosted by Google.

The most important points seem to be:
  1. git users are all peers with a complete copy of the tree. There is no repository and no commit access.
  2. git focuses on hashing and merging sets of files really, really fast
  3. git can't scale above 1 million files, but Linus believes that projects with that many files should be split into multiple projects for other reasons.
Linus has a lot of abuse for CVS, Subversion, and Perforce, because he thinks that they've been focusing on the wrong problem. He believes that distributed source control systems are inherently more robust and secure than centralized ones. Linus is relentless in his pursuit of technical excellence and doesn't hesitate to label competing projects as "stupid and ugly."

Speaking as someone who has a lot of experience using one particular centralized system, Perforce, I can say that when our central sever went down, we couldn't get any work done. Git users, on the other hand, can continue to work on patch sets even when the network is down or the main server is down, and even merge two patch sets when the network is unavailable.

git provides some security against malicious attempts to corrupt the central server. Because git checksums all files using the cryptographically sound hash SHA-1, people who are syncing up (or "pulling") a git branch should notice if that branch has been tampered with by people going outside the source control system.

One thing that is overlooked in this talk is that most corporations are also interested in securing their closed-source code against attempts to steal it. This is not an issue for Linux, and in fact, Linus wants as many people to mirror the kernel as possible, so that if any of the main server disks go down, he can copy it right back from them. "I don't do backups," Linus states flatly.

Linus also makes some jabs at Perforce that really hit home. He complains that all clients in a centralized source control system have to share the same namespace, so they often have to be named funny things in order to keep them from conflicting. Rather than naming them purely by what changes they contain, people must put some unique identifer in the client name in case anyone has a similar client. This is not a big deal at a small company. But try scaling that up to a really large organization with multiple sites, or an open source project, and it becomes difficult.

Interestingly enough, Linus states that his parting with the Bitkeeper people was amicable. He seems to respect their product, and states that using Bitkeeper really showed him what a source control system should be. I guess a lot of people in the open source community were upset that Linus was using a tool that was not itself open source to maintain his open source kernel. I haven't really looked into the debate much, but it's still interesting to get Linus' angle.

Linus states that git reduces political pressures because he doesn't have to decide who to give commit access to. I suppose what he really means is that it makes it easier for him to have degrees of trust. Rather than giving him a binary decision to make-- give this person commit access, or not?-- he can just pull patchsets from people with different levels of scrutiny depending on how much he trusts them. Ultimately, of course, Linus must decide what goes into head-of-line, aka "Linus' Tree," and that will always involve some amount of politics.

I will have to try out git the next time I get a chance. It just seems like one of those tools that will make an impact in the way people work, even if they don't end up using it directly. Obviously, most commercial projects are not the Linux kernel, where you have thousands of functionally anonymous contributors submitting bug fixes and patches. But a lot of big companies have multiple sites, and if those sites are going to develop software together effectively, they're going to need tools like git.