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

Saturday, November 22, 2014

.contains is undefined in JAVASCRIPT

String.contains(String) returns undefined in JS in most browsers except Mozilla firefox. We can replace above function with String.indexOf(String).

"Mycars".contains("My") returns true
"Mycars".contains("My1") returns false

"Mycars".indexOf("My") returns the index of the first character of 'My' within 'Mycars'
"Mycars".contains("My1") returns  -1

Sunday, August 24, 2014

How to Validate a Server

Validate a Server can be an important task when you are going to install a commercial applications with license only for specified servers. To validate a server we have to identify unique attributes related to servers. We can find unique attributes for a server both from software and hardware levels. Hardware level validation can be more reliable than software level since software level data can be easily fraudulently changed than the hardaware level data. But your selection may dependent on your requirements.
With this post I am describing how you can validate a server with hardware information. Simply you can access to Systems' hardware informations. As an example in Linux operating systems you can execute "dmidecode" and get the system information list (you can implement an application to execute those command programmatically using any programming language).
Then you can identify unique data elements related to a server like Serial Key, UUID, MAC etc.
You have to do a strign manipulation and retrive the those required values from the System information list.
Then for the best security we can  encrypt that value and also create a hash value from it. Now, we have a pre created and authenticated hash value. When ever we need to validate the server, what we have to do is dynamically create the hash value and compare with our stored pre-validated hash value.
If the two hashes are equal then the server validation is passed. If not server validation is false.