August 25, 2010

SQL query : Search sub string in column value string with delimeter

Input: String with proper delimeter as table column value
    ex:- /usr/tmp, /usr/tmp/psr, /usr/psr/dir1, /usr/psr/psr/dir1, /usr/lib
Output: substring between delimeter(,)
Note:
    1) This is SQL Query not PL/SQL program, its just a query
    2) User can search for only one string at a time
    3) User can change the search occurance i.e. need first occurance of the substring or nth occurance


SQL Query:



select substr(
        concat(',',concat(value1,',')),
        (instr(concat(',',concat(value1,',')), ',' , (instr(concat(',',concat(value1,',')),'psr',1,2) - length(concat(',',concat(value1,',')))),1)+1),
        (instr(value1, ',', (instr(concat(',',concat(value1,',')),'psr',1,2)),1)+1)-
        (instr(concat(',',concat(value1,',')), ',' , (instr(concat(',',concat(value1,',')),'psr',1,2) - length(concat(',',concat(value1,',')))),1)+1)
        )
as result
from check1


 Detailed Explanation:

1. Modify original string in this ",string," format
2. Search for the substring and find index of previous delimeter of the substring
3. Find the length of the substring

select substr(                        // value1 is column name
        // 1.Concatenating delimeter(,) before and after string
        concat(',',concat(value1,',')),

        // 2. Finding substring starting index
        (instr(concat(',',concat(value1,',')), ','
            , (instr(concat(',',concat(value1,',')),'psr',1,2)   
// Finding substring 'psr' 2nd occurance, user can change value 2 from (1 to n)th occurance
            - length(concat(',',concat(value1,','))))           
// Searching in reverse direction to find previous delimeter(,) index from substring
            ,1)                                    // Delimeter(,) index will be our starting of substring
            +1)                                    // Not including delimeter(,) in substring display

         // 3. Finding length of the substring
         // Finding next delimeter(,) index from substring
         ,(instr(value1, ',', (instr(concat(',',concat(value1,',')),'psr',1,2)) ,1)+1)-
      
        // Finding length between two delimeters(,) i.e. length of substring
        (instr(concat(',',concat(value1,',')), ',' , (instr(concat(',',concat(value1,',')),'psr',1,2) - length(concat(',',concat(value1,',')))),1)+1)
        )
as result                            // Displaying column as result
from check1                            // Table name check1

May 23, 2009

My M.Tech Thesis

I am doing the project "Simulating an efficient NIDS on gigabit ethernet communication". To acheive my objectives, I installed Snort NIDS and lot of its dependencies. It took time for me to configure properly because of lack of guidance. Finally my internal review was good. I am satisfied..I will provide my abstart here.. see and give me suggestions..

Intrusion Detection for network security is a compute intensive application demanding high system performance. Objective of thesis is to simulate a testbed evaluation of an efficient Intrusion Detection System (IDS) on gigabit ethernet communication. Testbed [3] includes forming a network with the both Network Intrusion Detection System (NIDS), Snort and attacker, who will generate live traffic [1]. By writing efficient rules for the snort, it will generate alerts which can be visually displayed in browser by using plug-ins. Running the Snort in a live network and the flooding the network with a variety of traffic, both “normal” (legitimate traffic that any network would reasonable expect to occur such as e-mail, HTTP, telnet etc) and attacks, including fairly recent and more well-known network attacks [5]. The pre-design tool allows for more efficient communication and extensive reuse of modules for dramatic increases in area-time performance. We can implement this simulation part on hardware with efficient performance.

May 08, 2009

Failed in IIT Kanpur Ph.D Written Test

I applied for the Ph.D in IIT Kanpur and in written test i got failure..But here the facilities are very good..I am impressed with this facilities here..I am thinking again i will apply here in November(Winter Admissions)...Let me try my luck in IISc Bangalore..There also i applied Operating Systems Ph.D..I am interested to do in Operating Systems..I dont know how far i will go..Anyway friends thanks for giving the moral backup..Love u All..URS PSR.COM

January 06, 2009

Applied for Civil Services

I applied for civil services 2009. My dad always says to me that we have to do something good for the society. So, I decided to write Civil Services. Wish me ALL THE BEST Friends. Hope you will encourage me.

December 15, 2008

My III Sem result

I got 3rd position in III Sem result...I dont know how I got...with god's grace and my friend's help i got 8.61 CGPA...After my AP and Kerala Trip, i am creating new post to blog...I will update my photos soon....till that Advanced Happy Christmas...and Adavanced Happy New Year...

November 03, 2008

My first Matlab Program, Encode and Decode image using Huffman Coding

For the academic purpose i had written a small program in Matlab.

I have tried encoding and decoding the image by using Huffman coding.

Huffman code generally used for data encoding but i tried Huffman coding on small image.

Preconditions:
  1. You need to create a small image, in my code i am using PSR.jpg
  2. It will work well only with small images

Matlab Code:

%Huffman Coding on image by Suresh Raju Pilli

%clearing all variableas and screen
clear all;
close all;
clc;

%Reading image
a=imread('psr.JPG');
figure,imshow(a)

%converting an image to grayscale
I=rgb2gray(a);

%size of the image
[m,n]=size(I);
Totalcount=m*n;

%variables using to find the probability
cnt=1;
sigma=0;

%computing the cumulative probability.
for i=0:255
k=I==i;
count(cnt)=sum(k(:))

%pro array is having the probabilities
pro(cnt)=count(cnt)/Totalcount;
sigma=sigma+pro(cnt);
cumpro(cnt)=sigma;
cnt=cnt+1;
end;


%Symbols for an image
symbols = [0:255];

%Huffman code Dictionary
dict = huffmandict(symbols,pro);

%function which converts array to vector
vec_size = 1;
for p = 1:m
for q = 1:n
newvec(vec_size) = I(p,q);
vec_size = vec_size+1;
end
end

%Huffman Encodig
hcode = huffmanenco(newvec,dict);

%Huffman Decoding
dhsig1 = huffmandeco(hcode,dict);

%convertign dhsig1 double to dhsig uint8
dhsig = uint8(dhsig1);

%vector to array conversion
dec_row=sqrt(length(dhsig));
dec_col=dec_row;

%variables using to convert vector 2 array
arr_row = 1;
arr_col = 1;
vec_si = 1;

for x = 1:m
for y = 1:n
back(x,y)=dhsig(vec_si);
arr_col = arr_col+1;
vec_si = vec_si + 1;
end
arr_row = arr_row+1;
end


%converting image from grayscale to rgb
[deco, map] = gray2ind(back,256);
RGB = ind2rgb(deco,map);
imwrite(RGB,'decoded.JPG');

%end of the huffman coding

Postcondition:
  1. Check the original image and decoded image
  2. Analyze the compression ratio.
You can easily understand the code. Its not at all difficult.

Please send your feedback and comments to psrdotcom@gmail.com

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com