Sunday, December 13, 2015

Linux command to get information related to a bind port

We can use following linux command to get details of a bind port.
lsof -i :port_number

[root@dhcppc1 ~]# lsof -i :5060
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
asterisk 3830 root    9u  IPv4  41463      0t0  UDP *:sip


Tuesday, December 8, 2015

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when executing asterix-java AGI server

I implemented an asterisk-java AGI script with MySQL DB integration and tried to execute with following command

java -jar asterisk-java-1.0.0.M3.jar

Server started successfully and called successfully to the service abstract method. How when the call flow met with a scripting line related to DB operations I always got the following run-time error.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 
This error can be resolved mentioning the class-path for  

mysql-connector-java-5.1.9.jar

I tried several standard ways to start the AGI server with mentioned class-path for jdbc but failed. Finally I found the way through following answer.
http://stackoverflow.com/questions/8818073/classnotfoundexception-com-mysql-jdbc-driver

I successfully started the AGI server and executed DB related functions by starting the AGI server jar file as follows.

java -classpath asterisk-java-1.0.0.M3.jar:mysql-connector-java-5.1.9.jar:. org.asteriskjava.fastagi.DefaultAgiServer

(asterisk-java-1.0.0.M3.jar & mysql-connector-java-5.1.9.jar are in the same location)

Thursday, December 3, 2015

JAVA Get a random number within a value range

Following method can be used to get a random value which is within a minimum and maximum value range.

//Import following class
import java.util.Random;
 
//Custom method to get a random value 
public int getRandomNum(int maxVal, int minVal){
    Random rn = new Random();
    return rn.nextInt(maxVal - minVal + 1) + minVal;
} 

Wednesday, November 4, 2015

Trace your Linux Top When doing Load Tests

This is a shell script which can be used to trace the top of the application-running machine and get a CSV including the load average, idle, res and processing for the particular application. A new record is added in each change of the top.

Link to Download the Script

You can start the shell script by (Don't forget to give executable permissions for the script as
chmod +x script_name.sh )
 
/path_to_the_script/top_tracer.sh

Script will ask for the following parameters.
Process ID for the process which you are interested.
A name for an intermediate text file which will be included whole top heading and record of the particular process. (text file will be created in the current location of the shell unless you give an absolute path)

Script will begin to record the top after pressing enter.

After the required time press CTRL + C to end the record.

Then script will ask for an absolute path with a name for the CSV. 

Eg Steps:-

/bin/top_tracer.sh
Enter the process ID :16986
Enter a text file name for write the top :/home/udara/blog_post_trace.txt
^CProvide the CSV path : /home/udara/blog_post_trace.csv




Eg CSV:-

load_avg, idle, res, processing
0.02, 94.0, 200960, 6.7
0.02, 98.9, 200960, 2.0
0.02, 98.2, 200960, 2.7
0.02, 98.4, 200960, 2.0
0.02, 97.9, 200960, 2.3
0.02, 98.1, 200960, 2.0
0.02, 95.1, 200960, 2.3
0.01, 96.6, 200960, 2.3



Eg TXT:-


top - 10:58:21 up  2:46,  5 users,  load average: 0.02, 0.06, 0.11
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.3 us,  0.9 sy,  0.0 ni, 94.0 id,  0.8 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  3940488 total,   329064 free,  2268192 used,  1343232 buff/cache
KiB Swap:  4063228 total,  4050076 free,    13152 used.  1110260 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
16986 udara     20   0  559444 200960  66972 S   6.7  5.1   2:44.25 skype



Sunday, March 22, 2015

VB Macro to find change over in an EXCEL data sheet



Logic of the following VB macro can be commonly used for an EXCEL worksheet by doing some modification of the logic sequence. This macro will change the background color of cells when found the first occurrence of a value which is different to the previous value set. 
Following hints will help you to identify how your logic sequence should be changed according to your requirement.  

c = 5 To 100 : used to indicate range of the columns of the data set. According to this code snippets program will consider values from column 5 to column 100.   

r = 2 To 100 : used to indicate range of the rows the data set. According to this code snippets program will consider values from row 5 to row 100.   

If (comparisonValue <> Cells(c, r + 1).Value) And (Cells(c, r + 1).Value <> "" And comparisonValue <> "") : According to this IF condition (c, r+1) cell background color will be changed if its value is different to (c, r) value and (c, r) is not empty. 

 
Sub FormatCells()

    Dim comparisonValue As String

    comparisonValue = ""

    For c = 5 To 100

        comparisonValue = ""

        For r = 2 To 100

            If Cells(c, r).Value <> "" Then

               comparisonValue = Cells(c, r).Value

            End If

            If (comparisonValue <> Cells(c, r + 1).Value) And (Cells(c, r + 1).Value <> "" And comparisonValue <> "") Then

                Cells(c, r + 1).Interior.ColorIndex = 8

            End If

        Next r

    Next c

End Sub

Wednesday, February 11, 2015

Linphone Error 'Your machine appears to be connected to an IPV6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6'

To resolve this error you can disable the IP V6 in your system as mentioned below. (I have successfully done this in ubuntu 12.04)

  1. sudo gedit /etc/sysctl.conf

  2. Now add these lines at the end of file:
  3. # IPv6
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1

  4. Save sysctl.conf file and close.

  5. Now Restart the system

Tuesday, November 25, 2014

Stop overflowing a HTML table and its content

If your HTML table and its content are overflowing, try this CSS combination.

table
{
            table-layout:fixed;
            width:100%;
            word-wrap:break-word;
}

Ref - http://www.456bereastreet.com/lab/table-layout-fixed/example-3.html