Archive for May, 2009

Introducing photos

Friday, May 29th, 2009

I’ve been in Tel Aviv for almost a week now, and will be here for 9 more. I’ll write about what I’ve done this week when I get a bit more free time, I need to organize my thoughts a bit more. Anyway, I’ve been taking a lot of pictures and I wanted a place to share them so I spent a couple of hours adding a photos section to this blog.

sunset from Tel Aviv

I did a bit of research on what photo-sharing tool to use. Notable options where various photo-blogging tools, Picasa, and Flickr. Photo-blogging tools were unsatisfactory because each image is uploaded as it’s own post, and that serves a much more artsy purpose than I’m looking for; I want to be able to bulk upload photos. Picasa seemed pretty cool but there’s a fixed disk space quota that I’ll most likely exceed very quickly, and I don’t want to have to pay for the service. So I rested on Flickr. Flickr so far has been pretty cool; there’s a 100Mb a month quota, which I’ve already exceeded for May, but you get effectively unlimited space if you’re patient.

So I uploaded a bunch of pictures and now I was looking for a good way to add them to akrish.net. I ran across this wordpress plugin that pretty much served exactly the purpose that I wanted. I installed the plugin, ran into a bunch of difficulties that took way to long to fix, and eventually got the plugin running. Then I updated my wordpress sidebar so that you can get to my albums from any of the pages on my blog. Since I ran into a couple of problems, getting this to work made me pretty happy.

Long story short, links to my albums are on the right. There’s only one right now and it contains some of the pictures of my trip to Israel, including a tour of Jerusalem and some of Tel Aviv. As I mentioned, I’m over my quota for the month so more pictures will be up in June.

By the way, let me know if there are any bugs as I did have to do some stuff by myself.

High Release Flicks and Lefty Backhands

Monday, May 18th, 2009

It’s high time that I wrote something about Ultimate; I’ve been playing for this entire school year and I’d say I’ve become kind of obsessed. So obsessed, that I just spent the last minutes (between writing the previous sentence and this one) watching videos of ultimate on youtube. Ultimate has essentially replaced soccer for me. In high school, I was obsessed with soccer, I would watch games whenever they were on (and often record them), I would run and lift weights to improve my fitness for soccer, and of course I played competitively for a club team and for my high school. This year, I’ve been watching ultimate videos whenever I get free time, I train for ultimate and I played for Thugmo (our Men’s B team).

I have a decent amount to write about with regards to ultimate (of course keep in mind that I’ve been playing for less than a year) and I’m sure there will be many more posts to come about the sport. For this post, I wanted to write about throwing. During the year, I usually spent a couple of hours a week outside of practice just throwing a disc around with a couple of my teammates. I attribute a lot of my improvement over the past year to those sessions outside of practice, as I’ve noticed that my throws are significantly better than they were at the beginning of the year. My coach also repeatedly told us this: throwing is the best way for a new ultimate player to get better.

One thing that I really like about throwing sessions is that you get to goof around. At practices, I spend most of my time working on my real throws, the ones I’d use in games. When I go out and throw with my teammates, yeah we work on real throws, but we also work on stupid throws. Like today, we started out normally, throwing standard flicks and backhands, then started mixing things up with high release throws and upside down throws. Finally, we played a 4v4 scrimmage with only left handed throws. It was really fun, but I’d argue that the scrimmage wasn’t all that beneficial.

There is some benefit to the goofing around though. Some of those throws are really useful (especially hammers and high release backhands), but practice and tournaments aren’t the place to perfect them. That’s where throwing sessions come in. You get to work on the throws that you don’t have, and get them to the point where you feel comfortable throwing them in games. I’ve been working on my high release flick and my left-handed backhanded, both of which I feel can be useful short-distance throws, and I’m almost at the point that I’m willing to throw them in games. The same can be said with my hammer. Throwing sessions have really increased the types of throws that I am comfortable with.

From another perspective, as a overworked student, throwing is a great break. When I was a freshman we used to play soccer as a break, but for soccer you need at least 6 people. With ultimate, you can have a pretty good time with just one other person, and I can almost always find someone on my team who is willing to throw with me for an hour. It’s really easy to organize a throwing session, and I derive a lot of enjoyment from it.

I guess I’m just really excited to be playing a competitive sport again. After a couple of years without it, I realized how much I missed it. Last year, I tried filling the gap with running, but the lack of a close team didn’t cut it for me (although I do still enjoy running). It’s been really amazing to be back on a competitive team.

I’ll leave you with a video I watched while writing this. Enjoy.

Crazy Python Features

Friday, May 15th, 2009

I just finished taking a compilers class (well except for the final), and it’s been the single hardest class I’ve taken in college. Homeworks were non-trivial, exams were very difficult, and the class project was to write a compiler for a subset of python. As far as class projects go, this one has been completely ridiculous, my project partners and I have devoted weeks to building this compiler and fortunately we managed to finish it, but many groups I believe did not.

Anyway, in designing the compiler, I developed a new understanding of python features, despite having programmed in python for over a year.  My group and I found a lot of really crazy features of python that lead to problems when designing our compiler. I’m not going to talk about all the cool things that everyone knows about python, like lambdas, function values, nested functions and so on. I thought it would be fun to mention some of the really cool stuff here.

Dynamically Adding to Classes

Python basically implements classes as dictionaries. Instances are simply copies of the dictionary (well technically they are copied lazily, using copy on write), but instances naturally contain all of the mappings that the class contains (as they should). However, you can dynamically add mappings to classes so I can do something like this:

class A(object):
    x = 3
a = A()
print a.x ==> 3
print a.y ==> AttributeError
A.y = 7
print a.y ==>7

And I can even do this for methods:

class A(object):
    x = 3
A.foo = (lambda self,y: (self.x, y))
a = A()
print a.foo(6) ==> (3, 6)

When we discovered this, my project partners and I were amazed. It’s a really cool feature but I can hardly see a use for it (if you do see one, please let me know). Further, it makes implementing classes pretty inefficient since you can’t use a virtual table approach that C++ and Java can use.

Differentiating functions and methods within classes

We submitted our project after thinking we were done and “thoroughly” testing everything. A couple of hours later, we got feedback from the auto-grading system saying we failed (among a couple others) a test case that did something like this:

class A(object):
    x = 4
def g(n):
    print n
a = A()
a.x = g
a.x(5) ==> 5

We failed this test case because we assumed that any call to an attribute reference was a method call, and so we implicitly pushed on a as the first argument. This isn’t the correct behavior as we then pushed on one more argument than we should have. When we saw this, we were again amazed. Python somehow knows that a.x is a function and not a method, so it knows when it should implicitly push on self.

We hacked together a fix that I thought was pretty cool. We were representing all functions as boxed 12 byte function values, where the first byte pointed to a dummy virtual table, the second byte pointed to the code for the function and the 3rd byte was the static link for that function. Since from this perspective, functions and methods were exactly the same thing, we had no way to tell whether the object we had was a function value or a method value, so we were pretty stuck. Instead, we added a byte to all function values that kept track of whether they were functions or methods (yeah this is a huge waste of space, but performance wasn’t our priority at this point). Then at runtime, we are forced to check whether the value we’re trying to call is a function or a method, and behave appropriately in each case.

Unfortunately there’s a huge increase in code size. Now every call in python requires the check mentioned above, and two distinct call instructions, of which only one would get executed (because we were required to push on the number of arguments as a parameter to the callee function). We discovered this bug like 2 hours before the deadline, and we weren’t being graded on performance, so we didn’t really care about this issue. I am interested to know how python does it. My guess is that in the class dictionary, methods aren’t stored as “function values” so you would be able to tell right away, but I haven’t looked it up. If you know how python does it, let me know.

If-Expressions

I didn’t really use If Expressions before this class, and now that I’m more familiar with them, I think they are actually quite useful in writing concise code. I’m not talking about the standard if-elif-else clauses, but more of the analogue to x ? y : z syntax in C. And this feature isn’t that crazy, in fact it’s what I expect python would do. So an if expression looks like x if y else z and the semantics are that this statement returns x if y evaluates to True and otherwise it returns z. So it’s just like the ?: construct in many other languages. It’s cool when you use it with function values. For example:

def foo(x): print x
def bar(x): print -x
y = True
(foo if y else bar)(4) ==> 4
z = False
(foo if y else bar)(4) ==> -4

And that’s really cool. I can really concisely choose what function I want to call at runtime. I haven’t thought of a lot of uses for this exactly, but I can definitely see myself taking advantage of it’s presence.

The global keyword
There are some really cool features with global that I think are pretty standard in most languages but that I’m not used to seeing. For example:

def g():
    global a
    a = 3
print a ==> NameError
g()
print a ==> 3

This means that the when you declare a as global, if it’s not already bound in the global environment, you make a binding for it. I’m not exactly sure how this works in other languages, but I can totally see a language throwing an error if a is not bound in the global environment. Here though, python is smart enough to make the binding for you, and then you can use it after the call to g. This means that there are some really interesting ways that you can dynamically add names to the global environment.

So I’m sure there are more really interesting features of python that I haven’t discovered, and I’m pretty sure there are some that I have found that I’m just no remembering right now but these are some of the coolest language features I’ve seen. As I mentioned throughout, some are definitely more useful than others and I’m sure that in some cases these may be undesirable. If you know of any crazy python features that I didn’t highlight, I’d be interested in hearing about them.

Every kid should be raised on Sesame Street

Thursday, May 14th, 2009

So a couple of my roommates and I have recently (re)-discovered Sesame Street on YouTube. It’s been quite entertaining seeing clips of videos that I remember distinctly from my childhood. Also some of the clips are really funny to college students. Here are some of my favorites:

 LL Cool J goes on an Addition Expedition. -  best line ever: “One Elmo monster and one Mr. LL Cool J makes one, two friends!”

Cookie Monster’s Rap. - I totally remember this song from when I was like five. Brings back good memories.

Hoots vs. Yo Yo Ma - Hoots is hilarious. Also Yo Yo Ma is awesome.

Cookie Monster’s Letter of the Day - Cookie Monster’s eyes are so funny.

Gangster’s - exactly like real mobsters…

As you can probably tell, I’m totally procrastinating during finals week. I thought I wrote about this before but I couldn’t find the post. Briefly, I hate finals. Not because of the exams, but because if I do any work that isn’t explicitly studying for your exams, I feel really guilty about not prioritizing exams. What this means is that my productivity goes down the drain. I do spend a decent amount of time preparing for my exams, but I definitely have more time to exercise, and work on other projects. So for the past couple of years, finals time for me has been a decent amount of studying mixed with a lot of wasting time, watching tv and playing guitar, but with an overall drop in productivity.

So that’s how we found the Sesame Street videos. I hope you enjoy them!

Movie Review: Earth

Sunday, May 3rd, 2009

I don’t watch that many movies, but this weekend my parents and I went to watch Disney’s (actually Disneynature’sEarth. All three of us really enjoyed the movie so here I am writing a short review.

First of all, you should watch the trailer, you get a feeling for the ridiculous footage that the directors managed to take.  The movie is basically a documentary about the Earth (duh) and a lot of the creatures that coexist with us. The “story” focuses on three families (polar bears, whales, elephants), but also spends some time on tons of other animals: monkeys, birds of paradise, wolves, penguins, you name it.

Naturally, the theme of how humans are making it difficult for animals to survive is present, but it’s quite subtle. The movie wasn’t designed to reprimand humans (like I believe An Inconvenient Truth was); instead it showed specific examples of how global warming was making it difficult for animals to survive. The narrator would say things like “as our world warms, it’s becoming harder for …,” without directly blaming humans (though we all know who’s fault it is). I really liked how they didn’t get distracted with this theme, as I could vision the movie being completely different if they had emphasized this point further. Not that I don’t think the whole environmentalism issue isn’t important, I think that the movie still made it’s point without becoming too intrusive and forceful.

I was also really impressed with the footage the directors captured. Even in the trailer, there are some amazing shots. I can’t say much about this without giving away anything really cool about the movie, but they use some pretty cool techniques. Most noticeable (and cool) is the time-lapse photography that they use to show change. They use it tastefully to show growth of organisms, seasons changing, etc. Then, there is a lot of aerial footage, in places like the Arctic Circle, Niagara Falls, the African Savannah, and the Rain Forest. A lot of this footage is also really cool (though some of it seems like pretty standard stuff).

The crazy thing is how they managed to get so much footage of animals. For one of the first scenes, the crew waited with cameras trained for two weeks to film polar bears emerging from their winter den after winter. There’s tons of this stuff and I haven’t really seen that much of it (though I confess I’m not much of a nature buff).

What really caught my attention was the soundtrack. It’s not often that I notice the soundtrack of a movie, but there were several times that I found myself thinking “this music is really fitting and also standalone awesome.” The soundtrack was recorded by the Berlin Philharmonic, and they’re an internationally known orchestra. I’m really excited for the soundtrack to come out so I can listen to it while studying.

Overall, I definitely recommend Disneynature’s Earth. Again, I don’t watch a lot of nature documentaries, but I really liked this one. I don’t think it’ll win many awards, but it’s a good movie. Also, you should watch it in theaters to really appreciate the cinematography.