Search for wild characters in sql search query

•May 14, 2014 • Leave a Comment

Use case : 
need to search for special characters like %,_ using sql query

Example:
Search for all names in a table which start with _

Now if you use the regular like statement it won’t work since _ is a special character in SQL which basically allows you to match on a single character.
Correct way to do would be to escape the special character _ in like query like this  

select * from MY_TABLE where NAME like’%!_SOMETHING%’ escape ‘!’ ;

Reference : 
http://www.techonthenet.com/sql/like.php 

 

Send attachment in mail on Linux using mutt.

•February 18, 2014 • Leave a Comment
You can use the following command to send a file as an attachment from your linux machine.

$ echo | mutt -a myFile.txt myAlias@something.something

C3P0 connection Setting Best Practices

•December 11, 2013 • Leave a Comment

Hi,

I came across an interesting C3P0 connection settings documents. Good read in case you are interested in tweaking your c3p0 connection settings for your software : http://www.mchange.com/projects/c3p0/index.html

How to drop packets for a particular DNS by updating your IP table

•November 27, 2013 • Leave a Comment

Use Case :
You want to replicate a scenario where one/many of your dependent services goes down. You want to see how your service behaves in such dependency failure cases.

Commands to drop iptables for the dependent service :
Use the following commands to update your IP table to block traffic the traffic

To block

“sudo iptables -A INPUT -j DROP -p tcp –source <dns name>”

To unblock

“sudo iptables -D INPUT -j DROP -p tcp –source <dns name>”

How to split files into smaller files using split command

•November 5, 2013 • Leave a Comment

Use Case :

While dealing with very large files sometimes we need to split the files into smaller chunks in order to work on different segments of the file at the same time.  Mostly this is required to do parallel work.

Use Unix split utility :

Unix/linux has inbuilt utility called split which can be used for this purpose.

split -l <no of lines each file should have> <fileToSplit> <prefix for names of smaller files>

 

for example : Lets say there is a large file named myFile.txt having 100 lines. You need to split this into smaller files having 10 lines each. Run the following command to achieve this

split -l 10 myFile.txt mySplitFile

This would create 10 files each having 10 lines in them having the following names :

mySplitFileaa, mySplitFileab, mySplitFileac … and so on.

Oracle SQLPLUS spool command to get query output in csv file

•November 3, 2013 • Leave a Comment

Use case : 

Get output of the sql query in .csv file with “comma” separated delimiter.
The file should not have any extra spaces
Single output per line

Solution : 
Use delimiter as ||’,’|| instead of plain comma. || characater acts as TRIM here.

1. spool output.txt
2. select name ||’,’||, age ||’,’||, id from employeeTable;
3. spool off

Jackson Polymorphism Deserialization

•October 11, 2013 • Leave a Comment

So recently I had a use case where I wanted to use jackson to convert an object into json string/bytes, sent it across wire and then deserialize it back.

The object consisted of attributes which were abstract and hence default jackson deserialization was not working.

I was getting the following Exception while deserializing :

Can not construct instance of <packageName> , problem: abstract types can only be instantiated with additional type information

The issue was : in case of polymorphic objects during deserialization we need additional information in order to know which particular class type was actually present during serialization.

jackson provides  a way to add this information by using the following line : 

  // one of:
  objectMapper.enableDefaultTyping(); // default to using DefaultTyping.OBJECT_AND_NON_CONCRETE
  objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

So to solve the issue : just add any one of the above lines before serializing the object. During deserialization the jackson would be able to convert the byte string into the original object by using the additional information about the type of the object attributes.

Reference : http://wiki.fasterxml.com/JacksonPolymorphicDeserialization

Hard Disk Full : Find largest directory

•September 2, 2013 • Leave a Comment

Sometimes many software engineers face the issue that their hard disk gets full. Mostly such scenarios are due to some random and unneeded files generated due to some leak process.

And its not possible to delete any directory / file in such scenarios. We need to find the root cause i.e. the directory which is occupying the maximum space and then find the files which are present in that directory.

The best way to solve this issue without killing the machine is to recursively check from the root i.e. / and keep on finding the directory with maximum space using the following command :

av.dubey@av.dubey>du -k – -max-depth=1 2>/dev/null | sort -nr -k1

5684228 ./usr
469492 ./var
206776 ./lib
181912 ./opt
117416 ./tmp
.
.

So for example by running this on root its clear that /usr is occupying the maximum space. now dig into /usr and do the same thing.

Why not write a script and keep on sorting the directories with decreasing size?
You can but this is always risky, cause in such scenarios there are high chances that if you run some heavy script you might bring the machine down temporarily or it might not respond for sometime. This is not always an option when you are dealing with production machines. So kindly trade off your options before running any cool script.

How to increase heap memory in eclipse

•February 12, 2012 • Leave a Comment

eclipse -vmargs -Xmx2048M -XX:PermSize=64M -XX:MaxPermSize=512M

 

RHEL5 FEDORA — yum install giving Nothing to do

•March 18, 2011 • 9 Comments

Problem:
yum install was not working
whenever i was trying to install some s/w using yum, it used to check local repository and ended up saying Nothing to do

Solution:
Actually whenever we install some s/w or package using yum , it looks into cd /etc/yum.repos.d/*.repo files
there you would see many different sections under heading
[heading]
baseurl=http://

yum looks for the package under these mentioned repositories i.e. baseurls

just add one more section with this heading to make it look for open source pkgs under fedora repository (works both for rhel5 and fedora)

example.. this worked for me

i wasn’t able to install pkgs like perl,perl-WWW::Mechanize, yumex etc

avidubey@avidubey] cd /etc/yum.repos.d /etc
avidubey@avidubey] ls /etc/yum.repos.d
already-present.repo MyOwn.repo
avidubey@avidubey] cat MyOwn.repo /etc/yum.repos.d
[MySection]
name=MyOwnRepo
baseurl=http://download.fedora.redhat.com/pub/archive/fedora/linux/updates/7/i386/
enabled=1
gpgcheck=0