My new found love
After a long gap, I am once again in love. I felt an immediate connection with my new found love and am kind of obsessed with it right now. Well, this time it is not a girl and before your brain starts getting into all kinds of stuff, let me tell ya, its not a boy too - Its 'Sheesha or Hookah'.
I tried my first hookah in Jaipur during my college days at JIIT, Noida. I went on a holiday to Jaipur with my college friends and we were hanging out at one of the markets. Suddenly, a person approached our group and asked us whether we would like to be get pampered at one of the cafes in the market. Well, actually a new Cafe Mocha was opening up and they had some media promotion going on, so they wanted a bunch of cool college going kids to experience the new cafe and give a review to the news channel people. We all agreed to it immediately and the entire Mocha was at our disposal with everything avaiable on the house. Thats where I ordered my first hookah "Green Apple" flavor. Man it was an amazing feeling, I got a little high at the end of it, probably due to the fact that I have never smoked. After some years I had the second hookah at my friends (Anuj Bajpai's) wedding in Lucknow. And now, after another few years I went out with my childhood friends to a newly opened Cafe Mocha in Civil Lines, Delhi.
We ordered a hookah "mixed fruit" flavor and I enjoyed the entire session. This was the first time that I got some kind of connection to it. I really liked it. Since then on, I have been asking my buddies to visit the cafe again and again. So today, the 3 of us - my cousin Utkarsh, my neighbor Manni and myself went again and had a long session of hookah, drinks and food. I tried my favorite "Green Apple" flavor again. Now, am again a little high and wanted to share this feeling. So got back to writing and here is my latest blog entry.MySQL function GROUP_CONCAT to return string result of concatenated values from a group
GROUP_CONCAT(expr) - This function returns a string result with the concatenated non-NULL values from a group.
SELECT id, GROUP_CONCAT(emp_name) FROM emp_table;
Install and Uninstall mysql server on Ubuntu 10.10 (Maverick)
Update your package repositories and installed programs:
sudo apt-get update
sudo apt-get upgrade --show-upgraded
Installing mysql server:
sudo apt-get install mysql-server
You will be prompted to set a password for the MySQL root user.
After installing mysql-server, it is recommended that you run mysql_secure_installation in order to secure MySQL.
mysql_secure_installation
After running mysql_secure_installation, MySQL is secure and ready to be configured.
Remove mysql server:
sudo apt-get --purge remove mysql-server mysql-common mysql-client libmysqlclient15-dev
How to dump selected records using mysqldump
In order to select a few records from a database table and creating a dump file, do the following:
mysqldump -u [username] -h [host] -w "condition" -p [database] [table] > [dump_file_name]
E.g. Creating a dump of all records where is_active flag is set to True:
mysqldump -u root -w "is_active=True" -p test_db emp_table > dump_file
How to exclude/ignore a directory from under SVN
To exclude a directory/folder from under SVN, follow the steps below:
1. Change directory to your working directory folder:
$ cd /home/myproject/
2. Cal the following command to exclude the directory from SVN:
/home/myproject/$ svn propset svn:ignore '*' bin/
You just removed 'bin' folder from your svn repository.
Sending email using Gmail account on Django
To send an email through Django using Gmail account, you would need to set some variable in the settings.py file of your project.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'your-password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
You can test your settings by going to Django shell:
python manage.py shell
from django.core.mail import EmailMessage
email = EmailMessage('sample mail', 'hello world', to=['someuser@domain.com'])
email.send()
Reference:
http://docs.djangoproject.com/en/dev/topics/email/
http://docs.djangoproject.com/en/dev/ref/settings/#email-host
http://sontek.net/using-gmail-to-send-e-mails-from-django
http://komunitasweb.com/2010/06/sending-email-using-gmail-account-in-django/
Creating ssh shortcuts
Problem statement: Avoid typing the whole user@hostname while connecting to remote server using ssh.
Solution:
1. Creating a config file for ssh
sudo pico /home/user/.ssh/config
2. Add the following section for each remote server
Host nickname
Hostname remote-server-hostname
User remote-server-username
E.g.
Host myserv
Hostname host.example.com
User root
Linux - Adding public SSH key on a remote server
Problem statement: Allow logging in to a remote server without password.
I have had this question of adding a public SSH key on to my remote server, whenever I format my machine. Everytime I googled and found a couple of solutions to the same. But, I had to struggle for at least half an hour everytime in order to achieve the desired connectivity between my local machine and remote server. Finally, I am noting down the best solution that I found for future needs.
Solution:
1. Generating the key pair (public/private):
ssh-keygen -t dsa -b 1024
It will prompt 2 questions:
a. Enter file in which to save the key (/home/username/.ssh/id_dsa):
The default choice is a good option, so just press return.
b. Enter passphrase (empty for no passphrase):
This is also an optional field, required for the first login to the remote server, every session.
2. Copying the public key on to the remote server:
ssh-copy-id -i /home/username/.ssh/id_rsa.pub user@hostname
3. Connecting to the remote server:
ssh user@hostname
The first time, you'll be prompted for your passphrase. The passphrase won't be asked anymore until you log out/in of your session.
MySQL Full text search commands
1. Moving existing table from one engine to another-
ALTER TABLE table_name ENGINE=engine_name;
Engine names could be -> InnoDB, MyISAM
For further reference, browse thru "A fast and furious guide to MySQL database engines"
2. "MySQL Indexs" a glimpse.
3. Creating Full Text index and playing with it "How it works"
4. Creating Full Text index on an existing table-
CREATE FULLTEXT INDEX index_name ON table_name (column_names);
5. Implementing Full Text search in Django using MySQL - "Extending Django's database API to include full-text search"
MySql code snippet - mysqldump example
The following code snippet in SQL is occasionally used by me and I tend to forget the basic syntax or the same.
So here it is, just for reference for future use.
How to backup database in mysql:
Mysqldump –u username –p database_name > dump.sql
How to restore a database from dump file:
mysql -u username -p database_name < dump.sql

