On a side note, I’m really enjoying Scott Hanselman’s podcast This Developer’s Life. It’s an homage to
the awesome This American Life, but
focused on programming issues. They interview interesting programmers,
but they carefully edit the interviews to focus on the parts that are
the most interesting, interspersing them with music and effects. It’s
really well done.
I woke up, got ready and went downstairs. I am not a morning person. I
try to do as little thinking as possible, because thinking eventually
leads to the rational conclusion that I should just go back to bed. I
get to the coffee machine, grab my plastic mug and start pouring.
Suddenly, I’m woken from my daze. I hear little footsteps pounding
across the hallway above me. I look towards the bottom of the stairs
and see a little figure race around the corner with a determined,
slightly fearful look in her face. She’s afraid that she’s too late
and that I’ve already left for work. She spies me and I must be
smiling because her face melts into the biggest, happiest smile and
her pace quickens. We run to meet each other in a big hug. “Daddy, can
I watch the milk go in your coffee?”
Moments like that are so joyous, and I have underestimated how much
they mean to me. I want to capture them and never let them go.
Like the rest of the geek world, we’ve been excited by Curiosity’s
successful trip to Mars. Here’s a cool video which combines an
animation of Curiosity’s landing mixed with the real reactions of the
astronauts that got it there. (Found on thekidshouldseethis.com)
I’ve been disappointed that real space travel is unlikely to become a
reality during my life. I honestly thought it would when I was a kid.
But watching Curiosity gives me hope that we will be able to continue
exploring our universe. This trip to Mars was much more of an
achievement than the last one. Here’s an animation of the last trip
(2003 Mars Exploration). Note that the final landing was achieved by
an air bag dropped roughly from high up in the air. Not much precision
required there.
Curiosity is huge (NASA)
The Curiosity rover is too large for the airbag approach (See image at
right comparing it to previous rovers), so an alternate system was
devised using a sky crane which gently lowered the rover onto the
Martian surface. Dropping an airbag seems much easier than gently
landing a rover without damage. The real advance in our lifetime is
that our machines are getting more intelligent. And the exciting thing
is that I can actually participate in that type of exploration. I
think I just convinced myself to learn how to program a robotic car!
I’m going to start blogging more. I know I’ve said that before, so
take it for what it’s worth. I think there is value in blogging. I’ve
been thinking about my life a lot lately, trying to find what makes me
tick. One of those things that gets me excited is programming. I
started thinking about that and remembered this meme that had passed
around the blog world a few years back. It was a list of questions
related to how you got started programming. I remember it especially
because I remember reading MarkD’s version and thinking how similar it
was to my own beginnings. Then, because I love going off on tangents,
I googled for ‘How I got started in programming’ to read other
responses. Many of the posts I found were on abandoned blogs. And now,
for the ‘causal relationship not supported by data’ statement. This is
because of Facebook and Twitter. OK, maybe it’s just the natural decay
of blogs. But I am concerned about the fact that most people write in
forums that are controlled by other people rather in their own forum.
That was one of the cool promises of the web. A little place of your
own that you controlled. Facebook and Twitter and Google+ are all cool
services, but the more time I spend on them, the less time I spend
here. I’m sure other people have written about this with more
eloquence than I could, but the bottom line is that I want to keep
writing. I want to learn more about myself, I want to teach others
what little I know, and I want to learn from others. I’ve been
journalling a lot lately and that has been useful, but the act of
hitting ‘publish’ will make my writing better. That’s what this blog
is for and I’m going to start using it again.
Maybe one of these days, I’ll even put up my own answers to ‘How I Got
Started in Programming’, but in the meantime, go read
MarkD’s
I wonder how many of my blog posts are based on stories from This American Life. Probably not
enough. Every time I start to listen to a show, I’m certain that I’m
not going to be interested and within a minute I’m trapped and can’t
stop listening. It’s that good. A recent show was about people who people who pursued crazy ideas.
The first story was about a mathematician named Frank Nelson Cole. Marin Mersenne had
claimed in the 17th century that 267-1 was a prime
number. He was prominent enough that the claim was felt to be accepted
wisdom and there was certainly no way to test the claim in the days
before computers. That’s a big honking number:
147,573,952,589,676,412,927.
In 1903, Frank Nelson Cole walked into a meeting of mathematicians to
present his talk. The title was boring, something like “On the
factoring of large numbers”. Without speaking a word, he walked up to
the chalkboard and started to write a large number, followed by
another large number and then started to multiply them together. It
took a while, but by the time he started to get towards the solution,
the crowd of mathematicians understood that he was proving that he had
found two numbers whose product was the famous “prime” number
267-1. As he came close to finishing, the anticipation
peaked and cheering began. He finished the calculation and sat down,
never speaking a word.
Stories like that give me the chills. Can you imagine how excited he
must have been when he found those 2 roots? I get that sensation every
once in a while when I make a programming breakthrough, solving a
problem which I had been banging my head on for a while. It’s nowhere as
profound as what he did, but I think I can understand the exhilaration
he must have felt.
I decided to see what those 2 roots are, using my new favorite
language, Clojure. I’m by no means an expert in anything, let alone
programming and especially functional programming, but here’s how I
went about it. The REPL is such a fun way to explore things like this:
I need a range of numbers which I’ll then test one-by-one to see if
they divide into 267-1 evenly.
I need to find the remainder of a division (Of note, mod also does
the same thing, but rem is a lot faster)
user=> (rem 9 2)
1
Can I find all the lower roots of a number? The #(...) syntax is
syntactic sugar for an anonymous function. The % is a placeholder
for the value which is being iterated over. So the following
function takes each value in the list returned by range and
supplies it to rem. If that rem function is equal to
zero, then the #(...) anonymous function returns true and filter
keeps the value.
Now let’s map over each of those values, finding the corresponding
higher root for each value. vector creates a vector (think list)
with the first value being the supplied value and the second value
being the other root (/ n %):
OK, that didn’t work. It clearly found way too many roots, because
267-1 was an approximation. We have to use BigIntegers which have
appropriate precision even with large numbers.
Cool!!! It works! Those are the roots of 267-1. How long did that
take to compute? (We need doall to make the time command wait
for all of the values to be calculated, otherwise it will return
after the first value is calculated. This has something to do with
the laziness of clojure sequences)
6 hours 18 minutes. I’m sure there’s a quicker way to do this. I do a
lot of redundant testing. For example, once we know that 2 is not a
factor, we shouldn’t check any more even factors. I’d be interested in
any advice to make it run faster.
I can’t even fathom how you’d go about doing this without a
computer. Can you imagine how frustrating it must’ve been any time you
had a simple error? Just amazing…
Phonegap is a tool that allows you to develop
apps in HTML5 + javascript and makes it easy to deploy them to
multiple mobile platforms, including Android and iOS.
ClojureScript is a dialect
of the awesome language, Clojure, that compiles to
Javascript (after a pass through the Google Closure optimizer). Because Clojure,
ClojureScript and Google Closure can be confusing terms, I’ll use CLJS
instead of ClojureScript for the remainder of this post.
What I wanted to do: Write a simple CLJS app that runs on my Android
phone using these tools.
Get HelloWorld working with PhoneGap
Following these instructions will
get the Android SDK, Eclipse plugin and PhoneGap working. If you
already have the Android SDK, you’ll be able to skip most of it. I’m
most comfortable in Emacs, so I’ll be using that instead of
Eclipse. Here is the command-line command for creating your project
(the -t refers to your android target which you can find by doing
android list avds):
By the end of these instructions, you should have a copy of an app
called HelloPhoneGap on your phone which, when clicked, shows a
‘Hello World’ screen.
Setup CLJS
Follow the simple instructions,
recreated here because they’re just so simple.
$ git clone git://github.com/clojure/clojurescript.git
$ cd clojurescript
$ ./script/bootstrap
That’s it. The CLJS compiler and REPL are ready to work.
Get HelloWorld working via HTML
Follow the
instructions
under the heading Using ClojureScript on a Web Page to build a
Javascript file and associated HTML file for testing.
Put CLJS and PhoneGap together
OK, let’s make something a little interactive on the phone. I’m going
to build a BMI calculator that takes a person’s height and weight in
Imperial (i.e. American) units and calculates a Body Mass Index. BMI
is simply weight divided by the square of height, with units of
kg/m2.
Basically, we create simple functions to convert Imperial heights and
weights to metric values, calculate a BMI and then use displaybmi to
parse form parameters, calculate the BMI and show that result in an
Android notification popup. alertDismissed is a callback that gets
called when the user dismisses the notification. (I’m just discarding
the information here). Those are the only 2 functions that are needed
by the HTML file, so those are the only 2 that need the :export
metadata tag. navigator.notification.alert is a PhoneGap API call
that does the actual notification.
The calls prefixed by js/ are understood by the CLJS compiler to
refer to the global JavaScript namespace. If you didn’t include that
prefix, the compiler would assume you meant a call in the local
bmi namespace, which would obviously fail.
Here’s the HTML file (in HelloPhoneGap/assets/www/):
The :simple value for optimizations and the true value for
pretty-print make it so that we can read the resulting JS file, but
can be changed to :advanced and false respectively when ready for
production.
Now, go back into the HelloPhoneGap Android project and compile it and
send it to the emulator (C-c C-c i in emacs). You should now have a
simple BMI calculator working on Android.
BMI Android Screenshot
Next steps
The promise of PhoneGap is that you could use similar HTML/Javascript
to create iOS versions as well, but I haven’t done that yet. There are
tons of API calls available on both platforms which are supposed to
give you the same access that native apps have. Using ClojureScript
means you get to use a modern functional language to create your app,
while getting access to the features that only JavaScript APIs
provide.
I have an ASUS eeePC 1000, running Ubuntu 10.10. Wireless worked
flawlessly at home, which is where I use it 99% of the time. On our
most recent trip, however, it wasn’t working. It couldn’t connect to a
WPA-secured network. Here are the relevant error messages:
NetworkManager[770]: <warn> Activation (wlan0/wireless): association took too long.
NetworkManager[770]: <warn> (wlan0): link timed out.
NetworkManager[770]: <warn> Activation (wlan0) failed for access point (linksys)
NetworkManager[770]: <warn> Activation (wlan0) failed.
NetworkManager[770]: <info> (wlan0): deactivating device (reason: 0).
After a little googling on my phone, I found out that others had this problem with the rt2860sta wireless driver. Fortunately,
there is a solution, which involved downloading the source code for
the latest driver, modifying it a bit and rebuilding the driver. Here
are the instructions:
vinod@ike:~/test/driver $ sudo make install
vinod@ike:~/test/driver $ sudo depmod -a
vinod@ike:~/test/driver $ sudo modprobe rt2860sta
```### Step 6: Fix problems with hibernation
A separate problem is that wireless has been flaky when the computer
wakes from hibernation, but [it's also fixable](http://www.twentyways.com/2010/11/19/fixing-wireless-issues-with-asus-eeepc-1000he-running-ubuntu-10-10/).
Add the following lines to `/etc/modprobe.d/blacklist.conf`:
blacklist rt2800pci
blacklist rt2800lib
blacklist rt2x00usb
blacklist rt2x00pci
blacklist rt2x00lib
Create a new file called `/etc/pm/config.d/unload_wireless` with the following line:
SUSPEND_MODULES="rt2860sta"
Reboot and you should have WPA-compatible, hibernatable wireless.
### References:
1. [rt2860sta driver installation](http://www.ctbarker.info/2010/05/ubuntu-1004-wireless-chipsets-and-wpa.html)
2. [Proper hibernation](http://www.twentyways.com/2010/11/19/fixing-wireless-issues-with-asus-eeepc-1000he-running-ubuntu-10-10/)
3. [Ubuntu Forums thread](http://ubuntuforums.org/showthread.php?t=1476007)
Have you ever been in one of those dreams where everything seems
normal and then a flying car (or something equally crazy) comes out of
nowhere? I’m used to having experiences like that when I’m dreaming,
but it was quite surreal to have it during waking hours.
Mala and Kavi had gone ahead (surreptiously to plan a surprise party
for someone else!). We were to meet at the ferris wheel at the Navy
Pier. I found her and she took my hand. She started leading me through
the crowds of tourists. I could sense excitement in her demeanor, but
didn’t think anything of it. She led me towards a group of people and
I caught a glimpse of someone who looked like my Dad. That’s
weird… why would he be here? It’s at that point that neurons started
to malfunction and I began to feel like I was in a dream. Then I saw
Mala’s mom and got even more confused. Slowly the group of strangers
came into focus and revealed themselves as my friends and family from
around the country. It was, without a doubt, the best birthday present
that I have ever received, or expect to receive. Thanks to Mala for
months of planning, and for wanting to make me feel special even
though I feel this way every day when I wake up next to her. Thanks to
all my friends and family who could make it and to the ones who
couldn’t. If this is the culmination of 40 years on this earth, I
can’t wait for the next 40!
I have just had the most amazing Italian meal that I’ve had outside of
Roberto’s in the Bronx. Mala made fresh homemade Pappardelle and a
Bolognese sauce that she just learned at
Revolution’s cooking class. The
thing is, she made this yesterday, and I just tried it today as
leftovers and it was still amazing. This sure is going to make going
lo-carb impossible.
I’m sure it’s probably too early to worry about this, but I often
wonder about the best way to introduce Kavi and Anika to
computers. ‘Introduce’ isn’t the right word because even Anika has
more experience with computers than I did at that age. So far, though,
computers are something that Daddy and Mommy use to do work, not
things that are for them. We’ll show them a Sesame Street video on
YouTube or family pictures on Facebook, but they don’t spend any
significant amount of time on it. They’re easily entertained without
computers. I know that will change as they get older, but for now at
least, they prefer their toys and their imagination to TV or
computers. Even at their young age, that is rare.
The dilemma is that I do want them to learn about technology and learn
how to use it in their lives without being controlled by it. I don’t
see anything wrong with exposing them to things like computers, iPads,
YouTube, etc., as long as it is monitored. I just want it to be a
healthy portion of their leisure time, not all of it. So many
children’s entertainment options are spoon-fed propaganda. They are
meant to be passively enjoyed, and the child just sits and absorbs
it. The source of the content is often questionable. Advertisers for
big corporations or government trying to get their message to kids
either overtly or subtly.
I like my childhood experience. My first major exposure to computers
was an Apple IIe. There was nothing organized about it. I spent a
large majority of my time playing games, but those were just the
gateway drugs to get me to realize that there was much more power in
those machines. The entire experience was about tinkering. Trying
to figure out how it worked, how to make it work for me, how I could
make it do things. The most exciting days in my childhood were the
days that the inCider magazine arrived with pages of DOS code listings
in the back. Retyping those code listings, making alterations, trying
to figure out how things worked… that is much more healthy than just
watching a video over and over again. I, of course, was much older
than Kavi is now, so I’m not too worried. I just don’t want them to
get addicted to a certain concept of what technology is for, before
they have the skills to really take advantage of it.