Saturday, June 25, 2011

Bob Parson Rules for Success

http://www.bobparsons.me/bp_16_rules.php?ci=21428

1.
Get and stay out of your comfort zone.
I believe that not much happens of any significance when we're in our comfort zone. I hear people say, "But I'm concerned about security." My response to that is simple: "Security is for cadavers."
2.
Never give up.
Almost nothing works the first time it's attempted. Just because what you're doing does not seem to be working, doesn't mean it won't work. It just means that it might not work the way you're doing it. If it was easy, everyone would be doing it, and you wouldn't have an opportunity.
3.
When you're ready to quit, you're closer than you think.
There's an old Chinese saying that I just love, and I believe it is so true. It goes like this: "The temptation to quit will be greatest just before you are about to succeed."
4.
With regard to whatever worries you, not only accept the worst thing that could happen, but make it a point to quantify what the worst thing could be.
Very seldom will the worst consequence be anywhere near as bad as a cloud of "undefined consequences." My father would tell me early on, when I was struggling and losing my shirt trying to get Parsons Technology going, "Well, Robert, if it doesn't work, they can't eat you."
5.
Focus on what you want to have happen.
Remember that old saying, "As you think, so shall you be."
6.
Take things a day at a time.
No matter how difficult your situation is, you can get through it if you don't look too far into the future, and focus on the present moment. You can get through anything one day at a time.
7.
Always be moving forward.
Never stop investing. Never stop improving. Never stop doing something new. The moment you stop improving your organization, it starts to die. Make it your goal to be better each and every day, in some small way. Remember the Japanese concept of Kaizen. Small daily improvements eventually result in huge advantages.
8.
Be quick to decide.
Remember what General George S. Patton said: "A good plan violently executed today is far and away better than a perfect plan tomorrow."
9.
Measure everything of significance.
I swear this is true. Anything that is measured and watched, improves.
10.
Anything that is not managed will deteriorate.
If you want to uncover problems you don't know about, take a few moments and look closely at the areas you haven't examined for a while. I guarantee you problems will be there.
11.
Pay attention to your competitors, but pay more attention to what you're doing.
When you look at your competitors, remember that everything looks perfect at a distance. Even the planet Earth, if you get far enough into space, looks like a peaceful place.
12.
Never let anybody push you around.
In our society, with our laws and even playing field, you have just as much right to what you're doing as anyone else, provided that what you're doing is legal.
13.
Never expect life to be fair.
Life isn't fair. You make your own breaks. You'll be doing good if the only meaning fair has to you, is something that you pay when you get on a bus (i.e., fare).
14.
Solve your own problems.
You'll find that by coming up with your own solutions, you'll develop a competitive edge. Masura Ibuka, the co-founder of SONY, said it best: "You never succeed in technology, business, or anything by following the others." There's also an old Asian saying that I remind myself of frequently. It goes like this: "A wise man keeps his own counsel."
15.
Don't take yourself too seriously.
Lighten up. Often, at least half of what we accomplish is due to luck. None of us are in control as much as we like to think we are.
16.
There's always a reason to smile.
Find it. After all, you're really lucky just to be alive. Life is short. More and more, I agree with my little brother. He always reminds me: "We're not here for a long time, we're here for a good time!"

Saturday, May 7, 2011

Getting Git

Bring up terminal (Ctrl-Alt-T) and type:
sudo apt-get install git-core git-gui git-doc

Now we need to setup ssh keys to connet to Github.
In terminal, to create key location type:
mkdir ~/.ssh

And to generate the key use your email address:
ssh-keygen -t rsa -C ""

It will ask for a passphrase, it is like a password.

Once it is done, we need to get the public key over to Github.
Type:
cat ~/.ssh/id_rsa.pub
and copy that content over to Github (follow instruction at Github on how to do this).

Once done, test it out
ssh -v git@github.com

It will ask you to confirm authenticity of host 'github.com'. Approve it.
It will ask you to enter passphrase. Give it.

If you see an entry that says Authentication succeeded (publickey), then it is all good.

Let's setup your git info. In terminal type:
git config --global user.name = ""
git config --global user.email = ""

Now you are setup with Git, time to get some stuff done!

Wednesday, May 4, 2011

Rails in Ubuntu 11.04 Part 2

By this time you get a welcome message when you hit http://localhost:3000/ in your browser.

Now let's make a real web application. We'll follow the steps in the welcome message, but in reverse order.

First, create our database.
Back to terminal, kill our server:
Ctrl-C

Get into MySQL:
mysql -uroot -p

Create a database (we are using utf-8 because we have worldwide user base):
create database betterblog_dev default character set = 'utf8' default collate = 'utf8_unicode_ci';

Create a database user:
create user 'bb_dev'@'localhost' identified by 'bb_pass';

And give him access to our newly created database:
grant all on betterblog_dev.* to 'bb_dev'@'localhost';

Let's test out this user. Go out:
exit

Then go back to MySQL using our new user:
mysql -ubb_dev -p betterblog_dev

If you can get in, great! Let's get out:
exit

Now we need to tell Rails about our new database and user.
cd /var/www/betterblog
gedit config/database.yml

Find a section labelled development and modify it as such (modification in bold):
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: betterblog_dev
pool: 5
username: bb_dev
password: bb_pass
socket: /var/run/mysqld/mysqld.sock

Save and Exit.

That should take care of the database, now the next step: setup default rout and remove blah blah.. okay, let's go do stuff.

Let's get rid of this welcome message and put our own awesome welcome screen!

Back to terminal
cd /var/www/betterblog
rm public/index.html

That would take care of removing, and for our own welcome screen:
rails generate controller welcome index

Okay okay, let's see what do we have now!
rails server

Go to browser and hit http://localhost:3000/

What error?!?! It probably says: Please install the mysql2 adapter

Not bad a helpful message. Too bad it is misleading. What we really need to do it install an earlier versoin of one of our gem, specificially mysql2 gem. So we need to remove that one and install a different version.
Back to your terminal:
Ctrl-C
sudo gem remove mysql2
sudo gem install mysql2 -v 0.2.6
rm Gemfile.lock
rails server

Use your browser to hit http://localhost:3000/
Routing Error?
Ah yes.. routes. Let's fix that. Back to terminal:
Ctrl-C
gedit config/routes.rb

Find a line that says:
# root :to => "welcome#index"
And remove the first '#' so it looks like this:
root :to => "welcome#index"

Save and Exit

Back to terminal.
rails server
And browser..
and error.
openssl? Let's fix that too.
Back to terminal
Ctrl-C
sudo apt-get install libssl-dev
cd ~/sources/ruby-1.9.2-p180/ext/openssl
ruby extconf.rb
make
sudo make install

Let's try again
cd /var/www/betterblog
rails server

Finally, not an error. But it says find me at ...
let's go there.
Back to terminal.
Ctrl-C
gedit app/views/welcome/index.html.erb

Hey look, it is exactly what you see on the browser. Let's make it ours!
Delete everything and put in the following:
<h1>BetterBlog<h1>
<p>We are making a better blog.</p>
Save and Exit

Start the server again:
rails server

Reload your browser on http://localhost:3000/

Hurrah!











Tuesday, May 3, 2011

Rails in Ubuntu 11.04

Setting up

Updated: see comment below from Haywood.
He is correct.
The following link will help you to get up and running in a jiffy like a true Ruby master.
-- end update

Start terminal (Ctrl-Alt-T)

Get Ruby
In terminal:
cd ~
mkdir sources
cd sources
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
tar -xvf ruby-1.9.2-p180.tar.gz
cd ruby-1.9.2-p180
./configure
make
sudo make install

Ruby should be installed now. Try it:
cd ~
ruby -v

Install MySql
You can get this from Ubuntu Software Center. Look for MySQL Server and MySQL Client. Install both.
Once done, go back to terminal and try this
mysql -uroot -p
You should enter mysql client. To get out type:
exit

Get Rails
Gem should have been installed when you install ruby. What is gem? Go to terminal and try this:
gem -v

If you do not see an error, you have gem.
Let's update gem itself:
sudo gem update --system

If you see an error about zlib, run this:
sudo apt-get install zlib1g-dev
cd ~/sources/ruby-1.9.2-p180/ext/zlib
ruby extconf.rb
make
sudo make install
sudo gem update --system

Now use gem to get rails:
sudo gem install rails

Now let's write some web application!!
back to terminal
cd /usr
sudo mkdir www
sudo chown www
cd www
rails new betterblog --database=mysql
cd betterblog

Let's run our web application!
rails server

Error! Could not find gem 'mysql2'?
Try this:
sudo apt-get install libmysqlclient-dev
sudo gem install mysql2

Now try again:
rails server
Does it says start anywhere? Let's try it!
Open up your browser and hit http://localhost:3000
Wohoo! A welcome screen!
Not really a web application yet, but we are getting there.

Go to part 2.

















Friday, June 11, 2010

Excellent Vim Resources for Javascript

Here's Broofa's excellent Javascript indenting function
http://vim.wikia.com/wiki/Improved_Javascript_Indent_script_for_Vim

Saturday, May 22, 2010

Ubuntu 10.04 Lucid, Apache Solr and Solr Cell

I just got Ubuntu 10.04 LTS Lucid installed and noticed that Apache Solr 1.4 is now available as a package! Wohoo!

It turns out that this package doesn't include the awesome Solr Cell, and if you use Solr without Cell... why?

So here's how to fix this little problem.

First, get yourself setup with Solr (I am using Jetty here).
sudo apt-get install solr-jetty

Create a folder for Solr Cell libraries
sudo mkdir -p /usr/share/solr/lib

Now we need to get Solr distribution from Apache
wget http://apache.mirrors.tds.net/lucene/solr/1.4.0/apache-solr-1.4.0.tgz
tar -xvf apache-solr-1.4.0.tgz
cd apache-solr-1.4.0/
sudo cp dist/apache-solr-cell-1.4.0.jar /usr/share/solr/lib/
sudo cp contrib/extraction/lib/*.jar /usr/share/solr/lib/

Restart Jetty.

That's all. From now on your call to update/extract will work just fine.

Wednesday, September 3, 2008

Wednesday, June 18, 2008

HTTP Persistent Connections keep on opening new connections

There is an odd behavior with Java HttpUrlConnection in which excessive amount of connection is opened. I can see this by doing netstat on my Windows box.

The setup is like this:

ExecutorService es = Executors.newFixedThreadPool(16);

Callable c = new Callable() {
public void call() throws Exception {
... do something that uses HttpUrlConnection
}
}

for(int i=0; i < 160; i++) {
es.submit(c);
}

es.shutdown();

If you run this and run netstat,you will end up seeing a lot more than 16 connections with TIME_WAIT status. In fact I'd bet there are probably more than 50 connections in that status to your destination.

There are many reasons why this shouldn't happened.
1. Keep-Alive should have reused connections.
2. Eventually one of the connection will timeout. After all you do establish that many connections to the remote system, and it might not like that you are doing that.

This page has excellent example of how to make sure keep-alive is being used and connections do get reused.
http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html

I follow everything there including making sure that my streams are closed. No effect.

However, I do see an interesting change when the number of parallel threads are reduced to 4. With that few parallel threads, not more than 4 connections are shown by netstat.

It turns out that this has to do with the default number of connections for keep alive.
According to this article, the number if 5.
http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html

I'd guess that the implementation of HttpUrlConnection is such that a connection is bound to a thread. If we have 4 threads, then there will be 4 connection recycled (after all it is the same 4 threads using it). However, when the number of threads is 16, then there are 16 connections being opened which is more than the maxConnection of 5. At this point odd behavior starts to happen. Instead of reusing, it starts to keep on spawning new connection.

The workaround is to actually start the jvm with system properties to change the max connections.

When I repeat the same operation with -Dhttp.maxConnections=16, netstat would give me exactly 16 connections. Nice!

So next time, if you need to issue X http calls in parallel, start your JVM by giving it maxConnections=X.

Saturday, June 7, 2008

Preparing Ubuntu with Developer's essential

Like compiler, make, etc.

sudo apt-get install linux-kernel-headers
sudo apt-get install build-essential

Saturday, May 10, 2008

Installing Lighttpd (Ubuntu)

sudo apt-get install libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0-dev
sudo apt-get install libbz2-dev

wget for the source (see lighttpd website)
unzip

./configure
make
make install

sed -e 's/FOO/lighttpd/g' doc/rc.lighttpd > /etc/init.d/lighttpd
chmod a+rx /etc/init.d/lighttpd
mkdir /etc/sysconfig
cp -p doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
install -Dp ./doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
update-rc.d lighttpd defaults