Intro to Caving in Timpanogos

Tuesday, August 04, 2009

Caving (or Spelunking) is the sport of exploring caves. Yosh and I recently had the opportunity to go on our first spelunking adventure. It was offered at the Timponogos caves in Utah for a group of five. It wasn't quite as dangerous and difficult as it sounds, but it was definitely more than just walking inside a cave. We donned our hard-hats with head lamps before entering the dark hole in the mountain. We were accompanied by a Ranger who knew what he was doing.


We had already taken the regular tour of the cave which in retrospect was dull in comparison to the spelunking experience. The path we took had a pretty low ceiling at many spots, sometimes so low we had to crawl in all fours. At one point we had to descend down the cave through a rock-climbing rope which was exciting. The cave walls were adorned with gorgeous calcite formations. At the end of our path there was a hidden lake (more like a pond really) which had a crystal clear surface. We all turned off our head lamps at this point and experienced the total darkness for about a couple of minutes. This is the kind of darkness that our eyes never get used to. No matter how long you stay in that darkness, it is impossible to detect anything. Experiencing the absence of even a single photon was quite unnerving. It was a lot of fun and definitely worth trying. We are both planning to pursue more spelunking in the future, lets see how deep it takes us.

Picture Time:


All ready to go in



Posing with the ranger



The whole group


Favorite Ted Talks - Part 2

Friday, July 17, 2009

Time to do a Part 2 on my series of Favorite Ted Talks. I've expanded my repertoire since I published part 1 to include talks that are not directly science related.

Benjamin Zander on Music and Passion:

This talk was particularly special to me, since it made me emotional when he played a Chopin piece on the piano. I am not even a piano fan (I am a proud husband of a Violinist), but that music was truly moving. The talk is definitely passionate and it packs a powerful emotional punch.

I assure you, that you'll have a greater appreciation for classical music or even a fan of classical music when you are done with it.

Juicy Bits:

(03:49)"The trouble with you is you're a two-buttock player. You should be a one-buttock player." And I moved his body like that while he was playing. And suddenly the music took off. It took flight.

(10:49) I always tell my students, "If you have a deceptive cadence be sure to raise your eyebrows then everybody will know."

(19:54)"I will never say anything that couldn't stand as the last thing I ever say. "




Learning from the Gecko's Tail:

A very good talk about how Biology and Robotics learn from each other. This might the first step in a world full of possibilities.

Wall climbing robots were made that mimicked a gecko and to the roboticists' surprise they found the robots to be unstable until they added the tails. When they fed this information back to the biologists, they conducted a series of experiments and found out how the tail helped in the gecko's climbing. There are some very interesting video clips of experiments they conducted. I love the part where they put the gecko in a wind tunnel and let it fly.

Evolution is an amazing process.



VS Ramachandran on your mind:

An amazing talk by one of the truly brilliant minds of our time. This is a talk about brain functions, neurology and other wonderful insights into some of the rare malfunctions in the brain. This is the man who cured the pain in a phantom limb with nothing more than a $10 mirror.




His other talk which is much longer and has a little bit of overlap with the ted talk is about the way the brain intercepts Art. This is an absolutely wonderful talk which well worth the one hour. He actually explains why Picasso's art work is beautiful.



Schools kill Creativity:

I saved my most favorite talk to the last, because there is much to talk about and this talk.

First lets begin by saying that THIS is a hilarious talk.
Second his arguments against the current education system, strikes the bulls-eye.
He has such valid points and he conveys them in a very engaging manner.

Juicy Quotes:
There are tons of interesting stories and quotes in this talk and I'll end up copying the transcript of his talk if I went after the juicy bits. So I'll try to reproduce only the quotes that still make sense when taken out of context.

(3:00)"All kids have tremendous talents. And we squander them, pretty ruthlessly. My contention is that creativity now is as important in education as literacy, and we should treat it with the same status."

"If you're not prepared to be wrong, you'll never come up with anything original. And by the time they get to be adults, most kids have lost that capacity. They have become frightened of being wrong."

"We stigmatize mistakes. And we're now running national education systems where mistakes are the worst thing you can make. And the result is that we are educating people out of their creative capacities."




If you've already seen any of these videos, it never hurts to watch it again. It's absolutely worth it.


Biking into a Lake

Tuesday, July 07, 2009

Biking into a lake is not quite the same as Biking around a lake or Biking near a lake, it is orders of magnitude more fun than both of them combined. If you are not familiar with the concept of Biking into a Lake, here's a quick intro:

  1. Take your bike and point it towards the middle of the lake.
  2. Start pedaling as fast as you can.
  3. Go as far as possible into the lake.
  4. Fall into the water (trust me this will happen)
  5. Repeat.
Oh yeah, it is just as much fun as it sounds.



Unfortunately, I can't take credit for inventing this really cool way of biking. It was first proposed by Thad and experimented by Yosh. The honor of being the first test subject goes to Blue lake in Utah located near the famous Mirror Lake.


We had a little bit of warm-up on the puddles on our way to the lake which was totally unintentional, since our lake biking was an improptu idea by Thad once we reached the lake.



The lake had a very mild slope which was very helpful for this art, but it was way too muddy to keep a steady biking pace. The bike tires would sink into the mud making it impossible to restart once we got stuck (and fell into the water). Trying to pull the bike out of the mud resulted in our feet sinking deeper into the mud.

After a few iterations of lake biking, Thad and I decided to go for a swim in the lake. We both managed to go deep enough in that freezing water to reach neck level water.



Can you see the tiny little heads sticking out of the water. We were hoping our bodies would soon go numb. But the water just kept getting colder as we went deeper, I could almost hear my skin cells screaming "Are you f-ing kidding me?". We decided to turn back once I realized I might panic if we kept at it.

One of these days, I'm gonna man up and go all the way.


Partying with the Moon Rock Liberator

Sunday, June 28, 2009

The other day I was reading an article online titled "How an Intern Stole Nasa's Moon Rocks". I didn't give it much thought at the time and moved on with my life. But on the back of my mind I developed a sense of respect to the man who pulled that incredible heist. A couple of days later my wife sent me an email that knocked me off my ass. The basic gist of the email is that her TA is Thad Roberts. For those of you who didn't read the article, he is the master mind behind the moon rock heist of 2002.

I could not contain the excitement once I found out that he is actually meetable (not a real word). Of course my wife managed to get me a little jealous when she wouldn't shut up about him. But I was never happier in my life with my wife's decision to take that Physics class.

Yesterday was the first time I got to meet the man in flesh and bones, in a "Physics" party for the students of that class. To be honest, I was expecting a charming, charismatic, adrenaline-seeking, egocentric, alpa-male and I was right up until the adrenaline-seeking part. He was everything the article described him to be, and a bit more. What the articles missed to mention was that he is actually a really nice guy who is down-to-earth and friendly. A regular guy with a regular life. I had a great time talking to him in the party and to my surprise it was probably the first time I actually enjoyed being at a party.

At the end of the party he recounted the experience of liberating the rocks. I call it liberating because he was only taking the used up rocks that were sitting in a metal safe (not even on display) that bear no scientific value anymore. The story from the horse's mouth was a little bit different from the one I read on the article. Apparently only 30% of the article is true and the journalist filled in the rest with some fluff to make it juicy. He did send me the original article that he personally approved for publication. But listening to the story from him was a lot more fun and interesting. I didn't ask him about a couple of questions about the story, but it was not the time and place, it'll have to wait.

He invited us to join an adventure club that he is putting together, I can't wait :).

Update: Thad has his own webpage with links to his new book (Did I forget to mention he wrote a book on quantum space theory when he was in jail?) that is due to be released soon and a blog with some pictures.


Favorite Ted Talks - Part 1

Thursday, June 11, 2009

I recently got into a Ted.com watching spree and found some great talks (mostly scientific) by some of the top scientists in the world. The amazing thing about the talks is its simplicity and the engaging nature in which the speakers present the topics.

I have a lot of favorite talks and this is my attempt to collate the ones that impressed the heck out of me.

Brian Cox on CERN's Super Collider:

A wonderful introduction of the LHC project by CERN. He covers why it is important to do this experiment and explains in plain english what is a Higgs particle.

Juicy Bits:
(05:42) "All science is either Physics or stamp collecting" - Rutherford

(13:34) "Saturn V rockets and sputnik and DNA and literature and science - these are the things that hydrogen atoms can do when given 13.7 billion years." - Carl Sagan





Brian Cox on What Went wrong at the LHC:

After a year from the previous talk, this one explains what happened in the LHC and why is it not operational right now. His openness about the issue is very reassuring and his argument towards the end of the speech speaks directly to the conspiracy theorists who claimed LHC is dangerous.

Juicy Bit:
He finished his speech with a quote from an English scientist Humphry Davy defending his protege's (Michael Faraday) useless experiments.

"Nothing is so dangerous to the progress of the human mind than to assume our views of science are ultimate, that there are no mysteries in nature, that our triumphs are complete and that there are no new worlds to conquer,"



Charles Elachi on Mars Rovers:

A very engaging talk about the Jet Propulsion Lab. The talk starts with some pictures of the people who started JPL. He explains how the paradigm shifted in JPL from a rocket launching facility to an exploration house. He shares some gorgeous pictures from Mars and covers a little bit of the Saturn's rings and its satellites Enceladus and Titan. Very interesting (funny) stuff .

Juicy Bits:
(1:40) "Do not go where the path may lead. Go instead where there is no path, and leave a trail." - Ralph Emerson

(1:50) "Don't try to improve a little bit on what somebody else is doing, because that doesn't get you very far."

(5:29) "We started from those stars; we are made of stardust. So, next time you are really depressed, look in the mirror and you can look and say, hi, I'm looking at a star here. You can skip the dust part."

(9:27) "Well, I always say it's important that you are smart, but every once in a while it's good to be lucky."

(27:09) "So if you were on Titan, you don't have to worry about four-dollar gasoline. You just drive to the nearest lake, stick your hose in it, and you've got your car filled up. On the other hand, if you light a match the whole planet will blow up. "





Brain Greene on String Theory:

A great talk that explains the String Theory in a perfectly lucid way. The concepts presented in this talk are mind-bending and almost like a mystery-novel. There are stories of scientists trying to come up with the Grand Unified Theory and the role of multiple-dimensions that help in achieving that goal (right now scientists predict 10 dimensions). Once again LHC will be instrumental in proving the existence of these extra dimensions, thus validating the String Theory.

Juicy Bits:
(5:40)"Kaluza was a man who took theory very seriously. There is a story that when he wanted to learn how to swim, he read a book, a treatise on swimming then dove into the ocean. This is a man who would risk his life on theory"



I am sure I'll come across more of these talks that'll trip my brain and I'll make sure to share them.


When did we forget our dreams?

Tuesday, June 09, 2009

Whenever I write something controversial in my blog and contemplate about hitting the publish button, I think of the following XKCD comic.



"There is not fate but what we make for ourselves" - from XKCD.


Algorithm for Incremental String Search

Wednesday, June 03, 2009

Incremental string search is a feature that is available in almost all of the recent editors/browsers. It is also known as find-as-you-type in layman terms.

Typically a string search involves getting the search term from the user and matching it against each string in the input array to find the match. Incremental search tries to do partial matching as soon as a character is pressed. The results are narrowed down for each key that is pressed.

Given a set of strings as input, lets see how we can implement incremental search to narrow down our result.

Conditions to satisfy:
  1. When no character is pressed, the search result must contain all the strings from the input.
  2. When a character is pressed, the search result must be the sub-set of the previously shown search result.
  3. When backspace is pressed we include new strings from the input set to the search result which satisfy the new search term.
  4. When a new character is pressed that doesn't match any of the strings in the input set, the search result must be empty.
Algorithm:
  1. Initialize the array (or vector) of strings (in_array) which will be incrementally searched.
  2. The search_term is a string which is empty to begin with. This string will grow/shrink depending upon users input.
  3. 'cursor_pos' keeps track of the position of the current cursor.
  4. 'pos' keeps track of the position of the character that will be checked.
  5. 'possibles' is a stack that holds an array of integers. The integers in the array point to the matching strings in the 'in_array'. The bottom of the stack always has all the indexes of the "in_array". The top of the stack has the latest indexes that match the search_term.
  6. loop until ESC is pressed.
    1. Get a character and store it in 'ch'.
    2. If the character is not a backspace or ESC add it to the search_term and increment cursor_pos.
    3. If character is ESC break out of loop.
    4. If character is back-space, remove the last character from the search_term, decrement cursor_pos (make sure cursor_pos is never negative). Pop the stack to remove the top most search result.
    5. look_for the strings in 'in_array' that has the character 'ch' at location 'pos'. Add the indices of the strings that match, to a vector and push the vector into the 'possibles' stack. If no strings match the character, then push an empty vector into the stack.
    6. Get the top of the stack and print the strings that are referenced by the indexes.
  7. END_PROGRAM.


Algorithm Animation:

The animation below shows the state of the data-structures when the algorithm is running.

Code:
The algorithm described above was implemented in C++ using STL libraries and ncurses. 'ncurses' is a unix library for designing command-line interfaces. It is mainly used in this project to read the character as we type it, so replacing it with a windows equivalent will work just as well. The code is uploaded on GitHub for download.

Caveat:
  • The goal of the code is to demonstrate the incremental search algorithm, it cannot be used as a drop-in library to include in a software.
  • It doesn't capture every scenario of the incremental search. Eg: If a user deletes the first character in the search term the code can't handle it.


Gay Marriage - A Rambling

Sunday, May 03, 2009

I had the most unpleasant conversation with an acquaintance the other day. He is a conservative person with thoughts that Gay Marriage is unnatural and probably a sin. I don't know why he felt it is necessary to share that with me, but I was dumb-founded by his arguments. I didn't really have the heart (or courage) to tell him that I'd probably vote yes to legalize gay marriage.

But later when I pondered about the subject of sexual choices, I realized I had no clue about them whatsoever. Of course, I have no problems with people being gay and two man or woman wanting to marry. I definitely don't think it is a sin, but what is the reason for a person's choice to be gay. Is it is a life-style choice? or Is it a genetic construct?

I've never had a friend or a family member who is openly gay, so I don't know their thought process. So I can't really agree to people's arguments that it is just a thought it can be overcome by prayer and discipline. What if it is more than that, what if it is not in the control of the person to choose his/her sexuality?

But this also begs the question, why are a lot of people averse to gays? Lets forget the religious people and consider the non-religious ones. Why are they so afraid of accepting the concept of homosexuality? Once again, could it be genetic construct that makes them unable to accept this concept? Are they afraid that a wide-spread acceptance of homosexuality might hinder the process of procreation thus resulting in the extinction of human race? Is there an evolutionary reasoning behind the hostility towards gays?

I did feel a bit shameful that I didn't speak up to voice my opinions that day.


Autoconf and Automake Tutorial

Saturday, May 02, 2009

I wrote a charming little utility for linux called getkey, that captures the keystrokes and displays them on the screen using OSD. Its called gekey and t has a couple of .c files and a hand crafted Makefile to go along with it.

But I wanted to use the auto-tools (autoconf and automake) to create a configure script and a Makefile so that my utility could by installed like any other GNU tool using the famous:

./configure && make && make install

When I went hunting for autotools tutorials, they were too elementary (based on a hello.c, with no dependency check) or too long, 100 page books on autotools.

My program has a couple of dependencies (xosd, Xtst, X11) and it is small enough to understand. So I decided to use this program to write a quick and dirty tutorial for autotools, with dependency checks.

These are the steps I followed to achieve that and here are the files that I'll be using for this example. getkey_example.tar.gz

Required Tools:

Make sure the following tools are available on the system, before getting started.

tar
make
aclocal
autoconf
automake

This tutorial is based on autoconf ver 2.63.

Setup:

In order to generate the configure script and the Makefiles, we need to define a set of rules and dependencies. This is done via two files 'configure.ac' and 'Makefile.am'.

Generating the configure script:

1. Leave the default Makefile in the project folder and run 'autoscan'. It will create a vanilla configure.scan file.

2. Now move the Makefile to a different place (so it doesn't interfere with the autogenerated files in future).

mv Makefile ../.

3. Rename configure.scan to configure.ac (this used to be configure.in for old versions, it is deprecated now).

4. Edit configure.ac and modify these lines.

WAS:
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
IS:
AC_INIT([getkey], [0.1], [email-address])
WAS:
# FIXME: Replace `main' with a function in `-lX11':
AC_CHECK_LIB([X11], [main])
# FIXME: Replace `main' with a function in `-lXtst':
AC_CHECK_LIB([Xtst], [main])
# FIXME: Replace `main' with a function in `-lxosd':
AC_CHECK_LIB([xosd], [main])
Chose one function from each of the libraries used in the program and replace 'main' with the function name. Any one function is enough to verify a library.

IS:
AC_CHECK_LIB([X11], [XOpenDisplay], [],[
echo "X11 library is required for this program"
exit -1])
AC_CHECK_LIB([Xtst], [XRecordCreateContext], [],[
echo "Xtst devel library is missing. Xtst is required for this program"
exit -1])
AC_CHECK_LIB([xosd], [xosd_create], [],[
echo "xosd devel library is missing. xosd is required for this program"
exit -1])
SYNTAX:
 AC_CHECK_LIB([libname],[func-name],[action-if-found],[action-if-not-found])
The line breaks are essential in the fourth parameter to the function AC_CHECK_LIB(). This is to make sure that configure script will exit when it can't find a dependency.

5. In configure.ac check for the line that has AC_CONFIG_FILES(). This tells the autoconf tool what are the output files. It should typically be

AC_CONFIG_FILES([Makefile])

6. Run autoconf.

autoconf

This will create the first version of configure script.

Generating the Makefile:

1. Add this line to the configure.ac
AM_INIT_AUTOMAKE([getkey], [0.1])
This instructs automake to generate makefiles after the configure script is run.
This will also define two constants PACKAGE(=getkey) and VERSION(=0.1) during make. This can be used in the code to display version specific print outs.
If you don't have a config.h file for configuration, then comment out the line: (I didn't use this in getkey)

AC_CONFIG_HEADERS([config.h])
2. Create a file named Makefile.am and add these lines.
AUTOMAKE_OPTIONS = foreign

CFLAGS=-Wall -I/usr/local/include -DVERSION=\"$(VERSION)\" -DPROG="\"$(PACKAGE)\""
LDFLAGS=-L/usr/local/lib -lX11 -lXtst -lxosd

bin_PROGRAMS = getkey
getkey_SOURCES = getkey.c circ_list.c

The first line AUTOMAKE_OPTIONS = foreign is to let automake know that it is not a standard GNU package.
A standard GNU package requires certain folders and files to be present, such as doc, src, INSTALL, COPYING, etc.

The CFLAGS and LDFLAGS is copied from the current Makefile that we moved to a different location.
bin_PROGRAMS = getkey is the name of the resulting executable.
getkey_SOURCES = getkey.c circ_list.c, this is the list of sources that will compile to result in getkey. List all the source files here.

If you have more than one resulting executable you can do
bin_PROGRAMS = prog1 prog2 prog3
LDFLAGS=-L/usr/local/lib -lX11 -lXtst -lxosd

bin_PROGRAMS = getkey
getkey_SOURCES = getkey.c circ_list.c
3. For our grand finale we run these commands

aclocal autoconf automake -a

aclocal is a tools that generates aclocal.m4 based on the configure.ac file which is used as an input to the autoconf tool.
autoconf will generate the configure script and automake takes Makefile.am as input and creates Makefile.in.
Now we have the final version of our configure script.

Ready to go:

1. Test out the configure script and the Makefile.

./configure
make

2. Create a package. Now that everything is working as expected, we can create a package for distribution.

make dist

This will create a tar.gz file with the package name and version number. Now it is ready for release to the world. Here you go getkey-0.1.tar.gz.

References:
http://sourceware.org/autobook/autobook/autobook_toc.html#SEC_Contents
http://www.amath.washington.edu/~lf/tutorials/autoconf/toolsmanual_toc.html
http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/


Learning Haskell - II = My Haskell Devel Tools and Resources

Saturday, April 25, 2009

My primary development environment at home is Linux (sometimes BSD). I do have Windows as a dual-boot (is it still dual-boot when you are running running more than two), but even when I am in windows, I develop in linux using andLinux, a variant of Linux that runs natively in a windows environment.

I use GHCi as my Haskell interpreter, since this seems to be the most standard compliant and the Haskell tutorial I am using is targeted around GHCi. My primary editor for writing programs is Vim and I use Github for storing my nasty little code snippets. I realize using git for this learning is probably an overkill, but I am a git n00b and there is no better way to learn git than just diving right in.

Even though I follow Learn You a Haskell(lets call this "LYH" in the future) tutorial, I do visit one other famous tutorial Real World Haskell everynow and then, when I am confused by a concept.

I think two posts without any code is probably an overkill for a blog series that is titled "Learning Haskell". So in my next post, I'll go over the first few chapters presented in LYH tutorial and share some code that I tried out.


New Look and Feel....

Tuesday, April 21, 2009

Boy was I pleased to get this over with. Its been on my list of todo for a long time to give my blog a much needed overhaul. I hated the fixed width blog template with a passion. It would render just fine on smaller screens, but on the latest widescreen monitors, the white space on both sides of the blog was proving to be a criminal waste. Hence this new look and feel.


A new fluid template that uses the screen real-estate more efficiently. Hopefully my loyal reader *ahem* won't feel repulsed by my choice of colors. Hey I am aiming for better functionality not more shiny, so deal with it. :) But seriously, if I've made a serious faux pas that impairs the redability, feel free to diss me in the comments. I am nothing if not flexible.

Update: As one of my loyal readers (my lovely wife) pointed out, the comment system was broken. She construed it as a plot to prevent people from commenting about the layout's awesomeness, but it was just a side-effect of the template change which broke my comment system. It is fixed now, thanks to BloggerBuster.


Learning Haskell - Part I

Saturday, April 11, 2009

Learning haskell has been nothing short of an adventure for me so far. I love that is so different from the regular old C/C++. It's been a very long time since I've learned something refreshingly new. I usually spend about an hour or two on the nights to learn haskell and on those days I go to bed with a big grin and a satisfaction that you can only get when you've learned something truly refreshing.

I got roped into this by the myriad of comments found online raving about its simplicity and power. This one in particular by the creator of Haskell - (paraphrased) "Learning a functional programming language will make you a better imperative programmer" pushed me over the edge.

Now the reason to choose Haskell in particular is because it was notorious for being purely functional. It is one of the goals of the language to stay purely functional. Apparently it is really hard to write imperative style programs in haskell. Plus there is the much touted #haskell irc channel which has some of the friendliest haskell experts who are tolerant to newbies.

I started with the "Learn You a Haskell for Greater Good", it is a free online book for haskell that has some pretty pictures and presents the subject in a non-scary way (yes I scare easy). Haskell is so different from any of the languages I've known before, so it is only fitting that the tutorial itself doesn't fit the conventional programming tutorial's style. It doesn't waste time on how to write the infamous "Hello World!" program which IMHO is an incredibly useless excercise.

I've gone through the first few chapters so far and I decided to take it slow and try out every example given in the book (which btw, is a lot of code snippets). Since there aren't any exercise problems in this book, I decided to start solving Project Euler problems using Haskell. I am going to start recording my thoughts about Haskell as a series in this blog. I believe this series will keep me motivated to dedicate more time to learn Haskell and keep writing about my experiences.


Pre-Standard Function Definition in C or Non-Standard Syntax for Function Definition in C

Thursday, March 19, 2009

void function_name(var1, var2)
int var1
float var2
{

}
This is a little known syntax for function definition in C that can throw people off sometime. I was stumped when I first saw this in the source code for zlib library. I didn't know how to search in google to look up more info about this type of syntax. These are called pre-standard function definition syntax.

Most people are familiar with the standard function definition syntax in C which looks like
void function_name(int var1, float var2)
{

}
But some pre-historic C compilers can only handle function definitions in the following format.
void function_name(var1, var2)
int var1
float var2
{

}

The modern C compilers will support this pre-standard syntax for legacy purposes, but if you try to compile this with a C++ compiler, you won't be successful. This is one of those features of C that C++ decided not to support.

If you are using gcc to compile a piece of software and you are still getting this error, then you might want to check your compiler flags to see if there is a -x flag in the list. This flag is used to specify a language to the gnu compiler collection. So if you have '-x c++' that means you are using gcc to compile the code as C++.

If you are trying to compile zlib as a part of your C++ project, don't be surprised if you are presented with a plethora of errors, it is because zlib is written in C and they've used these pre-standard syntax to make it compatible with legacy C compilers, thus making it unusable with c++ compilers.

I am sure there is a way to still include it in a C++ project and I'll write about it as soon as I find out how to do it :).


Feynman's Autobiography: A Fantastic Read

Tuesday, January 20, 2009

I recently finished reading Richard Feynman's autobiography called "Surely You're Joking, Mr. Feynman!". I've never been fond of reading anything more than a page on my computer screen, but this was an exception that caught me by surprise. I found interesting insights in to the mind of a great Physicist. It had some fun anecdotes and some deep thoughts which inspired me.

Feynman is a nobel laurete who is lauded by Neils Bohr himself.

"Remember the name of that little fellow in the back over there? He's the only guy who's not afraid of me, and will say when I've got a crazy idea. So next time when we want to discuss ideas, we're not going to be able to do it with these guys who say everything is yes, yes, Dr. Bohr. Get that guy and we'll talk with him first."
The little fellow that Neils Bohr is refering to is Richard Feynman.

I collected some interesting sentences from that book (or article) that inspired me a lot.
"You have no responsibility to live up to what other people think you ought to accomplish. I have no responsibility to be like they expect me to be. It's their mistake, not my failing."
This is the care-free attitude that enables a person to work on things that truly interests them.

The following quote struck a chord with my current state and I immediately realized what I was missing all these days.
"Physics disgusts me a little bit now, but I used to enjoy doing physics. Why did I enjoy it? I used to play with it. I used to do whatever I felt like doing -- it didn't have to do with whether it was important for the development of nuclear physics, but whether it was interesting and amusing for me to play with."
I had great passion for programming. But the jobs I've had since my graduation has made me doubt my abilities as a programmer. They weren't interesting enough, and I wasn't writing code that pushed my limit. I had more fun tweaking my editor (emacs and Vim) than writing "production" code.

Once I realized all of this from his autobiography, I decided to write code at my spare time for the pure joy of hacking. I started a tiny little key-grabbing tool that can be used in screencasts to display the current key that is being pressed. To put it in Feynman's words:
"It was effortless. It was easy to play with these things. It was like uncorking a bottle: Everything flowed out effortlessly."
This has set in motion an unexpected series of events, I am working on multiple projects on my spare time. I don't care if my projects have any monetary value, if I end up making some money that will be a completely unintentional side-effect :).

But not all of his chapters are about his work and thoughts on research. He gives pretty good advice about picking up women and gives on "how to get lucky". Too bad, I won't be needing them ;)
"We went into the bar, and before I sat down, I said, 'Listen, before I buy you a drink, I want to know one thing: Will you sleep with me tonight?'"
Apparently this is something that he learned from an MC at a bar in New Mexico. It worked for him in more than one occassion.

There are a lot more stories in that article that are fun to read. It is available for free online.


Setting Up an Experimental Verison of Your Site Using Multiple Databases in Django

Sunday, January 18, 2009

I recently started experimenting with Django as a learning experience. My friend and I created a nice little rss aggregator and decided to host it via DreamHost. Developing on my local computer was a piece of cake using the test server that comes with Django. But when we decided to move the setup to the hosting system, we faced our first obstacle, getting Django working on DreamHost. We followed some good tutorials here and here to get the initial setup ready.

But when we decided to setup a development version of our site (lets call it http://experiment.mydomain.com) we weren't sure how to configure Django so that we can have multiple databases and try some crazy things before pushing it to our production version. We did eventually figure it out, so here are some steps that might help fellow DreamHosters using Django.

First create a sub-domain for experimental purposes using DreamHost's administration panel. Make sure you enable FastCGI support for the sub-domain as well. I chose http://experiment.mydomain.com. Now ssh into your DreamHost server and there should be a folder for your new sub-domain in the home directory of your account.

I have my django installed under $HOME/django/src. The projects directory structure is as follows:

$HOME/django/main/projects/prj1 -- This contains my production code.
$HOME/django/devel/projects/prj1 -- This contains my experimental code, just copy over the files from the main directory into this one to begin with.

This way when I decide to launch multiple domains under my account, each one will have its own main tree and a corresponding devel tree.

Now lets configure the domains:

If you've followed Jeff Croft's Django setup tutorial, you'll have two scripts in your $HOME/mydomain.com folder. Which might look like the following:

#!/usr/bin/python2.4
import sys
sys.path += ['/home/amjith/django/src']
sys.path += ['/home/amjith/django/main/projects']
sys.path += ['/home/amjith/lib/python2.4']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'prj1.settings'
WSGIServer(WSGIHandler()).run()

Copy this file into the new sub-domain $HOME/experiment.mydomain.com folder and change it to match the devel folder path.

#!/usr/bin/python2.4
import sys
sys.path += ['/home/amjith/django/src']
sys.path += ['/home/amjith/django/devel/projects']
sys.path += ['/home/amjith/lib/python2.4']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'prj1.settings'
WSGIServer(WSGIHandler()).run()
Create a new database from DreamHost administration panel. Go into the devel folder and change the settings.py file to point to the new database name. Everything else should be the same. Now the next step is to do a syncdb in the devel branch. But before you do that check what the $PYTHONPATH variable points to and change it to the devel branch.
$ echo $PYTHONPATH
/home/amjith/django/main/projects:home/amjith/django/src
$ export PYTHONPATH=/home/amjith/django/devel/projects:home/amjith/django/src
Now you are ready to do a syncdb in the devel branch.
$ django-admin.py syncdb
Now, you are ready to check http://experiment.mydomain.com/admin/ and make appropriate entries to the database and start experimenting.

Summary:
  • Directory structure:
    • $HOME/django/main/projects/prj1 -- Main tree
    • $HOME/django/devel/projects/prj1 -- Devel tree
  • Create a new sub-domain from DreamHost administration panel
  • Create a new database from DreamHost administration panel
  • Domain directories:
    • $HOME/domain.com/dispatch.fcgi -- points to the main tree
    • $HOME/experiment.domain.com/dispatch.fcgi -- points to the devel tree
  • Modify settings.py in the devel tree to point to the new database
  • Change the PYTHONPATH environment variable to point to the devel branch
  • Do a syncdb in the devel branch:
    • django-admin.py syncdb
You are in business.


Running make (Compiling) From Vim

Monday, December 29, 2008

My biggest complaint about Vim since I switched from Emacs is the inability to open a command shell inside the editor. I like to run 'make' or do some other mundane activity in the command line without having to exit my editor. It is possible to at least compile the source using make without leaving Vim. It also comes with the benefit of jumping to the errors in the code.

Commands to remember:

:make - This will run the regular old make in the command line for you.
:copen - Opens the quickfix window, to show the results of the compilation. Opens the window even if there are no errors in compilation.
:cw[indow] - Opens the quickfix window only if there is an error. If quickfix window is open and there are now errors, the window is closed.

Double click or press enter on the error in the quick fix window to take you to the corresponding error in the source code.

:cn - Goto the next error in source code.
:cp - Goto the previous error in source code.
:cfirst - Goto the first error in source code.
:clast - Goto the last error in source code.

For the sake of convenience I've mapped the keys 'cn' and 'cp' to :cn and :cp. So instead of typing <esc>:cn<enter> to jump to the next error I can just type cn and it'll take me to the next error in the editor.

It can be done through .vimrc by adding these two lines:
map cn <esc>:cn<cr>
map cp <esc>:cp<cr>


Regex in Vim

Thursday, December 18, 2008

Regular expressions are the perhaps the most powerful tool to unix admins, programmers and most importantly Vim users. I am somewhat familiar with the Perl version of regex, but the regex used by Vim for its search and replace has some subtle differences which threw me off a bit.

Here are some examples that demonstrate the differences:

Input String: abc123def

1. Match one or more digits after 'abc'


PerlVimSelection
/abc\d+/ /abc\d\+ abc123

2. Match exactly 2 digits after 'abc'

PerlVimSelection
/abc\d{2}/ /abc\d\{2} abc12

3. Search & Replace 'abc' followed by digits with just the digits

PerlVimOutput
s/abc(\d+)/$1/ :s/abc\(\d\+\)/\1/ 123def


There are excellent tutorials on Regex for Vim :

http://www.vim.org/htmldoc/pattern.html
http://www.softpanorama.org/Editors/Vimorama/vim_regular_expressions.shtml
http://www.geocities.com/volontir/

Bottom Line: Escape the special characters in Vim regex and you'll do fine.


Writing a Linked List in C

Friday, December 05, 2008

Have you ever tried to multiply two 3 digit numbers using a pen and paper to find out that you aren't as glib at this art as you once used be? I had that experience a couple of years ago which shocked me a little bit.

Recently I had a very similar experience. I was writing a piece of code at my spare time and I was doing it in C. A little background about my education, I have a masters in Computer Science and I have been writing code for a living for the past 4 years. Back to my little project. Since C doesn't have the fancy STL libraries, I had to write the data-structure that I needed from scratch. I had to implement a Linked List and I was stumped. I knew the concept behind the linked lists and I know exactly the cost of every operation in the linked list, but when it came to writing one from stratch I was struggling to get it working at my first attempt. I realized how spoiled I've become by these fancy new libraries and languages. I did manage to get an ugly hacked version working in a couple of hours. It took me an additional couple of hours of coding and re-factoring to finally get it to a state where I was satisfied by my creating.

It was such a humbling and character building experience.


Review of PC-BSD 7

Friday, October 03, 2008

I posted my first full-length article in OSNews. It is a review of PC-BSD 7 which I am currently running on my desktop at home. PC-BSD is a fantastic OS and many thanks to Vijay for kindling my interest in this OS.

Writing the article wasn't too bad. It took me less than 3 days to do it. But after I finished it, I felt I could've written it differently. For some reason when I was proof-reading I felt it was too rigid, it didn't sound like my writing at all. I need to stop worrying about being correct and just blurt out what I think. (Note to self: Be relaxed when writing articles).

Now that it is up on the OSNews site, I can't help myself logging into the OSNews backend to check every hour to see how many readers I've managed to amass :). When I first published it this morning, it got a whopping 500 hits in 30mins. Looking at those numbers made me giggle with happiness. Its an amazing feeling when you know that someone is interested in hearing what you have to say.


8 Things I Want in Chrome

Thursday, September 11, 2008

There are plenty of reviews for Google Chrome which talk about the V8 JavaScript engine, webkit and other internal improvements, but this is an attempt to look at Chrome on the surface as a normal user who just switched from Firefox 3.

I replaced Chrome as my default browser after a mere 10minutes of playing around with it. I have been burned multiple times by a misbehaving tab that brought down my browser, so the ability to kill an individual tab was the selling point for me. I was thrilled by the responsiveness of the browser, it is nice to see an application that is actually snappy. It was simple (perhaps too simple) to use and easy on the eyes.

Before I bitch and moan about what I want in Chrome, it is only fair to list some things I immediately liked about it.

Things I like:
There are so many subtle UI conveniences that demonstrate the level of attention to detail that went into making Chrome.

Keyboard Shortcuts: They've borrowed most of the keyboard shortcuts from Firefox which made the transition smooth.
Ctrl + L - Puts the cursor on the location bar (omnibar)
Ctrl + E or Ctrl + K - Puts the cursor on the omnibar and switches the omni bar into a search state (a question mark in front of the query).
Ctrl + Shift + T - Re-open the recently closed tab (undo close tab)
Ctrl + Enter - Automatically fills the www. and .com at the beginning and end of a word in the omni bar.
Alt + Enter - Type a search term or URL in the omnibar and press Alt+Enter to open the result in a new tab.
Ctrl + Tab or Ctrl + Pg Up/Dn - Switch tabs

Find: The find system is very intuitive. It is incremental and it automatically highlights all occurrences of a word in the page.

Things I want in Chrome:
  1. A lot of people complained about the absence of AdBlock in Chrome. I don't care much for blocking ads, but it gets important if the websites are running Flash ads. The memory hog can be noticeably large if you have multiple tabs with flash ads. I'd at least like to have the ability to turn off certain flash elements on a page without having to kill the flash plugin for the whole browser.
  2. The sub pages that get opened out of Google reader act like a child process. This makes it impossible to kill individual pages that the Reader has spawned off. So if a page in that group misbehaves, then I'll have to kill the whole group.
  3. No provision to delete selected entries from history. I don't want to purge the history every time I want to delete just one entry.
  4. Scrolling a page using the mouse seems jumpy in Chrome. I constantly find myself trying to locate my last sentence after a scroll move to continue reading an article. Smooth scrolling might help here.
  5. The current method of page zooming (Ctrl ++ or Ctrl + Mouse Scroll) only increases the text-size. All other elements in the page (formatting, images) remain the same which makes the page look ugly. Firefox 3 does a good job of zooming the whole page (including the images). Here is an example:
  6. Page View: Regular Size

    Page View: Zoomed in Chrome

    Page View: Zoomed in Firefox 3

  7. I like the about:plugins and the about:memory. I feel like they should have a about:config for power users to tweak more.
  8. Create exceptions to pop-up blocker. I don't want to click the pop-up block notification every time to see the pop-up window in a website that I trust.
  9. A way to search my bookmarks will be a nice addition to the whole package.


Core Dump. 2008 One Winged Angel.Bloggerized by : GosuBlogger