Friday, 30 September 2011

Ruby Postgres script

Swami Nikhilaananda said:
"Ruby is a gem of a language"

There was a very simple requirement that I had - I wanted to write a script to update a postgres table. On looking up quite a few resources also, I was unable to solve the issue that I was facing. Let me put down the completely stripped down version of the script here first...

#!/usr/bin/ruby
require 'postgres'
conn = PGconn.connect("localhost", 5432, '', '', "tblName", "username", "password")
puts conn
This script is the typical script that you will find on looking up any site. However, the error that you will face on running this is the following:
... `require': no such file to load -- postgres (LoadError) ...
This was quite annoying... Finally I discovered the required solution. So, I thought that this needs to be shared. Though it appears to be trivial, it is definitely not something that I could find with ease :)
#!/usr/bin/ruby
require 'rubygems' 
require 'postgres'
conn = PGconn.connect("localhost", 5432, '', '', "tblName", "username", "password")
puts conn
That line needs to come before you add require for others. Then it works like a charm <-- well, everyone uses that line :P So, thought I should too :-)


Do you spend a lot of time on the computer? Click here to learn how to use the Dvorak keyboard

Sunday, 25 September 2011

Installing Gnome3 and a couple of tweaks

Baba Gyani Triviani said:
"Life is always a trade off - You get something, at the cost of something else"

Ubuntu is probably the most commonly used Linux distribution. Ubuntu used to be shipping with Gnome for quite some time; however the latest version had Unity. While Unity appeared to look quite fancy in the beginning, a couple of sessions later, I found it incredibly annoying. There are several annoying features that one can find by running a simple Google search.

However, there is an alternative - Gnome3. Some people may prefer KDE for the beautiful environment considering it is quite familiar, being similar to Windows; Gnome though was my personal favourite (Though Linus Torvalds hates it) for being minimalistic and doing the job right. So, I decided to install Gnome, and found they have a new version Gnome 3.

[Note: From what I understand, you will lose Unity for good - Point of no return]

How to install Gnome 3:
To install Gnome 3, first launch your terminal. Then type the following four commands. As you would have probably guessed, this requires an internet connection.
sudo add-apt-repository ppa:gnome3-team/gnome3 
sudo apt-get update 
sudo apt-get dist-upgrade 
sudo apt-get install gnome-shell
Done!
Reboot your system and choose Ubuntu Gnome Shell Desktop at the login screen.

Issues and Fixes (These are some issues, and the resolutions)
  • No shutdown option! Or is there...?
  • But, how about Hibernate?
  • Icons on Desktop
  • Maximise and Minimise buttons?
After doing this, you will find that the Gnome 3 is up and running smoothly. However, the following are some issues you may see... Don't worry, there are very simple solutions too.

No shutdown option! Or is there...?
So, after installing Gnome 3 and using it, I wanted to shut down my system and I found that there was a Suspend option but there was no shutdown option, nor a hibernate option in the drop down menu on the top right where it was always there. I had to log out, and then at the login screen, press on the power off button from the top right. This was most annoying - Why should I do something in two steps when I used to do it in one? I then started running the command
sudo shutdown -h now
I then found that you can shut down without logging out. When you click on the menu on the top right, keep Alt button pressed. On doing that, you will see that the Suspend button becomes Power Off...

But, how about Hibernate?
If you are like me, you keep a few windows open, and want to resume work the next day. You won't want to power off, and open all of them all over again. So, yeah, Hibernate. But, there is no Hibernate right? To achieve this, as well as fix the previous issue also permanently, you can do the following.

Open the terminal and run the command
sudo apt-get install gnome-shell-extensions-alternative-status-menu
This will add a Power Off option to the menu. And on pressing Alt key now, the Suspend button becomes Hibernate. Easy, no?

Icons on Desktop
Another issue was that icons on the desktop are disabled by default. To solve this, as well as to get control over a lot of things, install dconf-tools. Run the following command in a terminal.
sudo apt-get install dconf-tools
Then, launch the dconf-editor by pressing Alt + F2, and typing in dconf-editor and press enter.
In the window that opens, go to org > gnome > desktop > background and check the box to show desktop icons.

That will get you the Desktop icons back.

You can remove some of the default icons that appear by going to org > gnome > nautilus > desktop and unchecking the icons that you don't want.
Did you know: Windows button + D will minimise all your windows, or restore them - toggle

Do you spend a lot of time on the computer? Click here to learn how to use the Dvorak keyboard
Maximise and Minimise buttons?
The windows don't have a minimise and maximise button by default. Let's proceed to fix that. Open the Terminal and run the following command
sudo apt-get install gnome-tweak-tool
Then, launch gnome-tweak-tool by pressing Alt + F2, and typing in: gnome-tweak-tool  and press enter.

In the window that opens, navigate to Shell in the panel on the left, and then in the Arrangement of buttons in the title bar option, choose All.

You can then press Alt + F2, and typing in r and press enter.

Proceed to remove Unity fully.
sudo apt-get remove unity 
sudo apt-get remove scrollbar*
I hope you enjoy using Gnome 3... Well, I did. Read about the various features of Gnome 3, and you will discover quite a few yourself.

Bonus: Add Docky - The Mac OSX Dock Doppelganger

If you are a big fan of the Mac OSX dock, which most of us are, then Docky can be an excellent app. Not only is it as smooth as the Mac one and does everything exactly similarly, it also serves as the much missed task bar to which most of us are used to. A beautiful app, a definite recommendation.


The Feedback system

Swami Gulagulaananda observed:
"Control theory says positive feedback results in unstable systems, psychologists say positive feedback results in emotionally stable systems"

People are different, and different people think differently. It is a well known thing about the two people seeing the same glass as half empty and half full. That being said, different people have different ways of leading lives, and they believe in principles of their own, formulate their own philosophies or sometimes follow those set by others and/or by God.

The ability to formulate their own philosophies and principles, is developed after some experiences were had. Like, a man lied to his wife, said that he was with his friend, while instead he was dining with his secretary. Later, he got a bump on his head after the wife discovered the lie on interrogating the friend (sans the overhead glaring lights)  She subsequently relayed the illumination gained to him through her rolling pin. This man develops either one of the following principles - Don't lie to wife, or take friend into confidence before going for a clandestine rendezvous, or hide the rolling pin. Suppose he didn't choose option one, and forgot to hide the rolling pin, and the wife happened to see him with her on her way home, then he gets some more experience which will teach him something more. To be more careful, and also to keep the helmet for at least 15 minutes after entering the house.

This lather-rinse-repeat mechanism is based on a simple concept which is the fundamentals in control theory - Feedback.

This figure shows y as the output. The input r is combined with the feedback taken from output and the new output y is again computed. Every time, new behaviour results from the result of past experiences.
(http://en.wikipedia.org/wiki/File:Simple_feedback_control_loop2.png)


Feedback, however, is not obtained by a person only through his own experiences. He can learn from someone else's experiences as well. And not only does a person depend on experiences, he also tends to depend on opinions. And this is where the topic begins to get interesting. For, the question is, whose opinion is to be considered and whose to discard.

A worthwhile read would be on two topics - Dunning Kruger effect and Illusory Superiority. A question on technical aspects is normally straightforward - A person knows it, or he doesn't. It's often boolean as the computer engineers like, or digital, as the electronics guys like. Basically, 0 or 1, it is absolute. However, human relations are more complex, and involve a lot of parameters.

A simple example would be a person who wants to be better than what he was yesterday. "Yes, every day, I want to learn something. I don't want to make the mistake I made yesterday. I want to be a better person, one who is adored, loved and respected" and so, he does something interesting, for the feedback system is not applicable all the time. He asks for the opinion of another. Why? The feedback system doesn't work all the time. There is the problem of Social Contract - You don't tell people something that you feel, just because you felt it. How many times have you felt "Dude, you stink, didn't you have a bath?" or "Dude, keep your voice down. Why do you want the whole bus to know that the biriyani that you had with your wife last night was amazing? (Whatever that was supposed to hint)"

There are some things you tell your friend, because, you are friends - Macha, don't pick your nose in public da, it's bad manners... You might say this to your friend. But, if your colleague did that, you wouldn't venture a remark. So, you don't always get honest feedback from people. So, the guy who aspired perfection goes around trying to get it - putting his finger down the throat of others to force it out. What happens as a result? A tactful person may safely evade and circumvent. But some people may decide to be honest, and give an opinion. "Hey, I think you speak with an accent. That's a tad annoying" The guy is now wondering "Oh boy, I didn't know that. Maybe I should flatten my style? Or is this the only guy who feels that? Let's verify". So, he goes around asking other people...

One of the following things can happen -

  • If he was indeed speaking with an annoying accent, and people are genuine, then they will give honest opinions. He puts it in his feedback loop and corrects himself
  • If he was indeed speaking with an annoying accent, and people decide to circumvent and change topics "Hey, the weather is great today!" he might think that the first guy was jealous and not correct himself.
  • If he was not speaking with an accent, and people are genuine, they will give honest opinions, and he concludes that the first guy was jealous or a moron
  • If he was not speaking with an accent and people say he was, he will wrongly make changes...
Now accent is just an example. But notice that the decision of the person now depends rather heavily on people, their morals, qualities and knowledge. If the people whom he sought advice from have the IQ comparable with a retarded rabbit, then he is in trouble. But even otherwise, he tends to become a people-pleasing person - One, who over a period of time, will align himself to the society in a bid to become acceptable, loses originality, ability to reason, and individuality.

But this doesn't mean that opinions are bad - Opinions of people are always important. Right opinions are very important. For, in times of deep trouble, the brain of a human behaves in ways it wouldn't have, when not under stress. Then, people unaffected by stress continue to hold reason, and they can give sane advice. Again, the person's decision will be affected by qualities of people, and thus, right company becomes sine qua non.

To summarise, a person must develop a strong ability to think rationally on his own - through his own as well as through others' experiences. A person should be able to choose good company, using his reason. The person should know whose opinion matters, and how much weightage is to be given to whose opinion. One must always listen to all opinions, and then decide himself which is the best option and not blindly follow others. Well informed opinions are much better than one taken without adequate data, and data always comes through research as well through other people. Thus, we conclude that the individual needs to be strong and stable, or have a strong and stable partner to depend on.

Wednesday, 21 September 2011

Environment and effects

Swami Gulagulaananda said:
"The environment has profound influence on you - Evolution happens, not just as metamorphosis of the body, but also of mind"

I would like to narrate a couple of incidents, using my favourite character Raj again. So here goes:
Raj was done with his exams, and had got his results. He had scored quite good marks, distinction, in fact. Raj was studying in the best college in the state. People around him were some of the best guys in the entire state, and he just sat wondering about his marks. He found that when compared with his classmates, he was exactly in the middle. There were as many people above him, as below him.
As he was thinking about this, his phone rang. He picked it up, and saw that it was his school friend with whom he had not spoken for a long time. "Hey, how have you been? Long time, huh?"  They spoke for quite some time, and then the topic about exams had come. The exams being state level, was a common topic. "How much did you score?" asked Raj. "Oh, I got 65%" 65? Wow, that's not even a distinction, and that was more than 12 less than what Raj had got, around 78. "Why so less? Didn't you study well?" asked Raj, for the girl was actually quite clever. "Hey, I did. Well, all my friends here have got the same, more or less, between 62 to 67. So, it's alright, so what else have you been doing?". The college in which this girl was studying was a different one, not at the same level as Raj's college.
The scores that were scored by that girl and her friends - well, just about a handful were there in his college. Most others were way ahead. Which was why Raj felt that the marks she and her friends scored, were very less - he was comparing his marks with people around him, and they being toppers, made his score seem low, though higher than his friend. While she, on comparing with people around her, was satisfied and didn't understand what Raj was saying.
Raj also had similar experiences in several other places. There was one instance where Raj and a close friend of his had studied the exact same topics for a test, and while Raj was happy that he had studied a lot, the friend, who was a topper, was very worried because he felt that he had not studied anything.

Raj also had another revealing experience, when people around him used to praise his knowledge about something a lot all the time, his new teacher chided him for being so far behind - The reason for this difference is that the benchmarks were different. The people who were praising him were far behind compared to him, and the person who chided him was far ahead of him.

Through these instances, we see that the standards of comparison themselves are different. Nobody is right, and nobody is wrong. But standards and benchmarks themselves are set apart.

There was a comment on my blog posts, saying that I come along too strongly on certain things like, for example, I hate Chetan Bhagat's style of writing, which I feel is too simple and drab - I don't even like to put style in the same sentence as one that has Chetan Bhagat. Well, the only reason his books are popular is that they connect well with the common folk, and his sentences don't need them to put stress on their (puny) minds. Rather, the language reminds them of their own everyday lingo, and they are able to connect with stories like '2 states'. (I feel I can write better than him. Here's a link to some short stories I wrote, judge them for yourselves.) Frankly, any person who has read good books will have feelings like 'nails against blackboard' when they read such irritating material. Understand the difference, simplicity is not what I am against. Sudha Murthy writes in very simple English as well, but her books are a delight to read. Now, here, people will say opinions are different - Hey, you like something, what I like and what you like are not necessarily the same. So, yeah, tastes are different. But I say - It is not tastes that are different, it is standards and benchmarks.

This is also the same reason I hate Kannada songs that are being released currently. Frankly, when you compare them with songs of the past, you will see that the "songs" of now are just merely proses that are being sung by incredibly talented singers with incredibly good music. The lyrics as such is ridiculous. If someone does like it, it doesn't talk about opinions - it reflects benchmarks. If your tastes are inherently poor, you liking such a song will not make it good in reality. It will make it seem good to you - And if you are a person who is happy with mediocrity, then so be it.

There can be no debates and discussions on standards and benchmarks, unless people can see superior things and compare. A person who is amidst 65% people will not be able to appreciate the low scores till he sees a person with 90%. If everyone around you looks like that, then you are just ok with it. For, by definition, it makes it average.

Therefore, people's opinions don't matter if their standards are low

Saturday, 17 September 2011

Yes Man

Swami Nikhilaananda said:
"Say Yes"

There is a movie called Yes Man which has Jim Carrey, a loser who is totally depressed in life attending a workshop where the guy there asks him to say Yes to everything, so that he can embrace the positive energy. It's a really nice movie, that shows him getting into trouble in the beginning, but then all the creases get ironed out by the end of the movie.

I have had quite a few experiences that are similar. So, I thought I should share a couple of anecdotes just to show you how things are... The following is part real, part fiction, but you will get the message.
Raj was working in a very large company, but as time passed, he was beginning to feel stagnated. He looked back over the past one year and tried to assess what he had done. He found that he had not learned anything significant in the past year, well, nothing that required a year to learn. He felt that he was learning a lot more in college, amidst the fun, while here, he was like Harold Smith, the villain from Powerpuff girls who felt the work was getting totally monotonous and there was no excitement. 
And then, one day, there was a circular that said that there was an event where one could talk about any topic that can benefit others. Raj could have dismissed this as yet another event and let go, but then he remembered the movie 'Yes Man' and decided to give it a shot. He registered to talk with the intent of getting at least a certificate and a time out. While giving the seminar, one among the audience seemed to be really interested in the talk. After the talk, Raj met that person, and was engaged in a pleasant conversation, and subsequently came to know that there was an opening in his team, a team that was way more exciting than Harold Smith's job. And thus, Raj switched teams - this would not have happened if he had not registered for the event... Raj is very happy in his new job

Whether you call this as fate, or anything else, the result is something you will appreciate. And then, one more incident happened in Raj's life.
Raj's friend told that there was a competition, and asked Raj if he wanted to participate. Raj decided to embrace it, and said cool! Raj and his friend decided to participate in the event, where Raj's friend was also supposed to join them. After the event, Raj's friend's friend decided to offer Raj a job in a large company, and that was yet another pleasant surprise. Raj declined the offer politely, but was again reminded of the theory from Yes Man
The beauty of these two anecdotes is that, the objective of going to an event was something, but the benefits came from unexpected sides. Similarly, you never know how things will come to you, but if you decide to sit quietly at home, watching some series, you won't be able to reap benefits that come from connecting with people. It is always better to have a rather positive outlook in life, and give things a shot - What's the worst thing that can happen? Nothing... You will return empty handed.

Therefore, it is better to do work without expectations, as Lord Krishna says, but again, it is better to do work than to not do work, as Swami Nikhilaananda says :-) Have a great weekend guys