Monday, September 5, 2016

IPv6 Notes


Type if IPv6 Addressing modes:
1) Unicast addresses
2) Multicast addresses
3) Anycast addresses

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

Special Address in IPv6:
  1. Global addresses
  2. Link-local addresses
  3. Site-local addresses
  4. Unique local addresses (ULA’s)
  5. IPv4 mapped IPv6 addresses
  6. IPv4 compatible IPv6 addresses
  7. Special unicast addresses
  8. Multicast addresses
Reference: Please see RFC 1884 - IP Version 6 Addressing Architecture for more information. 

1.Global unicast addresses:
Address scope is the whole IPv6 Internet, Equivalent to public IPv4 addresses
Defined in RFC 3587:
2001:DB8::/32 – documentation-only prefix

2.Link-local addresses:


fe80::/10 This is a link-local prefix offered by IPv6. This address prefix signifies that the address is valid only in the local physical link.
Automatically configured on an interface using MAC address , Address scope is limited to the local link and shall used to send neighbor solicit messages

Eg: if MAC Address(48bits):                                                 00:90:27:17:FC:0F 
MAC Convert to colon hexadecimal notation :            ::0290:27FF:FE17:FC0F
The link-local address for the host is:                 FE80::0290:27FF:FE17:FC0F

3. Site-local addresses : Depricated and replaced by Unique local addresses

4. Unique local addresses(ULA):

fc00::/7 This is called the Unique Local Address (ULA). These addresses are routed only within a set of cooperating sites. These were introduced in the IPv6 to replace the site-local addresses. These addresses also provide a 40-bit pseudorandom number that reduces the risk of address conflicts.
Globally unique and are intended for local communications
Not routable on global Internet, routable within organization
Replaced the site-local addresses
Global scope, no zone ID required 

Defined in RFC 4193

5. IPv4 mapped IPv6 address:
Used by IPv6 only application to be able to deal with IPv4
requests.  Requires dual stack configured on the host. Defined in RFC 4291

Example:  IPv4-mapped IPv6 address for the IPv4 address 192.168.0.189 is:

0:0:0:0:0:FFFF:192.168.0.189 = ::FFFF:c0a8:bd

6. IPv4 Compatible IPv6 Address:
::/96 The zero prefix denotes addresses that are compatible with the previously used IPv4 protocol.

Used by IPv6 only application to be able to deal with IPv4 requests. Requires dual stack configured on the host

Example:  IPv4-comaptible IPv6 address for the IPv4 address 192.168.0.189 is: 
0:0:0:0:0:0:192.168.0.189  = ::C0A8:BD

7.Special unicast addresses:


::1/128 This is called the loop back address and is used to refer to the local host. An application sending a packet to this address will get the packet back after it is looped back by the IPv6 stack. The local host address in the IPv4 was 127.0.0.1 . 
Loopback unicast address – 0:0:0:0:0:0:0:1 = ::1
Similar to IPv4 address 127.0.0.1
Used by a node to send an IPv6 packet to itself
Should not be assigned to any physical interface


::/128 An IPv6 address with all zeroes in it is referred to as an unspecified address and is used for addressing purposes within a software. 
Unspecified unicast address – 0:0:0:0:0:0:0:0 = ::
Similar to the IPv4 address 0.0.0.0
Indicates the absence of an address


2001:db8::/32 This is a documentation prefix allowed in the IPv6. All the examples of IPv6 addresses should ideally use this prefix to indicate that it is an example.

8.Multicast IPv6 addresses:


ff00::/8 This prefix is offered by IPv6 to denote the multicast addresses. Any address carrying this prefix is automatically understood to be a multicast address. 

An identifier for a set of interfaces (typically on different nodes). Defined in RFC 4291.
Some reserved multicast addresses:

FF02::1 (link-local scope, all nodes on the link)
FF02::2 (link-local scope, all routers on the link)
FF05::2 (site-local scope, all routers in the site)

FF02:0:0:0:0:1:FFXX:XXXX (Solicited-node multicast address)

Tunneling:
Encapsulating IPV6 packets into IPV4 packets.IPV6 packets becomes the payload part of the IPV4 packets. It is called 6-to-4 tunnelling.

Neighbor Discovery Replaces ARP (Address Resolution Protocol):
Refs: http://ipv6.com/articles/general/Stateless-Auto-Configuration.htm

Example: TP link configuration of DHCP http://www.tplink.com/be/article/?faqid=855

a) Router Solicitation (request something): 
Send by host to routers with src address is the link-local address of the host and destination address is FF02::2

b) Router Advertisement: 
Send by routers periodically or in response to a Router Solicitation message, Source address is the link-local address of the sending router and Destination address is the unicast address of a node that sent a Router Solicitation or FF02::1

Stateless Address  Auto congiuration (SLAAC):
https://supportforums.cisco.com/document/97586/dynamic-address-assignment-ipv6-using-slaac-and-dhcp
http://www.ciscopress.com/articles/article.asp?p=2154680

Lets Hands on:
  • On Windows client:
    • netsh interface ipv6 install/uninstall
      • IPv6 is installed and enabled by default on Windows Vista and Windows 2008 Server
    • netsh interface ipv6 add address "Local Area Connection" fd00::c0a8:64
  • On Linux client:
    • ifconfig  eth0 inet6 add fd00::c0a8:c7/64
  • On Solaris client:
    • ifconfig e1000g0 inet6 addif  fd00:1:11:5a:214:4fff:fe86:1111/64 up

Experiences:
$ ping6 -I wlan0 fe80::3602:86ff:fe63:3b0c      == My link-local ip
PING fe80::3602:86ff:fe63:3b0c(fe80::3602:86ff:fe63:3b0c) from fe80::3602:86ff:fe63:3b0c wlan0: 56 data bytes

64 bytes from fe80::3602:86ff:fe63:3b0c: icmp_seq=1 ttl=64 time=0.038 ms

$ping6 -I wlan0 ip6-allrouters -n   
Routers responded back

Monday, May 23, 2016

XAMPP PHP errors


Sample : info.php to test PHP version <!--php // Show all information, defaults to INFO_ALL phpinfo(); // Show just the module information. // phpinfo(8) yields identical results. phpinfo(INFO_MODULES); ?--> Enable error on html Error #1: File not fount error <br/> <b>Warning</b>: simplexml_load_file(): I/O warning : failed to load external entity "../data/asset.xml" in <b>E:\xampp\htdocs\NFPDL\live\php\getAssetMenuListJson.php</b> on line <b>78</b><br /> <br/>

Tuesday, March 1, 2016

JavaScript: Quick reference



function logt(msg)
{
  if(navigator.appName == "Netscape")
    console.log("[DBG]: " + msg);
  else
    alert("[DBG]: " + msg);
}
------------Method to convert secs to HH MM SS --------------------------------
function getSecsInHHMMSS(secs){
    var hh = ("0" + Math.floor(secs/3600)).slice(-2);
    var mm = ("0" + Math.floor((secs%3600)/60)).slice(-2);
    var ss = ("0" + Math.floor((secs%3600)%60)).slice(-2);
    var hhmmss=hh+":"+mm+":"+ss;
    return hhmmss.toString();
}
//getSecsInHHMMSS(100) will returns  00:01:40

-------------Method to parse the query string --------------------------------------
function getQueryValue(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=');
        if (decodeURIComponent(pair[0]) == variable) {
            return decodeURIComponent(pair[1]);
        }
    }
    logt('Query not found :'+variable);
    return "";
}

//Now make a request to index.html?mins=120
durr=getQueryValue('mins') * 60;
document.getElementById("endtime").innerHTML = getSecsInHHMMSS(durr);

-------------Method to print Key name of JSON obj using values -----------

//This defines a method called getKeyByValue() to any object which
// returns the Key name using value of JSON format
Object.prototype.getKeyByValue = function( value ) {
    for( var prop in this ) {
        if( this.hasOwnProperty( prop ) ) {
             if( this[ prop ] === value )
                 return prop;
        }
    }
}

var test = { Key1:11, Key2:22, Key3:33 }
alert(test.getKeyByValue (33))   # This will print "Key3"

Monday, October 26, 2015

vimdiff tool usage notes

vimdiff Keyboard Shortcuts:

do - Get changes from other window into the current window.

dp - Put the changes from current window into the other window.

]c - Jump to the next change.

[c - Jump to the previous change.

Ctrl W + Ctrl W - Switch to the other split window.

:qa to quit all
:qa! to quit all without saving
:wqa save and quit all

Note: 
  • If you load up two files in splits (:vs or :sp), you can do :diffthis on each window and achieve a diff of files that were already loaded in buffers
  • :diffoff can be used to turn off the diff mode. 

Link: http://amjith.blogspot.in/2008/08/quick-and-dirty-vimdiff-tutorial.html  

Sunday, October 25, 2015

Google Repo command


Google Repo Command tips:

Intro: The Google repo command used to manage multiple git repository under single umberlla.


To list status for all git repo
repo forall -c 'git status'

To lists status for all with repo name git repository under manifest
repo forall -c 'pwd; git status'
repo forall -c 'pwd; git status -s| cut -c4- '

To pull all the repo changes
repo forall -c 'git reset --hard'
repo forall -c 'git clean -fd'
repo sync && repo start --all



Friday, October 16, 2015

Git commands


Basics:
========
To add files to be committed      
  git add 
To commit a change in the local tree. To be done after the git add.
  git commit -m "comment about the changes"
To push the changes or checkin the changes to main branch    
  git push
To discard all changes done in a branch locally
  git stash save --keep-index
  git stash drop
    
To create a new branch     
  git checkout -b myBranch
 
To create a patch from the local branch
 Before this check out a new branch, do all changes in the branch, verify it. And then commit those changes. Do not push the changes to master.
 git format-patch master --stdout > myPatch.patch

git reset  updates the index for that path so that it matches HEAD (the current commit). 
It doesn't touch the working tree

git rm --cached -r  to remove a directory which was added.
 
GT Diff:
==========
git diff HEAD@{1}
The @{1} means "the previous position of the ref I've specified", so that
evaluates to what you had checked out previously - just before the pull.

git diff HEAD@{1} filename
This is a general thing - if you want to know about the state of a file
in a given commit, you specify the commit and the file, not an ID/hash
specific to the file.

git diff --cached --name-only   
It lists the filenames in the staging area that will be committed to git. Can be used after all the files to be committed are added thru 'git add'  to verify only intended files are being commited

git difftool --cached
the diff of files that are about to be committed against the head will be showed in vimdiff one by one.

git difftool  
the diff of files in the two commits will be shown in vimdiff one by one.

git log --pretty=oneline
compact display of git log

how about 
  • git diff --name-only for changes relative to index
  • git diff --name-only --staged for ... well staged chages :)
  • git diff --name-only HEAD got both
To get the modified files alone:
git status --porcelain|awk '{if($1=="M") {print "basename " $2}}'|sh

To copy the modified files alone to a remote server, as below:
git status --porcelain|awk '{if($1=="M") {print "scp " $2 " account_name@server_ip:~/my_codebase/$(dirname " $2 ")/;"} }'|sh


Global GIT Configuration: ~/.gitconfig

#vi ~/.gitconfig
[alias]
    st = status
    ci = commit
    br = branch
    co = checkout
    df = diff
    dc = diff --cached
    lg = log -p
    who = shortlog -s --
    changes=diff --name-status -r
    diffstat=diff --stat -r
    logtree = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
    last = log -1 HEAD
    tree = log --graph --decorate --pretty=oneline --abbrev-commit
     # format %cd with --date=short cuts the timezone in log 
    ll = log --graph --pretty=format:\"%C(yellow)%h %C(green)(%cd)%C(auto)%d %Creset%s [%an]\" --date=short
    logtree = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
 
[user]
        email = emailid@email.com
        name = Name S
[color]
        ui = auto
[diff]
        tool = vimdiff



# run
git config --global diff.tool vimdiff  #to defibe difftool
git difftool    # launch vimdiff with changes

This will add alias "tree"
git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"

For external file diff usage
[diff]
    external = /bin/git-meld.sh


$ cat /home/<dir>/bin/git-meld.sh
#!/bin/bash

meld $2 $5





vi editor ~/.vimrc



" Run time config for vim editor
set cindent    " for c indentation(correct spacing)
syntax on    "To color the VIM editor
set nu ” line numbers
set ts=4 " –> for tab spaces set to four per tab character
set sw=4 "–> Set the shift width to four spaces
set spell " –> set spellchecking on
 set spl=en "–> Set spelling language to english
set ai "–> Enable auto indentation
set nu "–> Enables line numbers
" To remember last position of open file
if has("autocmd")
  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

endif

Thursday, May 21, 2015

Highlight the anchor in HTML




To highlight the anchor use following css style code:

<style type="text/css" >
a{color:orange;text-decoration:none;font:bold} 
a:focus{color:cyan}
</style>
<script>
function FocusOnInput(){
        document.getElementById('text').focus();
}
//Add FocusOnInput() in onload event in the body attribute:
</script>

< body onload="FocusOnInput()" >

use id="text"   # highlighthe first componenet

Eg:
<a  id="text" href="http://google.com"> </a>


Note:  DOM Level 2 HTML
only elements that have a focus() method are 
HTMLInputElement, 
HTMLSelectElement, 
HTMLTextAreaElement and 
HTMLAnchorElement.       eg: <a  id='text' hreaf= ... >
And this notably omits HTMLButtonElement and HTMLAreaElement.

Logging on condition:
function logt(msg) 
{
  if(navigator.appName == "Netscape") {
    console.log("[DBG]: " + msg);
    }  else {
   alert(msg); }
}

Monday, November 18, 2013

How to make the tmp file system volatile


mount -t tmpfs -o size=65536 tmpfs /tmp
With size restricted /tmp dir created .
 For this you need enable temp file system in Linux kernel.

 mount -t tmpfs -o size=$((192 * 1024)) tmpfs /var

 For example in nfs create a temporary fs to hold core files alone:

 #update the core file pattern
echo "/var/core/core.%e.%p" > /proc/sys/kernel/core_pattern
mkdir -p /var/core
mount -t tmpfs -o size=$((32 * 1024)) tmpfs /var/core

PHP example


HTML Client :  demo.html

<!DOCTYPE html>
<html>
<head>
<script src="javascript/jquery/jquery-1.9.1.min.js"></script>
<script>
http_post = function(){
var data = $.ajax({
        type: "POST",
        async: false,
        url: 'http://10.30.130.125/demo.php',
        data: ({request : {ID:"hello world"} }) 
        }).responseText;
         //return eval('(' +data +')');
//eval('(' +data +')');
//alert (data);
document.getElementById("demo").innerHTML=data ;
<!---document.getElementById("demo").innerHTML="Hello World";  -->
}
</script>
</head>
<body>
<p>Click the button to trigger a function.</p>
<button onclick="http_post()">Click me</button>
<p id="demo"></p>
</body>
</html>


PHP File: demo.php

<?php
error_reporting(E_ALL);
$in_str = "None" ;
if ($_POST) { 
//var_dump($_POST['request']) ;

$in_str = '{"demo":"'.$_POST["request"]['ID'].'"}' ;
//$in_str = $_POST["request"] ;
}

$service_port = '5000' ; 
$address = '10.30.130.170' ;

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

$result = socket_connect($socket, $address, $service_port);

echo $in_str ;

/* write into TCP/IP socket.*/
socket_write($socket, $in_str, strlen($in_str)); 

/* read from TCP/IP socket. */
$out = socket_read($socket, 4096);

/* Closing socket... */
socket_close($socket);

//$out = "{\"a\":1 }" ; 
header('Access-Control-Allow-Origin: *');
echo $out;
//echo '{"hi": 1 }';

/*echo "{\"a\":1 }" ;*/

?>

C Server Socket code below:

#include < sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include <sys/types.h>

int main(int argc, char *argv[])
{
    int listenfd = 0, connfd = 0;
    struct sockaddr_in serv_addr;
        char recvBuff[1024];
    int data = 65;
        int  n  ;
    time_t ticks;

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(&recvBuff, '0', sizeof(recvBuff));

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(5000);

    bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

    listen(listenfd, 10);

    while(1)
    {
        connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
        n = read(connfd, recvBuff, sizeof(recvBuff)) ;
        recvBuff[n] = 0;
        printf("Recieved Client request.\n") ;
        printf("%s\n" , recvBuff) ;  // Received string will be ID => {"demo":"hello world"} 
        if(strstr(recvBuff, "hello world")== 0) 
        {
         write(connfd, &data, sizeof(data));
         close(connfd);
        }
        else
        {
          printf("%s\n" , recvBuff) ;
        }
        data++ ;
     }

}

Thursday, February 16, 2012

TT Specifications

Specs:

1.Blades
1.1.Handles
The Shakehand Models
AN - Anatomic Handle
FL- Flare Handle
ST -Staright handle
The penhold models
(It has rubber on only one side, hence to reduce weight, Asian use to hold
like a pen and drives the all shots in one side.)
CS-Chinese penhold
Jp- Japanese penhold
2.Rubber

Click here to search local butterfly rackets

Read b before you buy

Sunday, December 4, 2011

Look at a String literals



#include <stdio.h>
#include <string.h>
char *ap1="char *ap1";
static char *ap2="static char *ap2";
int ii;
main()
{
int i;
char a[] ="char a[]";
char a1[] ="char a1[]";
static char a2[32] ="static char a2[10] ";
const char a3[32] ="const char a3[10] ";
char *ap ="char *ap";
static char *aptr ="static *aptr";

printf("strlen a[] %d \n",strlen(a));
printf("sizeof a[] %d \n",sizeof(a));
printf("a[sizeof] %d \n",a[strlen(a)]);

char help[20]="a b c d e ";

printf("local:\n&i %p %d \n",&i,i);
printf("a1 %p %s \n",a1,a1);
printf("a2 %p %s \n",a2,a2);
printf("a3 %p %s \n",a3,a3);
printf("*ap %p %s \n",ap,ap);
printf("*aptr %p %s \n",aptr,aptr);
printf("global:\n*ap1 %p %s \n",ap1,ap1);
printf("*ap2 %p %s \n",ap2,ap2);
printf("&ii %p %s \n",&ii,ii);

}

[output]: ./a.out

strlen a[] 8
sizeof a[] 9
a[sizeof] 0
local:
&i 0xbff103f8 -1074723816 < stack
a1 0xbff103e5 char a1[]
a2 0x8049940 static char a2[10]
a3 0xbff103c5 const char a3[10]
*ap 0x80486d8 char *ap
*aptr 0x80486cb static *aptr
global:
*ap1 0x80486b0 char *ap1
*ap2 0x80486ba static char *ap2
&ii 0x8049968 (null)

NULL in stdio is ((void*)0)

Tuesday, November 29, 2011

Quick Makefile


CC=gcc
S = file1.c file2.c

O = $(S:%.c=%.o)


exe: ${O}
     $(CC) ${LIBS} -o $<



# pull in dependency info for *existing* .o files
-include $(OBJS:.o=.d)

%.o: %.c 

 $(CC) ${INCLUDES} $(CFLAGS) -MMD -o $@ -c $<
 gcc -MM $(CFLAGS) $*.c > $*.d


.PHONY clean
clean:
     \rm -rf *.o exe


Note: Green highlighted stuff optional or use -MMD, are used to create dependencies

Another Example:
--------------------
ERR = $(error found an error!)
.PHONY: err

err: ; $(ERR)

Thursday, October 27, 2011

Vi Tips - QuickFix


See
:help :compiler
:help :make

(the latter without a preceding exclamation mark) which will
automagically display the first error (if any) as soon as the make job
terminates. (Not sure if you'll get to the first _warning_ or _error_),
and a few other useful commands for use after that:

:cfir[st]
:cla[st]
:cn[ext]
:cp[revious]
:cnf[ile]
:cpf[ile]

for navigating the error list, and

:cope[n]
:ccl[ose]

to see it in its own window (the "quickfix" window), where hitting Enter
on an error moves to that line in the source. Of course, these commands
can be mapped for ease of use; for instance I have the following in my
vimrc:

:map :cnext
:map :cprev

which I use not so much for compiling but for the ":helpgrep" and
":vimgrep" commands (whose results also come in a quickfix window).

See also ":help quickfix.txt"



====================Vimdiff ==================
# vimdiff
Most of what you asked for is folding: vim user manual chapter on folding. Outside of diffs I sometime use:
   * zo -> open fold.
   * zc -> close fold.
But you wll probably be better served by:
   * zr -> reducing folding level.
   * zm -> one more folding level, please.
or even:

   * zR -> Reduce completely the folding, I said!.
   * zM -> fold Most!.
   
]c - Jump to the next change.
[c - Jump to the previous change.
:diffupdate :diffu -> recalculate the diff,

Sunday, August 21, 2011

Good Technical Books

1. Computer Architecture and Organization by John P. Hayes
Publisher: McGraw-Hill Companies; 3rd edition (December 1, 1997)
ISBN-10: 0070273553
ISBN-13: 978-0070273559http://www.blogger.com/img/blank.gif

2. Solid State Pulse Circuits by Bell David A
ISBN: 8120307445,
ISBN-13: 9788120307445
Publisher: Prentice Hall PTR

3. THREADTIME: Multithreaded programming guide by Scott J. Norton, Mark D. Dispasquale
Publisher: Prentice Hall PTR (November 1, 1996)
Language: Englishhttp://www.blogger.com/img/blank.gif
ISBN-10: 0131900676
ISBN-13: 978-0131900677
Link1: Google.books

4.The Magic Garden Explained: the Internals of Unix System V Release 4: an Open Systems Design By Berny Goodheart James Cox.
Publisher: Prentice Hall
Author: Berny Goodheart James Cox
ISBN: 0130981389
EAN: 9780130981387

Thursday, July 7, 2011

Step to extract a specific file from tar ball

1) zcat compressed.tar.Z | tar xvf - file1 file2
2) cat compressed.tar | tar xvf - file1 file2
3) tar -xf filename.tar file1 file2

Wednesday, May 18, 2011

JDBC Applications with MySQL


$cat Connect.java
import java.sql.*;

public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
//String query = "Select * FROM mysql.user";
String query = "Show databases";
String dbtime;
try
{
String userName = "root";
String password = "mysql";
String url = "jdbc:mysql://10.255.6.58/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);

System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
System.err.println ("Message :"+e.getMessage());
System.err.println ("Error message: " + e);

e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {
dbtime = rs.getString(1);
System.out.println(dbtime);
} //end while

conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}


Compile Connect.java to produce a class file Connect.class that contains executable Java code:

% javac Connect.java

Then invoke the class file as follows and it should connect to and disconnect from your MySQL server:

% java -classpath .:/path/mysql-connectorJ-5.jar Connect
Database connection established
mysql
test
userdb
Database connection terminated


http://www.kitebird.com/articles/jdbc.html
http://download.oracle.com/javase/tutorial/jdbc/basics/connecting.html
http://www.java-samples.com/showtutorial.php?tutorialid=9

Tuesday, November 23, 2010

Auto Login using expect script


#!/bin/expect -f
# Parse argument Variables
set user [lrange $argv 0 0]
set ipaddress [lrange $argv 1 1]

spawn ssh -l user ipaddress
match_max 100000
# Look for passwod prompt
set timeout 2
expect "*(yes/no)?" {
send "yes\r"
}
expect "*?assword:*"
send "password\r"
interact
expect eof


---End---

./test user 192.1.1.1

Enablling traces in Bash script


#!/bin/bash

# require that all variables be set, otherwise the bash script will abort
set -o nounset

# pltTrace=2 # uncomment pltTrace to enable trace

export nodeType=""
export BaseProgName=`basename $0`
export ProgName=${BaseProgName}.$$

# if pltTrace is not already defined, define it
# this will allow individual programs to be
# debugged without turning on debugging for
# all scritps that source this file
if ! [ ${pltTrace:+1} ]
then
declare -x pltTrace=0
#change pltTrace to 1 to turn on debug for
# all scripts that haven't defined pltTrace
fi

if [ $pltTrace -ge 2 ]
then
PS4='${ProgName}:$LINENO: pltTrace-> '
set -o xtrace
fi

echo `date '+%Y%m%d.%H%M.%S'` ${BaseProgName} ": ENTER: Echoing here ..."

echo hello
if [ ! : ]; then
echo hello 2
fi
echo hello 3

---END---
Execute:
export pltTrace=2
./test

ttest.16898:37: pltTrace-> date +%Y%m%d.%H%M.%S
test.16898:37: pltTrace-> echo 20101124.0558.51 test ': ENTER: creating ZFS pools and files systems ... starting'
20101124.0558.51 test : ENTER: creating ZFS pools and files systems ... starting
test.16898:40: pltTrace-> echo hello
hello
test.16898:42: pltTrace-> '[' '!' : ']'
test.16898:47: pltTrace-> echo hello 3
hello 3

Monday, May 31, 2010

How to Use Purify

To use purify, you must create an instrumented executable file. For example, if your program consists of two files named main.C and List.C, you could created an instrumented executable named a.out by typing:

purify g++ -g main.C List.C

(As usual, use the -o flag to produce an executable named something other than a.out.)

Once you have produced an instrumented executable, just run it in the usual way (by typing its name, and, if your program is designed to use them, the appropriate command-line arguments).

Don't be surprised if the instrumented executable runs much more slowly than the non-instrumented version; it may also be much larger than the non-instrumented version.

And Run the executable automatically purify window will get opened along with the your executable.

Visit Following link for example
http://pages.cs.wisc.edu/~cs368-1/handouts/purify.html#example

Thursday, April 23, 2009

How to Create Stored Procedures and Functions in a MySQL Database

Over the past few years one major advantage that some databases, such as Oracle and Microsoft SQL Server, have had over MySQL is their ability to use stored functions and stored procedures. Well, that was before MySQL 5; with MySQL 5 a database developer can start adding in their own bespoke functionality.
What are Stored Procedures and Stored Functions?

Any programmers reading this should already be comfortable with the concept of subroutines and functions: encapsulated pieces of code that can be called by programs - often used to carry out repetative or complicated tasks.

Subroutines and functions can be made available to a single program or many; and that, of course, is what stored procedures and stored functions are - they are procedures (or subroutines) and functions stored in the database.
What's the Difference Between a Stored Procedure and a Stored Function?

The difference between a stored procedures and stored functions is the same as the difference between a subroutine and a function:

* a stored procedure runs some code
* a stored function runs some code and then returns a result

Why Use Stored Procedures and Stored Functions?

The real advantage to using stored procedures and stored functions is that they provide functionality which is platform and application independant. For example, a team of developers may provide:

* a Visual Basic application on Windows
* a Gambas application on Linux
* a PHP application on a web server

Without stored procedures and stored functions then the functionality would have to be developed independently for each application, but with stored procedures and stored functions the functionality only has to be developed once.

1. Creating MySQL Stored Procedures


A stored procedure is the same as a subroutine in that it cannot directly return a result, however it can receive variables that can be modified by the procedure; these variables are defined as:

* in - the variable can only be used as an input to the procedure
* out - the variable can only be used as an output from the procedure
* inout - this is both an input to, and an output from, the procedure

Procedures are always declared in the same way:

* define the procedure name
* define the procedure inputs and outputs
* define the the body of the procedure (enclosed within a BEGIN ... END statement)

One other (rather imporant) thing to bear in mind is that semicolons are used as part of the definition of the procedure. For this reason the end of line delimiter must be redefined to something that won't be used in the definition. For example:

delimiter //
create procedure circle_area (in r double, out a double)
begin
set a = r * r * pi();
end
//
delimiter ;

Running MySQL Stored Procedures

A MySQL stored procedure is run by using the call method:

call circle_area(22, @a);
select @a;


In this example 1520.5308443375 would be displayed on the screen.

2. Creating MySQL Stored Functions


Unlike stored procedures stored functions always return a result, they will also be one of two types:

* not deterministic - may produce different results for the same inputs (for instance random numbers or dates)
* deterministic - will always produce the same result for any given inputs

Like procedures, all functions are created the same way:

* define the function name
* declare any inputs
* define the data type to be returned by the function
* state whether or not the function is deterministic
* define the body of the function (again within a BEGIN ... END statement)

For example:

delimiter //
create function circumference (r double) returns double
deterministic
begin
declare c double;
set c = 2 * r * pi();
return c;
end
//
delimiter ;



Running MySQL Stored Functions

Unlike stored procedures stored functions are used as part of a select statement:

select circumference(22);

In this case (for anyone that's interested) the result would be 138.23007675795.
Conclusion

Stored procedures and stored functions are important tools for any database developer, and thankfully, those tools are now available to MySQL users - provided, of course, that they're using MySQL 5.

Read more: "MySQL Stored Procedures and Functions: How to Create Stored Procedures and Functions in a MySQL Database" -
http://database-programming.suite101.com/article.cfm/mysql_stored_procedures_and_functions#ixzz0DVzBNS5i&A