Wednesday, October 8, 2008

फ़िर से शुरुवात करने की कोशिश.

ऐसा लगता था की मेरी ज़िन्दगी थोडी थोडी स्थिर होती जा रही थी जब तरह से मैं गाजियाबाद मैं था। नौकरी ठीक ठाक चल रही थी घर मैं ज़रूरत का सामान भी धीरे धीरे जोड़ चुका था ।मेरा भाई सुमित तो मेरे साथ रहता ही था और माता पिता जी भी समय समय पर हमारे साथ रहने आते रहते थे। यका यक मैंने अपनी नौकरी बदलने की सोची बहुत बड़े संगठन से था तो तो गहरी सूच मैं डूब गया था मैं की मुझे क्या करना चाहीए, बहुत लोगो से सलाह मशवरा भी किया और अंततः मैंने यह फैसला किया की मैं नौकरी बदल ही लेता हूँ। परन्तु समस्या यह थी की नए संघठन के साथ सम्मिलित होने के लिए मुझे बंगलोर जाना पड़ता । मैंने एक सक्थ फैसला किया और बंगलोर आ गया, मुझे यहाँ एक महीना हो गया है जब मैं यह ब्लॉग लिख रहा हूँ। मुझे ऐसा लगता है की बहुत कुछ बदल गया है स्थिर से अस्थिर हो गया है कुछ तो, घर वालों से दूर रहना क्या होता है मुझे काफी समय से पता है परन्तु इतना दूर रहना की जा के मिल भी न सकूं दीपावली पे यह एक बहुत अलग अनुभव है, मैंने धर्य नही छोडा है अभी तक तो और मैं उस समय का इंतज़ार कर रहा हूँ जब हम सब एक बार फ़िर से साथ रह रहे होंगे।

Wednesday, June 11, 2008

MySQL Index varchar fields partially

Once upon a time :) I had a simple table.
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| pnrkey | bigint(20) unsigned | NO | MUL | NULL | |
| pr_aac | char(2) | NO | MUL | NULL | |
| pr_pn_fn | varchar(99) | NO | MUL | NULL | |
| pr_pn_ln | varchar(99) | NO | MUL | NULL | |
+----------+---------------------+------+-----+---------+-------+
I created it using the following create statement..
DROP TABLE IF EXISTS ePDI_passengername;
CREATE TABLE ePDI_passengername (

pnrkey BIGINT UNSIGNED NOT NULL,
pr_aac CHAR(2) NOT NULL,
pr_pn_fn VARCHAR(99) NOT NULL,
pr_pn_ln VARCHAR(99) NOT NULL,

INDEX ePDI_passangername_index_pr_fn(pr_pn_fn),
INDEX ePDI_passangername_index_pr_aac(pr_aac),
INDEX ePDI_segmentData_index_pnrkey(pnrkey),
INDEX ePDI_passengername_index_pn_ln(pr_pn_ln)

)PARTITION BY RANGE(pnrkey)(
PARTITION p0802 VALUES LESS THAN (2008030000001),
PARTITION p0803 VALUES LESS THAN (2008040000001),
PARTITION p0804 VALUES LESS THAN (2008050000001)
);

I added 500,000 records to my table, and saw that the index table MYI was bigger in size than the data one MYD. also I was not happy with the performance of indexes on pr_pn_fn & pr_pn_ln as mysql ignored indexes in like '%string%' kind of searches and the performance was very poor in like 'string%' kind of searches

I shortened the indexes and found improvement in performance

Altering table indexes
alter table ePDI_passengername drop Index ePDI_passangername_index_pr_fn;
alter table ePDI_passengername add Index ePDI_passangername_index_pr_fn(pr_pn_fn(10));

Database interview questions

  1. What is the difference between a primary key and a unique key.
  2. How do I find all the people whose salary are the third highest in an organization.
  3. Why do we partition tables
  4. What is the difference between Inner join and outer join.

Saturday, June 7, 2008

Eclipse security component error in Ubuntu

If you get this error "Could not initialize the application security component. The most likely cause is problems with files in your application's profile directory. Please check that this directory has no read/write restrictions and your hard disk is not full or close to full. It is recommended that you exit the application and fix the problem. If you continue to use this session, you might see incorrect application behaviour when accessing security features"
try this
mkdir ~/.mozilla/eclipse
chmod 777 ~/.mozilla/eclipse

Tuesday, May 27, 2008

Java interview questions

  1. What are the various ways to implement threads.
  2. How do we make a section of code thread-safe.
  3. What all do you know about Springs Framework.
  4. Which template have you used in Springs DAO.
  5. Explain some features of Hibernate.
  6. How is Hibernate different that Springs DAO.
  7. Which version of Struts have you worked on.
  8. Explain the flow of control in a struts framework.

Thursday, May 22, 2008

AverTV Super 007 on Linux ( Ubuntu )

I recently purchased this tuner card was disappointed to discover that it was not running on Ubuntu 8.04, I read forums and was happy to know that it was not impossible, but the issue was that a lot of stuff was written, I have filtered out to few steps that helped me to get the card working
  1. sudo apt-get install mercurial
  2. hg clone http://linuxtv.org/hg/v4l-dvb
  3. cd v4l-dvb
  4. sudo make
  5. sudo make load
Start tvtime and things should work.

PHP, MySQL Interview questions

  1. What are the differences between PHP4 & PHP 5.
  2. Give your ideas how you can scale up a LAMP based website.
  3. Which design pattern is used by Symfony.
  4. what is the difference between pass by value and pass by reference.
  5. Describe the highlights of MVC architecture.
  6. How many types of tables does MySQL have.
  7. What are the differences between MyIASM and INNODB table types.
  8. What could be a possible reason if someone is looking to store session information inside a database, what are the steps involved in doing the same.
  9. How would you do clustering in MySQL.
  10. What are the different types of Indexes in MySQL.
  11. Explain FullText index in MySQL.
  12. Can we overwrite a row using insert in MySQL if the primary key is unique.
  13. Suggest some optimization steps in MySQL and sql queries.
  14. How would you create a function which would accept variable number of inputs.

Thursday, May 8, 2008

Postgres showprocesslist

Looking for something like showporcesslist for postgres, here is something I found.
Edit your postgres.conf
stats_start_collector = true

This must be set to true for the statistics collector to be launched at all.

stats_command_string = true

This enables monitoring of the current command being executed by any server process. The statistics collector subprocess need not be running to enable this feature.


After restarting postgres the following query will show currently running queries


psql -U postgres template1 -c "select * from pg_stat_activity"

only as user "postgres"

Monday, April 28, 2008

Weekend with Suse 11 Beta, FreeBSD

Last weekend I was ready to test SUSE 11 Beta ( 55 days were still to go before its release ) and FreeBSD. Installation of SUSE was great I felt like I am installing a Microsoft product, when I ran it for the first time KDE4 was really cool. I have been using Gnome since quite sometime now and recently KDE4 was a lot talked about in the air, so I wanted to give it a try.
I made some changes in the screen resolution and refresh rate. and restarted the xserver, to my surprise the taskbar didn't load, I restarted the machine but same issue, I then created a new user and the new user desktop was fine, but when I logged on to the new user again the same thing happened.
I reinstalled with Gnome, still many bugs, then I finally installed FreeBSD. as expected it was good from the optimal resource utilization angle, but user friendliness I guess Linux (especially Ubuntu) has an upper hand.

Tuesday, April 22, 2008

OpenSUSE 11

This is something I am really excited about opensuse 11, I have used and loved enough of Fedora and recently Ubuntu and was always impressed by something different in OpenSUSE, but the only reason I could not use OpenSUSE was that SUSE was not very friendly to my hardware configuration, maybe this new release bridges the gap so that people like me could use it.
Its beta version is available freely for download.

Thursday, April 17, 2008

Java based multi threaded webserver

Had nothing to do since last few days so decided to make a small webserver, it has a small configuration file also, here the code that I landed up creating
-----------------------------------------------------------------------
import java.io.*;
import java.net.*;
import java.util.Properties;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class myServer {

public static void main(String args[]) {

String configFileName="config.properties";
String docRoot="";
int portNumber=80;

// ---- Load configuration file. ------
try {
configFileName = args[0];
}
catch(ArrayIndexOutOfBoundsException aioobe){
//Look for default configuration file.
}


try{
Properties properties = new Properties();
properties.load(new FileInputStream(configFileName));
System.out.println("Using configuration file "+configFileName);
portNumber = Integer.parseInt(properties.getProperty("port"));
docRoot = properties.getProperty("documentRoot");
}
catch(IOException ioex){
System.out.println("\nConfiguration file not found.\nPlease specify config file to use\nExample:\n\tjava myServer "+configFileName);
return;
}

// declare a server socket and a client socket for the server
ServerSocket echoServer = null;
Socket clientSocket = null;

// declare an input and an output stream
String line="";
DataInputStream is;
PrintStream os;

// Try to open a server socket on port 9876
try {
echoServer = new ServerSocket(portNumber);
System.out.println("HTTP Server started at port number "+Integer.toString(portNumber)+", Document root as "+docRoot+"\nTo stop server press ^c");
}
catch (IOException e) {
System.out.println(e);
}

while(true){ // Server runs infinitely.

try {

clientSocket = echoServer.accept();
is = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());

for (int i=1;i<5 ;i++ ){
line = line.concat(is.readLine());
}
Runnable runnable = new HandleClient(os, line, docRoot);
Thread thread = new Thread(runnable);
thread.start();

line="";

}

catch (IOException e) {
System.out.println(e);
}

}
}
}

class HandleClient implements Runnable{
PrintStream printStream;
String clientData;
String requestFileName;
String docRoot;

public HandleClient(PrintStream in_printStream, String in_clientData, String in_docRoot){
this.printStream = in_printStream;
this.clientData = in_clientData;
this.docRoot = in_docRoot;
//Set filename
this.requestFileName = this.clientData.substring(3, this.clientData.indexOf("HTTP/1.1")).trim().replaceAll("/", "\\\\");
this.requestFileName = this.docRoot.concat(this.requestFileName);
}

public void run(){
try {
//System.out.println("About to serve "+this.requestFileName);
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
File file = new File(this.requestFileName);
if (file.exists()){
//System.out.println("File Exists");
}
else{
System.out.println("File does not Exist "+this.requestFileName);
this.printStream.println("Not found.");
this.printStream.close();
return;
}

fis = new FileInputStream(file);

// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
//this.printStream.println(dis.readLine());
this.printStream.write(dis.read());
}
this.printStream.close();
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
//System.out.println("served "+this.requestFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;

} catch (IOException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;
}
}
}
---------------------------------------------------------------------------

--------- Configuration file --------------
#Configuration file
documentRoot=d:\\amit\\docroot
port=9999
errorPage=404.html

Wednesday, April 16, 2008

MySQL Stored procedure example

DELIMITER $$

DROP PROCEDURE IF EXISTS `mycash`.`addUnit` $$
CREATE PROCEDURE `mycash`.`addUnit` (in_name varchar(45),
in_type enum('Home', 'Organization', 'Community'),
in_country_code tinyint,
in_area_code smallint,
in_pincode integer,
in_street_address text
)
BEGIN
INSERT INTO `unit` (`name`, `type`, `country_code`, `area_code`, `pincode`, `street_address`, `creation_date`)
VALUES (in_name, in_type, in_country_code, in_area_code, in_pincode, in_street_address, CURRENT_DATE);
END $$

DELIMITER ;

MySQL cleaner ways to do things

Create table ..

CREATE TABLE `mycash`.`unit` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Sequence number',
`name` VARCHAR(45) NOT NULL COMMENT 'organization or home name',
`type` ENUM('Home','Organization','Community') NOT NULL DEFAULT 'Home',
`country_code` TINYINT UNSIGNED NOT NULL,
`area_code` SMALLINT UNSIGNED NOT NULL,
`pincode` INTEGER UNSIGNED NOT NULL,
`street_address` TEXT,
`creation_date` DATE NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
COMMENT = 'Top level entity, could be a house, organization or community';

Monday, April 14, 2008

Free Domain names, Free Java PHP MySQL hosting

The following free domain name registrars are in my knowledge

  1. co.cc
  2. freedomain.co.nr
  3. dot.tk

If you are also looking for a hosting support free of cost PHP, Tomcat, MySQL, then you can comment on this article, I have a server at my home and I can arrange some space over that.

Thursday, March 27, 2008

LAMP - Apache, PHP, MySQL Installation easy steps

Some like it binary some like compiling, I am amongst the compiling ones..
here are some easy steps that I usually follow to compile Apache, PHP to my machine.

  1. Apache
    1. ./configure --prefix=/usr/local/apache2.2.6 --enable-so --enable-proxy --enable-rewrite --enable-expires --enable-headers --enable-deflate --enable-ssl
    2. sudo make
    3. sudo make install
    4. cd /usr/local
    5. ln -s apache2.2.6 apache
    6. cd
  2. PHP
    1. ./configure --prefix=/usr/local/php5.2.5 --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib
    2. sudo make
    3. sudo make install
    4. cd /usr/local
    5. ln -s php5.2.5 php
    6. Configure Apache httpd.conf for PHP module
      1. LoadModule php5_module modules/libphp5.so
      2. AddType application/x-httpd-php .php .phtml

Thursday, March 13, 2008

Ubuntu Server edition kernel compile make menuconfig error

I install Ubuntu 7.10 Server edition, it was nice required less resources. GUI was missing, but the resources it saved where more important than X11.
Then I wanted to install Ultra Monkey and for that I read that first kernel needs to be patched up. I downloaded the kernel source from kernel.org, unzipped it and tried "make menuconfig" to my surprise it gave error and it was hard to understand.
Googling made me land on the fact that it requires ncurses-devel
I tried "sudo apt-get install kernel-package libncurses5-dev fakeroot wget bzip2"
and then "make menuconfig", now things work...

Wednesday, March 12, 2008

Ubuntu 8 Download

Ubuntu 8 is about come, beta is scheduled to be released on 20th mar, meanwhile if cannot wait ( like me ) then things can be downloaded from here
One more thing that I discovered today that its not just Mythdora alone, there are Mythbuntu and KnoppMyth also in the market, however I must mention here that my experience with Mythdora was very bad neither I liked the OS nor did the MythTV worked as decently as I thought It would.

Saturday, March 8, 2008

vi editor tips & tricks

To enable syntax hi lightening
:syntax enable

enable line number
:set number

Indentation
:set autoindent

you can make a file ~/.exrc with these commands so that every time vi starts you don't have to re enter the commands

my exrc contents are ..
------------------------------
:set number
:set autoindent
:syntax enable
------------------------------

Saturday, March 1, 2008

url rewriting in java & php

A lot of time we need to re-write URLs from dynamic to static, the reason may be security or SEO, but we keep needing it from time to time
I had done the same in PHP applications that I had build using mod_rewrite ( a module that can be compiled under apache httpd). Recently I was asked to do the same with an application running on Tomcat server I found an easy way to do it.

Wednesday, February 27, 2008

Fedora 8 Vs Ubuntu 7.10 Vs Suse 10.3 Vs Mandriva

I tried all these distros recently, and found Ubuntu 7.10 far better then others, Ubuntu was very stable applications were easy to install, on Fedora my tvtime kept freezing when I made it full screen, on Ubuntu there was no such issue, and I was able to install mythtv also.

Tuesday, January 29, 2008

iMilk

iMilk using your iPhone


Saturday, January 19, 2008

A Samba configuration file that works

[global]
workgroup = Workgroup
netbios name = SAMBA
server string = Samba Server
security = SHARE
encrypt passwords = Yes
obey pam restrictions = Yes
pam password change = Yes
passwd program = /usr/bin/passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
unix password sync = Yes
log file = /var/log/samba/%m.log
max log size = 0
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
dns proxy = No
hosts allow = all
printing = lprng
preferred master = yes

[homes]

comment = Home Directories
valid users = %S
read only = No
create mask = 0664
directory mask = 0775
browseable = No

[printers]

comment = All Printers
path = /var/spool/samba
printable = Yes
guest ok = Yes
browseable = No
public = yes

[Shared]

path = /tmp
read only = No
guest ok = Yes
create mask = 0664
directory mask = 0775

[Storage]
comment = storage
writeable = yes
public = yes
path = /storage

Thursday, January 17, 2008

How to configure linux networking / Internet

Note: You MUST be at the ROOT user to make/save any changes. Linux users, your distribution will determine the location of your network config file which will need to be updated and saved in order for the changes to remain in effect after rebooting. Network cards are referred to as eth0, eth1, eth2, etc based on their position on the PCI bus.

Display Current Config for all NIC's: ifconfig
Display Current Config for eth0: ifconfig eth0
Assign IP: ifconfig eth0 192.168.1.2
Assign IP/Subnet: ifconfig eth0 192.168.1.2 netmask 255.255.255.0
Assign Default Gateway: route add default gw 192.168.1.1
Assign multiple IP's: ifconfig eth0:0 192.168.1.2
Assign second IP: ifconfig eth0:1 192.168.1.3
Disable network card: ifconfig eth0 down
Enable network card: ifconfig eth0 up

View current routing table: route "or" route -n
View arp cache: arp "or" arp -n
Ping: ping -c 3 192.168.1.1
Trace Route: traceroute www.myroorkee.com
Trace Path: tracepath www.myroorkee.com
DNS Test: host www.myroorkee.com
Advanced DNS Test: dig www.myroorkee.com
Reverse Lookup: host 66.11.119.69
Advanced Reverse Lookup: dig -x 66.11.119.69

Nobody will ever need more than 640k RAM !

"Nobody will ever need more than 640k RAM!"
-- Bill Gates, 1981
"Windows 95 needs at least 8 MB RAM."
-- Bill Gates, 1996
"Nobody will ever need Windows 95."

-- logical conclusion

Thursday, January 3, 2008

How to add a new hard disk to Linux

Yesterday night I was planning to add a new hard drive to my Linux machine ( Ubuntu ), I thought it would be a difficult task, but to my surprise it was almost like a walk in the park.
here are the simple steps that made me through.
  1. Physically added the new hard drive ( Not yet partitioned )
  2. ls /dev/sd*
    1. This will give you a list of devices, you should be able to identify the device which you have recently added, it was easy for me as I saw something like this
    2. /dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb
    3. As /dev/sda seems to be portioned /dev/sdb is the new hard drive.
  3. Partition the new hard disk
    1. cfdisk /dev/sdb
    2. I created just 1 partition, you may have your own preferences.
  4. Format the partition
    1. mkfs -t ext3 /dev/sdb1
  5. Configure the system so as to auto mount the drive ever time you boot the system.
    1. Edit the /etc/fstab file
      1. vi /etc/fstab
    2. add the following line
      1. /dev/sdb1 /storage ext3 defaults 1 2
  6. Just to check if the file was correctly edited, type "mount -a" if no error is shown you are done.
  7. no need to reboot you new hard disk is accessible through /storage