Fresh installation of Ruby, Rails, Git, RubyGems, and Postgresql 8.x

Most people need to do this only when they get a new system. I had to go through this to help out a potential brogrammer, and it would have been much easier if I pointed him to one place where he could just following direction. Instruction here applies to Mac OS X 10.6.x.

For Windows users, use the convenient installer done by guys at EngineYard from here (http://railsinstaller.org/) to install Ruby, Rails, etc., and installer from Postgres from here (http://www.postgresql.org/download/windows/) to install Postgresql.

1. Install Xcode

Xcode is included in the Mac OS X install disc. You can install from the DVD or you can down load it from here,
http://developer.apple.com/xcode/. If you already have xcode installed, you are good to go.

2. Install Git

Download and install git if you don’t have one already. Do the following and see if returns a version.

git --version

Best place is to go here (http://git-scm.com/), and download and install the latest stable release.

3. Install RVM and Ruby

RVM lets you manage set of gems for Ruby/Rails version combination. This is the best way to install Ruby and Rails. Follow the link below and install RVM and Ruby version 1.9.2 (which is latest, stable version as of this time).

curl -L get.rvm.io | bash -s stable --ruby

3.1. Then, update the .bash_profile (or whatever shell profile or rc file you need)

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

3.2. Reload the shell.

source ~/.bash_profile

3.3. Test to see if installation was successful.

rvm list known

3.4. Install Ruby 1.9.2 (or 1.9.3)

rvm install 1.9.2

3.5. It’s probably a good to set 1.9.2 as default as well.

rvm use 1.9.2 --default

4. Install RubyGems if not already installed

Doing the following command in terminal and see if it returns version number.

gem -v

If it doesn’t return a version number, follow the steps below to install RubyGems.

4.1 Download the latest stable version from here (http://rubygems.org/pages/download)

4.2 Unzip and Install

tar xzvf rubygems-1.X.Y.tgz
cd rubygems-1.X.Y
sudo ruby setup.rb

5. Configure RVM gemset

Now, you have to actually make a choice whether you want to install the latest version 3.1 or the one before 3.0.x. If you just do gem install rails, it will install 3.1. I am sticking with 3.0.10 for a little longer, since that’s what I am used to. But, if you are starting new, you should just install 3.1. When you search for code examples online, make sure it’s for 3.1, since 3.1 is quite different from 3.0.x.
rvm gemset create rails31

Also set default gemset.

rvm use 1.9.2@rails31 --default

6. Install Rails

Depending on what you decided above,

gem install rails -v 3.1.0

7. Install Postgresql 8.x

I’ve used MySQL mostly before, but after Oracle’s purchase of MySQL and since I deploy most of my apps on Heroku, which only supports Postgresql, I have been using Postgresql for quite sometime. For typical Rails app, it shouldn’t matter whether you use MySQL or Postgresql. You need to be careful when you need to write raw SQL statement. Postgresql is known to be more strict with the syntax.

Latest Postgresql is 9.x, but I believe pg gem only supports up to 8.x. Better stick with safe version.  Follow the link below to download and install Postgresql 8.x. Remember the admin username and password.

http://www.enterprisedb.com/products-services-training/pgdownload

pg gem will be installed when you create a Rails app with

rails new [APP NAME] -d postgresql

and install gems with

bundle install

8. Configure Postgresql for Rails

The most you have to configure is to create a user and password for each app.

8.1 Login as admin (whatever admin username you picked when you installed the Postgresql)

psql -U admin

8.2 Create a username and password for your app.

create role [USERNAME] with createdb login password '[PASSWORD]';

You would use the username and password you just created in /config/database.yml file in your Rails app.

(org.mongodb.mogod) Exited with exit code: 100

For some reason, I couldn’t run mongo shell and the console was overrun by the same error message like the following.

8/1/11 6:49:15 PM com.apple.launchd[1] (org.mongodb.mongod) Throttling respawn: Will start in 10 seconds
8/1/11 6:49:25 PM com.apple.launchd[1] (org.mongodb.mongod[394]) Exited with exit code: 100
8/1/11 6:49:15 PM com.apple.launchd[1] (org.mongodb.mongod) Throttling respawn: Will start in 10 seconds
8/1/11 6:49:25 PM com.apple.launchd[1] (org.mongodb.mongod[394]) Exited with exit code: 100

And searching on Google didn’t turn up any interesting results.

IT PAYS TO LOOK AT YOUR LOG FILE! Well, this shouldn’t be new, but it somehow skipped my mind until I saw the config file.

In the log file was the following helpful error message.

**************
old lock file: /usr/local/mongodb_data/mongod.lock.  probably means unclean shutdown
recommend removing file and running --repair
see: http://dochub.mongodb.org/core/repair for more information
*************

Mon Aug  1 18:49:35 [initandlisten] exception in initAndListen std::exception: old lock file, terminatingMon Aug  1 18:49:35 dbexit:
Mon Aug  1 18:49:35 [initandlisten] shutdown: going to close listening sockets...
Mon Aug  1 18:49:35 [initandlisten] shutdown: going to flush diaglog...
Mon Aug  1 18:49:35 [initandlisten] shutdown: going to close sockets...
Mon Aug  1 18:49:35 [initandlisten] shutdown: waiting for fs preallocator...
Mon Aug  1 18:49:35 [initandlisten] shutdown: closing all files...
Mon Aug  1 18:49:35 closeAllFiles() finished
Mon Aug  1 18:49:35 dbexit: really exiting now
Well, after deleting the lock file, everything was back to normal.

When in doubt, always look in your log file!

Relevance in current Internet

I just finished reading TechCrunch article, How Facebook Can Put Google Out of Business. This also reminded me of Paul Adam’s articles, The Real Life Social Network and How Your Customers’ Social Circles Influence What They Buy, What They Do and Where They Go. And also this good analogy of Facebook, Google and other hot startups.

I was also asked a lot of questions about problem of current social media and how I could make it better as part of interview questions. One common answer I provide is the relevance. How important are these news, status updates, tweets, etc. to me? I agree that the biggest difference between Facebook and Google is the core of each company – people (social) or links (web pages).

Many companies are trying to figure out who you are as a person. For example, another favorite startup of mine, Hunch, is trying to figure out who you are and what you would like based on what you already like. Netflix tries to figure out what movies you might like based on your ratings of movies. Amazon has been doing it for a while with features like “you might also like…” Facebook is obviously in good position because of the social interaction data they have – what you shared, who you have interacted with, what you liked, etc. in addition to social graph. Twitter can also certainly figure out by analyzing followers, tweets and especially retweets, but right now I feel that noise-to-signal ratio on Twitter is too high. You control tweet relevance by carefully choosing who you follow.

We are bound to create more data. The amount of data we generate will never decrease. In the sea of data, it would be harder and harder to find information that is relevant to you, but to others. In this sense, Facebook is definitely sitting on a gold mine. It’s kind of creepy, but the more interactions you have on Facebook, the more Facebook knows you, and it provides good targeting data to advertisers. Can Google build significant social product? Nothing is impossible, but I think it would be very hard. Facebook is just too big, and I just don’t see why I would use similar feature on another platform. Once you have your social network established on one platform, it is extremely hard to create the similar network on a different platform. In social network, the winner takes all, unless the winner screws up big time. It could happen (as has happened a couple of times already with Friendster and MySpace).

We are living in an interesting time, indeed.

Lean Startup in Education (Hacking for Education)

Today I have had the most productive conversation with my wife (which is shame because I think she has a lot of good insights and look at things from different view points). It was inside the car, while we were driving to Lawrence Hall of Science, which is an awesome place all around.

I had to leave my most current job abruptly, and knowing the reasons behind it, she asked me what’s the most important element angel investors look before making an investment. It was an easy question to answer – the team, of course. And she wholeheartedly agreed. She said she experienced exactly the same at her Korean school, where she teaches grade school kids, and at Korean American Community Center, where she worked before working at the Korean school.

The Korean school she teaches at is part of a church (I am an atheist, but I welcome all religions), and thus their curriculum is not directed or regulated by school district. She said she and a few other teachers like to try new ways of teaching kids. Their attitudes were just like those of tech startup founders. Failure is okay, since you will learn more from failures and apply it to the next new idea. However, she said there were other teachers who are very resistant to trying new things even if they are not the ones implementing or preparing the experiment. Not only do they waste time, they also put out the passion brought on my good teachers. So, she understood how important the team is. Not everyone in the team needs to be super smart, but it’s important for the team to be open to experiments, not be afraid of failures and support each other.

She said she saw the same thing at the Korean American Community Service. She worked there as an office manager until our first child was born. The community center reached the peak while she was there, because she said everyone was open to trying new things – services or classes or whatever – to serve the community better. And most of all, they had the full support from the head of the community center. She also said amazing thing about leadership. Good leadership is not about leading, but creating an environment for team members to innovate. You shouldn’t try to make everyone follow your views, thoughts or directions, but instead give team members freedom to experiment, learn from successes/failures and move  forward. I was like DANG! That’s the most insightful thing I heard from my wife (again, I should have more conversations with her) . :)

I told her that’s the exact operating principal for tech startups these days. I couldn’t believe we were in such unison! And it got me thinking about our education system.  Many people are concerned about our failing education system, and WE HAD THE ANSWER ALL ALONG! Apply “Lean Startup” principal to our education. Encourage teachers to take 20% of their time to innovate. It’s not possible without school district’s support, but if there is, it’s totally doable. And have Lighting Talk or Lesson Learned sessions with other teachers so that they could learn from others’ successes or failures. And pivot if an idea didn’t work out. Or perhaps we need an national website for teachers to share their experiments and lessons learned from them. I truly believe this HACKING FOR EDUCATION will save us, and put our great nation again in leading position.

Silicon Valley Bubble

I went back home to the East Coast, Washington DC suburb, this past holiday season. I also went up to see my friends and cousins in NJ and NY. Having the first meaningful conversation with my friends and relatives in about two years made me realize one thing about Silicon Valley.

We (those of us living in the SF Bay Area) are living in a bubble. I am not talking about startup/options/hype kind of bubble, but a tech bubble. I was the one most knowledgeable about up-to-date information of facebook and its eco-system with apps and social games, twitter, google, etc. None of my friends and relatives seem to know nor even care about such information.

It’s just amazing and unbelievable when you think about such high concentration of technical knowledge, talent and money in one geographical area.

Kitchen Nightmares and Entrepreneurship

I am a big fan of Hulu. Ever since I found Hulu, I don’t watch much of TV. This is clearly new way of watching TV shows.It’s very convenient, and I get to watch whatever I want (as long as episodes are available) and whenever I want. Since I don’t have much time to watch during the weekday nights, I tend to “binge” watch on weekend nights.

I have recently discovered a very interesting show called “Kitchen Nightmares“, and while it’s entertaining and a little formulaic, I drew a lot of parallels with entrepreneurship.

Passion

It was amazing to see how many co-owners didn’t have passion for their restaurants! It was very clear some owners were using it for their ego trip, even though it was failing. You need that fire in the belly, which enables you to take charge of chaotic situation and plow through.

Passion was something a lot of investors and entrepreneurs talk about (also in the book called “Monk and the Riddle“). An entrepreneur without passion is an oxymoron. If investors see the lack of passion, it’s the fastest way to getting turned down.

Leadership

Oh, man, did it matter! I have never seen inside of a kitchen during dinner rush, but it was definitely chaotic. If there is no clear leadership, everything falls apart. Bad restaurants were plagued with inconsistent food, confusion in the kitchen and among wait staff, and angry customers who had to wait for a long time for their food to arrive or whose food wasn’t exactly top quality. It also turned out that whoever took charge happened to be one with hottest passion, most fire in the belly. And it shows.

Also in entrepreneurship, especially in hard times, leadership matters the most. Someone with hottest passion may not be the best leader, but that person will at least carry the company through especially in hard times. Continue reading

Full text search on Heroku

If you want to have full text search capability on Heroku, you should definitely use texticle or acts_as_tsearch. It is possible to use acts_as_farret on Heroku, but since you can only write to /tmp directory and your index file will be deleted sooner or later, you should not use it.

I first used texticle, and later switched over to acts_as_tsearch because I wasn’t happy with performance. Acts_as_tsearch is working really fine for me, and since your database on Heroku is already Postgres, there should be minimal configuration required. I even switched my local database from MySQL to Postgres to make both development and production environments consistent.