Friday, October 15, 2021

हिंदी भजन (Hindi Bhajan)

 

नारायण स्तुति 

भजमन नारायण नारायण हरी हरी ।

लक्ष्मीनारायण नारायण हरी हरी ।

सत्यनारायण नारायण हरी हरी ।

भगवन नारायण नारायण हरी हरी ।

जय जय नारायण नारायण हरी हरी ।

बोलो नारायण नारायण हरी हरी ॥






Sunday, April 9, 2017

VIM Settings which I like

:set nocompatible
:set bs=2
:set expandtab
:set tabstop=4
:set shiftwidth=4
:set showmatch
:set mouse=a
:set virtualedit=all
:set nu
syntax enable
set hlsearch
set incsearch
set ignorecase
set smartcase


set t_Co=128
highlight DiffAdd cterm=NONE ctermfg=Black ctermbg=Green gui=NONE guifg=Black guibg=Green
highlight DiffDelete cterm=NONE ctermfg=Black ctermbg=Red gui=NONE guifg=Black guibg=Red
highlight DiffChange cterm=NONE ctermfg=Black ctermbg=Yellow gui=NONE guifg=Black guibg=Yellow
highlight DiffText cterm=NONE ctermfg=Black ctermbg=Magenta gui=NONE guifg=Black guibg=Magenta

Thursday, February 4, 2016

My BASH and EXPECT Script for APIC-EM


~/.bashrc
==========

show_code()
{
    cd /ws/code/$view/apic-em-core/services
    find apic-em-pki-broker -name "*.java" > cscope.files
    find apic-em-pki-broker -name "*.py" >> cscope.files
    find apic-em-pki-broker -name start >> cscope.files
    find apic-em-pki-broker -name status >> cscope.files
    find apic-em-pki-broker -name "*.sh" >> cscope.files
    find apic-em-pki-broker -name "*.xml" >> cscope.files
    find apic-em-pki-ca -name "*.java" >> cscope.files
    find apic-em-pki-ca -name "*.py" >> cscope.files
    find apic-em-pki-ca -name start >> cscope.files
    find apic-em-pki-ca -name status >> cscope.files
    find apic-em-pki-ca -name "*.sh" >> cscope.files
    find apic-em-pki-ca -name "*.xml" >> cscope.files
    cscope -b
    cscope -d
}

set_view()
{
    view=$1
    if [ -d /ws/code/$view ]
    then
        cd /ws/code/$view/apic-em-core
    else
        read -p "Do you want to pull code? (y/n)" input
        if [ "$input" == "y" ]
        then
            su - tapmahes -c "~/.main.sh $view"
            cd /ws/code/$view
            sudo chown -R enc .
        else
            ls /ws/code
        fi
    fi
}

search_code()
{
    pattern=$1
    str=$2
    find . -name "$pattern" -print | xargs grep $str
}          

code_diff()
{
    if [ $view ]
    then
        cd /ws/code/$view/apic-em-core
        git show --name-only | grep services > /tmp/diff_list
        git diff --name-only >> /tmp/diff_list
        readarray -t array < /tmp/diff_list
        while true
        do
            var=0
            for e in "${array[@]}"
            do
                echo $var : $e
                ((var++))
            done
            read -p "Enter the number:" num
            git show HEAD^1:${array[$num]} > /tmp/original
            vimdiff /tmp/original ${array[$num]}
        done
    else
        echo Error# View is not set, please set the view using 'code <view_name>'
    fi  
}

alias code=set_view
alias bro='cd /ws/code/$view/apic-em-core/services/apic-em-pki-broker'
alias ca='cd /ws/code/$view/apic-em-core/services/apic-em-pki-ca'
alias cpg='~/enc.exp cpg $view'
alias cpgb='~/enc.exp cpgb $view'
alias cpgc='~/enc.exp cpgc $view'
alias cs=show_code
alias search=search_code
alias cdiff=code_diff


====================================================

$ cat /home/enc/enc.exp
#!/usr/bin/expect
set timeout 1000

proc setup_grapevine {} {
    spawn ssh grapevine@10.78.106.45
    expect {
        "password:" { send "Grapevine1\r" }
        timeout {
            send "Error"
            exit
        }
    }
    sleep 1
    send "mkdir /home/grapevine/tapesh\r"
    send "mkdir /home/grapevine/tapesh/broker\r"
    send "mkdir /home/grapevine/tapesh/ca\r"
    interact
}

proc copy_to_grapevine_broker {obj1} {
    spawn scp /ws/code/$obj1/apic-em-core/services/apic-em-pki-broker/pki-broker-service/target/apic-em-pki-broker-service-enc-private-build.tar.gz grapevine@10.78.106.45:/home/grapevine/tapesh/broker/
    expect {
        "password:" { send "Grapevine1\r" }
        timeout {
            send "Error"
            exit
        }
    }
    interact
    spawn scp /ws/code/$obj1/apic-em-core/services/apic-em-pki-broker/pki-broker-service/src/main/config/service-config.json grapevine@10.78.106.45:/home/grapevine/tapesh/broker/
    expect {
        "password:" { send "Grapevine1\r" }
        timeout {
            send "Error"
            exit
        }
    }
    interact
}

proc copy_to_grapevine_ca {obj1} {
    spawn scp /ws/code/$obj1/apic-em-core/services/apic-em-pki-ca/target/apic-em-jboss-ejbca*.tar.gz grapevine@10.78.106.45:/home/grapevine/tapesh/ca/
    expect {
        "password:" { send "Grapevine1\r" }
        timeout {
            send "Error"
            exit
        }
    }
    interact
    spawn scp /ws/code/22jan/apic-em-core/services/apic-em-pki-ca/src/conf/service-config.json grapevine@10.78.106.45:/home/grapevine/tapesh/ca/
    expect {
        "password:" { send "Grapevine1\r" }
        timeout {
            send "Error"
            exit
        }
    }
    interact
}

if { [string compare [lindex $argv 0 0] "cpg"] == 0 } {
    setup_grapevine
}
if { [string compare [lindex $argv 0 0] "cpgb"] == 0 } {
    copy_to_grapevine_broker [lindex $argv 1]
}
if { [string compare [lindex $argv 0 0] "cpgc"] == 0 } {
    copy_to_grapevine_ca [lindex $argv 1]
}



Wednesday, August 19, 2015

How install EJBCA and JBOSS


Based on : https://forge.fusiondirectory.org/projects/fd-plugins/wiki/How_install_EJBCA_and_JBOSS

Based on http://www.ejbca.org/docs/installation.html#Ubuntu%20quick%20start
Tip : Install tmux or screen to use two terminals or more
  • Create new user
  • useradd -m ejbca
  • passwd ejbca
  • Install softwares
  • apt-get install openjdk-7-jdk ant ant-optional unzip ntp
  • Download and install jboss and ejbca
  • Configure ejbca (where is jboss and other if you need)
  • echo "appserver.home=/home/ejbca/jboss-as-7.1.1.Final" >> ejbca_ce_6_2_0/conf/ejbca.properties
  • Launch jboss
  • export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-<arch>/jre
  • jboss-as-7.1.1.Final/bin/standalone.sh
  • EJBCA install (answer to question)
  • cd ejbca_ce_6_2_0/
  • export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-<arch>/jre
  • ant deploy
  • (wait little that jboss reload)
  • ant install
  • Restart jboss
  • ctrl + c
  • jboss-as-7.1.1.Final/bin/standalone.sh
  • Import superadmin.p12 in your browser (/home/ejbca/ejbca_ce_6_2_0/p12/superadmin.p12)
  • Configure jboss for logging
  • Run ./bin/jboss-cli.sh
  • connect
  • /system-property=org.jboss.as.logging.per-deployment:add(value=false)
  • /subsystem=logging/logger=org.ejbca:add
  • /subsystem=logging/logger=org.ejbca:write-attribute(name=level, value=DEBUG)
  • /subsystem=logging/logger=org.cesecore:add
  • /subsystem=logging/logger=org.cesecore:write-attribute(name=level, value=DEBUG)
  • exit

Saturday, August 8, 2015

History of linux


Mid 1960 - multics (a time sharing operating system) was getting developed by AT&T Bell but it was too large/complex.... finally AT&T pulled out from project.

In 1969-70,  Ken Thompson and Dennis Ritchie (both of AT&T Bell Laboratories) wrote Unix Operating system (on a much less scaled version).

Later they rewrote it in C, make it portable.

Unix philosophy was to use a large number of software tools, small programs that can be strung together through a command-line interpreter using pipes, as opposed to using a single monolithic program that includes all of the same functionality.

Both Unix and the C programming language were developed by AT&T and distributed to government and academic institutions, which led to both being ported to a wider variety of machine families than any other operating system.

Under Unix, the operating system consists of many utilities along with the master control program, the kernel. The kernel provides services to start and stop programs, handles the file system and other common "low-level" tasks that most programs share, and schedules access to avoid conflicts when programs try to access the same resource or device simultaneously. To mediate such access, the kernel has special rights, reflected in the division between user space and kernel space.

During the late 1970s and early 1980s, the influence of Unix in academic circles led to large-scale adoption of Unix (BSD and System V) by commercial startups, including Sequent, HP-UX, Solaris, AIX, and Xenix. In the late 1980s, AT&T Unix System Laboratories and Sun Microsystems developed System V Release 4 (SVR4), which was subsequently adopted by many commercial Unix vendors.

1983, none of the computer operating systerm was free.

1984, Richard M. Stallman (founder of Free Software Foundation) started developing the GNU operating system (a unix-like operating system)

The GNU Project has developed a comprehensive set of free software tools (cp, rm, vi, gcc) for use with BSD Operating system

By 1991, the GNU mid-level portions of the operating system were almost complete, and the upper level could be supplied by the X Window System, but the lower level (kernel, device drivers, system-level utilities and daemons) was still mostly lacking

GNU developed it's free operating system called 'GNU Hurd' which was an ambitious design, unexpectedly difficult to implement and has only been marginally usable.

At another hand, Tanenbaum started MINIX for educational purpose, and was first released in 1987, with its complete source code made available to universities for study in courses and research, however still licencsed.

1991, Linus Torvalds, who was working for MINIX, almost copy the concept from MINIX (which was more a micro kernel) and made a monolithic kernal called Linux and use GNU free utilities to proivde a 'free operating system'.

As 'hurd' was still not triggering, GNU also adopted Linux as kernal around 1992. Basically Linux was the 'kernal part' and the operating system was 'GNU/Linux' Operating system.







Wednesday, August 5, 2015

How to add disk space into linux VM

In linux console, run 'ls /dev/sd*' and notice how many devices are there

shut the linux vm

Go to VM setting and add a new harddisk of specified size

boot the linux vm

again run 'ls /dev/sd*' and notice a new device (normally first device is called sda, another is sdb, another is sdc and so on )

Create partition using cmd 'sudo fdisk /dev/sdb' ... it will ask for partition... make a single big one.. it's name will be /dev/sdb1  /* n to create new partition, p for primary and w for write */

format the new partition using 'sudo mkfs -t ext3 /dev/sdb1'

Run 'sudo fdisk -l' to see if partition is done properly.

For mounting create a folder first like 'sudo mkdir /ws' (so i created a 'ws' folder under /)
now mount using 'sudo mount -t ext3 /dev/sdb1 /ws'

recheck using 'df -h'

Add this entry '/dev/sdb1 /software ext3 defaults 1 1' to etc/fstab file manually

reboot and see if you can still see your disk  :)

Saturday, June 6, 2015

Understanding RSA

RSA Algorithm



RSA Algorithm for Key-pair generation:

1) Choose 2 distinct prime numbers ‘p’ & ‘q’. Preferably large , random & of same bit size.
2) Compute  modulus  “n = p.q”.
3) Compute  F(n) = (p – 1) (q – 1) where is F(n) is Totient  function.
4) Choose an integer ‘e’ such that  1 < e < F(n) and e and F(n) are co-prime. ‘e’ is the Public key exponent.
5) Determine d multiply e = 1  mod F(n) ,the Private key exponent.

Public Key is modulus ‘n’ & exponent ‘e’ = (n, e).
Private Key is modulus ‘n’ & exponent ‘d’ = (n, d), the secret.

Encryption (Message ‘m’)

m power(e) (mod n) = c, the cipher text.

Decryption (Cipher text ‘c’)

c power(d) (mod n) = m, the original message.


Example:


RSA Algorithm for Key-pair generation:


1) Choose 2 distinct prime numbers ‘7’ & ‘13’. Preferably large , random & of same bit size.
2) Compute  modulus  “n = p . q = 91”.
3) Compute  F(n) = (p – 1) (q – 1) = 72 where is F(n) is Totient function.
4) Choose an integer ‘e’ such that  1 < e < F(n) and e and F(n) are co-prime. ‘e’ is the Public key exponent.
 e = {5,7, 11, 13, 17,...}. Let it be 5.
5) Determine  d multiply e = 1 mod(F(n))
5 multiple d = 1 mod (72)
5d = 1 (mod 72)  equals a set of candidates { …,29, 101, 173, …}. Chose d = 29.
Public Key is modulus ‘n=91’ & exponent ‘e=5’ = (91, 5).   [ Note: e.d = 1 mod (p-1 x q -1) ]
Private Key is modulus ‘n=91’ & exponent ‘d=29’ = (91, 29), the secret.
                        “Note: Factoring ‘n’ to find ‘p, ‘q’, & then ‘d’ is the hardest part(as of today)
                                     and strength of RSA (so far)”

Encryption (Message ‘10’)

10 power(5) (mod 91) = 82, the cipher text.

Decryption (Cipher text ‘82’)

82 power(29) (mod 91) = 10, the cipher text.

Tuesday, March 31, 2015

Installing django on fresh ubuntu


I have just installed a ubuntu (latest 64 bit avialable on ubuntu web site) over a freshly installed 'vmware palyer' (again downloaded latest from vmware website)... all comes in FREE as of now.

Installed Ubuntu ...
Now, next steps was to install django server, so I open the terminal and this is how I installed it...

I was following this link for it : https://www.howtoforge.com/tutorial/django-install-ubuntu-14.04/

===============

tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sqllite
No command 'sqllite' found, did you mean:
 Command 'sqlline' from package 'sqlline' (universe)
 Command 'sqlite' from package 'sqlite' (universe)
sqllite: command not found
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sudo apt-get install sqlite
[sudo] password for tapesh:
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  libsqlite0 sqlite3
Suggested packages:
  sqlite-doc sqlite3-doc
The following NEW packages will be installed:
  libsqlite0 sqlite sqlite3
0 upgraded, 3 newly installed, 0 to remove and 102 not upgraded.
Need to get 182 kB of archives.
After this operation, 754 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/universe libsqlite0 amd64 2.8.17-10ubuntu2 [139 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ trusty/universe sqlite amd64 2.8.17-10ubuntu2 [14.4 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ trusty/main sqlite3 amd64 3.8.2-1ubuntu2 [28.9 kB]
Fetched 182 kB in 2s (67.8 kB/s)
Selecting previously unselected package libsqlite0.
(Reading database ... 163905 files and directories currently installed.)
Preparing to unpack .../libsqlite0_2.8.17-10ubuntu2_amd64.deb ...
Unpacking libsqlite0 (2.8.17-10ubuntu2) ...
Selecting previously unselected package sqlite.
Preparing to unpack .../sqlite_2.8.17-10ubuntu2_amd64.deb ...
Unpacking sqlite (2.8.17-10ubuntu2) ...
Selecting previously unselected package sqlite3.
Preparing to unpack .../sqlite3_3.8.2-1ubuntu2_amd64.deb ...
Unpacking sqlite3 (3.8.2-1ubuntu2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libsqlite0 (2.8.17-10ubuntu2) ...
Setting up sqlite (2.8.17-10ubuntu2) ...
Setting up sqlite3 (3.8.2-1ubuntu2) ...
Processing triggers for libc-bin (2.19-0ubuntu6.5) ...
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sudo apt-get install python-setuptools
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following NEW packages will be installed:
  python-setuptools
0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.
Need to get 230 kB of archives.
After this operation, 830 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main python-setuptools all 3.3-1ubuntu1 [230 kB]
Fetched 230 kB in 2s (79.3 kB/s)                      
Selecting previously unselected package python-setuptools.
(Reading database ... 163922 files and directories currently installed.)
Preparing to unpack .../python-setuptools_3.3-1ubuntu1_all.deb ...
Unpacking python-setuptools (3.3-1ubuntu1) ...
Setting up python-setuptools (3.3-1ubuntu1) ...
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sqllite --version
No command 'sqllite' found, did you mean:
 Command 'sqlite' from package 'sqlite' (universe)
 Command 'sqlline' from package 'sqlline' (universe)
sqllite: command not found
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sqllite -version
No command 'sqllite' found, did you mean:
 Command 'sqlline' from package 'sqlline' (universe)
 Command 'sqlite' from package 'sqlite' (universe)
sqllite: command not found
tapesh@ubuntu:~$ sqlite --version
sqlite: unknown option: --version
Use -help for a list of options.
tapesh@ubuntu:~$ sqlite -version
2.8.17
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ pip --version
The program 'pip' is currently not installed. You can install it by typing:
sudo apt-get install python-pip
tapesh@ubuntu:~$ pip
The program 'pip' is currently not installed. You can install it by typing:
sudo apt-get install python-pip
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ ls
Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
tapesh@ubuntu:~$ cd Downloads/
tapesh@ubuntu:~/Downloads$ ls
tapesh@ubuntu:~/Downloads$ wget https://bootstrap.pypa.io/get-pip.py
--2015-03-31 06:21:10--  https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 103.245.222.175
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|103.245.222.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1608741 (1.5M) [text/x-python]
Saving to: ‘get-pip.py’

100%[=================================================================================>] 1,608,741    325KB/s   in 5.3s  

2015-03-31 06:21:21 (296 KB/s) - ‘get-pip.py’ saved [1608741/1608741]

tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$ ls
get-pip.py
tapesh@ubuntu:~/Downloads$ python get-pip.py
Collecting pip
  Downloading pip-6.0.8-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 83kB/s
Installing collected packages: pip

  Exception:
  Traceback (most recent call last):
    File "/tmp/tmpfgWRwc/pip.zip/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
    File "/tmp/tmpfgWRwc/pip.zip/pip/commands/install.py", line 347, in run
      root=options.root_path,
    File "/tmp/tmpfgWRwc/pip.zip/pip/req/req_set.py", line 549, in install
      **kwargs
    File "/tmp/tmpfgWRwc/pip.zip/pip/req/req_install.py", line 754, in install
      self.move_wheel_files(self.source_dir, root=root)
    File "/tmp/tmpfgWRwc/pip.zip/pip/req/req_install.py", line 963, in move_wheel_files
      isolated=self.isolated,
    File "/tmp/tmpfgWRwc/pip.zip/pip/wheel.py", line 234, in move_wheel_files
      clobber(source, lib_dir, True)
    File "/tmp/tmpfgWRwc/pip.zip/pip/wheel.py", line 205, in clobber
      os.makedirs(destdir)
    File "/usr/lib/python2.7/os.py", line 157, in makedirs
      mkdir(name, mode)
  OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip-6.0.8.dist-info'

tapesh@ubuntu:~/Downloads$ sudo python get-pip.py
The directory '/home/tapesh/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
The directory '/home/tapesh/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
The directory '/home/tapesh/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
Collecting pip
  Downloading pip-6.0.8-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 97kB/s
Installing collected packages: pip

Successfully installed pip-6.0.8
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$
tapesh@ubuntu:~/Downloads$ cd
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ pip --version
pip 6.0.8 from /usr/local/lib/python2.7/dist-packages (python 2.7)
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sudo easy_install virtualenv
Searching for virtualenv
Reading https://pypi.python.org/simple/virtualenv/
Download error on https://pypi.python.org/simple/virtualenv/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'virtualenv' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for virtualenv
error: Could not find suitable distribution for Requirement.parse('virtualenv')
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ sudo easy_install virtualenv
Searching for virtualenv
Reading https://pypi.python.org/simple/virtualenv/
Best match: virtualenv 12.0.7
Downloading https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz#md5=e08796f79d112f3bfa6653cc10840114
Processing virtualenv-12.0.7.tar.gz
Writing /tmp/easy_install-GXDQBd/virtualenv-12.0.7/setup.cfg
Running virtualenv-12.0.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-GXDQBd/virtualenv-12.0.7/egg-dist-tmp-TJOjti
warning: no previously-included files matching '*' found under directory 'docs/_templates'
warning: no previously-included files matching '*' found under directory 'docs/_build'
Adding virtualenv 12.0.7 to easy-install.pth file
Installing virtualenv script to /usr/local/bin
Installing virtualenv-2.7 script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/virtualenv-12.0.7-py2.7.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ virtualenv --no-site-packages django-user
New python executable in django-user/bin/python
Installing setuptools, pip...done.
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ ls
Desktop  django-user  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
tapesh@ubuntu:~$ cd django-user/
tapesh@ubuntu:~/django-user$ ls
bin  include  lib  local
tapesh@ubuntu:~/django-user$ cd..




cd..: command not found
tapesh@ubuntu:~/django-user$
tapesh@ubuntu:~/django-user$
tapesh@ubuntu:~/django-user$
tapesh@ubuntu:~/django-user$
tapesh@ubuntu:~/django-user$ cd ..
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$
tapesh@ubuntu:~$ source django-user/bin/activate
(django-user)tapesh@ubuntu:~$
(django-user)tapesh@ubuntu:~$
(django-user)tapesh@ubuntu:~$
(django-user)tapesh@ubuntu:~$
(django-user)tapesh@ubuntu:~$ ls
Desktop  django-user  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
(django-user)tapesh@ubuntu:~$ cd django-user/
(django-user)tapesh@ubuntu:~/django-user$ ls
bin  include  lib  local
(django-user)tapesh@ubuntu:~/django-user$ \
>
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$ easy_install django
Searching for django
Reading https://pypi.python.org/simple/django/
Best match: Django 1.7.7
Downloading https://pypi.python.org/packages/source/D/Django/Django-1.7.7.tar.gz#md5=a62d6598966947d150525ad2ab20fb0c
Processing Django-1.7.7.tar.gz
Writing /tmp/easy_install-L1hzoy/Django-1.7.7/setup.cfg
Running Django-1.7.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-L1hzoy/Django-1.7.7/egg-dist-tmp-CNW019
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
creating /home/tapesh/django-user/lib/python2.7/site-packages/Django-1.7.7-py2.7.egg
Extracting Django-1.7.7-py2.7.egg to /home/tapesh/django-user/lib/python2.7/site-packages
Adding Django 1.7.7 to easy-install.pth file
Installing django-admin.py script to /home/tapesh/django-user/bin
Installing django-admin script to /home/tapesh/django-user/bin

Installed /home/tapesh/django-user/lib/python2.7/site-packages/Django-1.7.7-py2.7.egg
Processing dependencies for django
Finished processing dependencies for django
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$
(django-user)tapesh@ubuntu:~/django-user$ ls
bin  include  lib  local
(django-user)tapesh@ubuntu:~/django-user$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.7.7'
>>>
(django-user)tapesh@ubuntu:~/django-user$


CISCO tips and tricks


/*************************************************
CISCO : copy to linux server TCL script
***************************************************/

[bgl-ads-146]@~$cat /nobackup/tapmahes/script/cpl.tcl
#!/bin/env expect

set timeout 60
spawn scp i86bi_linux-adventerprisek9-ms root@10.78.106.52:/root/tapesh/IOU/
expect "password:"
send "cryptolab\r"
expect "100%"
sleep 1

[bgl-ads-146]@~$



/***********************************
CISOC .bashrc alias list
************************************/

[bgl-ads-146]@~$cat ~/.bashrc | grep alias
alias cpl=/nobackup/tapmahes/script/cpl.tcl
alias emacs='/router/bin/emacs-22.3 &'
alias sun='ssh blr-stgios-view1'
alias junk='cd /nobackup/tapmahes/junk'
alias people='cd /nfs/wwwPeople/tapmahes'
alias ssh88='ssh mcp-bld-lnx-88'
alias ssh85='ssh mcp-bld-lnx-85'
alias ssh86='ssh mcp-bld-lnx-86'
alias ssh1='ssh blr-stgios-view1'
alias sshl='ssh root@10.78.106.52'
alias ssht='ssh -t tapmahes-vlnx ". .bashrc; bash -l"'
alias cs='cd /vob/cisco.comp/crypto && cscope-64 -R'
alias cs1='find . -name "*.[ch]" > cscope.files && cscope -d'
alias ver='cat /vob/ios/.publication_manifest | grep crypto'
alias crashinfo='mcp_gdb -p linkfarm/x86_64/usr/binos/bin/x86_64bi_linux_iosd-adventerprisek9-ms.sun'
alias corefile='mcp_gdb_core -p linkfarm/x86_64/usr/binos/bin/x86_64bi_linux_iosd-adventerprisek9-ms.sun -c '
alias tc='tcsh' #if ($?prompt) source ~/.cshrc.keychain
alias gdb64='/router/bin/gdb-bleeding-64'
alias uco='cc_unco -force_unco'
alias cco='cc_co -nc -f'
alias unix_image='unix-jo3s-ms'
alias mosy='/router/bin/mosy-14.2.0.0 -s'
alias buidmib='make dir/*.code '
alias osup='cd /vob/ios.sys6/sys/obj-7k-sup3-rp-earl7'
alias rpk9='make s72033_rp-adventerprisek9-m.ucode'
alias prep='prep-commit tapmahes@cisco.com'
alias ptall='make -k PRECOMMIT_CRYPTO=1 precommit.testall > & make.out &'
alias snaps='cd /auto/ios-snaps'
alias ht='cd  /auto/ios-snaps/haw_t.snap/ios/sys'
#alias ps='/usr/bin/ps'
alias sa='/auto/ses/bin/static_iosbranch'
alias myp='ps -ef | grep tapmahes'
alias mymake='ps -ef | grep tapmahes | grep make'
#alias gcc='/auto/router/bin/gcc.c2.95.3-p11a.solaris'
alias unix='cd /vob/ios/sys/obj-sp-unix'
alias linux='cd /vob/ios/sys/obj-x86_64bi-linux'
alias crypto='cd /vob/cisco.comp/crypto'
alias ikev2='cd /vob/cisco.comp/crypto/ikev2/src/ikev2'
alias objs='cd /vob/cisco.comp/crypto/objects/ios.sparc.v7/'
alias 2800='cd /vob/ios/sys/obj-7k-c2800'
alias update='cc_update -m LATEST'
alias gvim='gvim -bg lightblue -fg black'
alias gw='gvim -bg white -fg black'
alias gp='gvim -bg peachpuff -fg black'
alias gb='gvim -bg brown -fg white'
alias er='stty erase ^H'
alias eq='stty erase ^?'
alias ct='cleartool'
alias pwv='ct pwv'
alias rcscope='/router/bin/cscope'
alias myviews='ls /ws/tapmahes-bgl'
#alias flex "/auto/ses/bin/tools/iosclassic_fl"
alias sys='cd /vob/ios/sys'
#alias cscope='/sw/packages/cscope/12.9/solaris2bin/cscope.kani'
alias cscope='cscope-15.5-p7'
alias tb3='cd /auto/ios-snaps/t_base_3.snap/ios && cscope -d && cd -'
alias tb4='cd /auto/ios-snaps/t_base_4.snap/ios && cscope-64 -d && cd -'
alias googlem='cd /auto/ios-snaps/mcp_dev.snap/ios && cscope-64 -d && cd -'
alias xe37='cd /auto/ios-snaps/v152_4_s_xe37_throttle.snap/ios && cscope -d && cd -'
alias xe38='cd /auto/ios-snaps/v153_1_s_xe38_throttle.snap/ios && cscope -d && cd -'
alias xe39='cd /auto/ios-snaps/v153_2_s_xe39_throttle.snap/ios && cscope -d && cd -'
alias xe314='cd /auto/ios-snaps/v155_1_s_xe314_throttle.snap/ios && cscope-64 -d && cd -'
alias xe313='cd /auto/ios-snaps/v154_3_s_xe313_throttle.snap/ios && cscope-64 -d && cd -'
#alias tftp='cd /auto/tftp-blr-users1/tapmahes'
alias rss='cd /auto/ios-snaps/t_pi12_rss.snap/ios'
#alias s1='ssh blr-stgios-view1'
#alias s2='ssh blr-stgios-view2'
#alias mdi='make -j16 dependencies && cd obj-sp-unix && make -j16 unix-adventerprisek9-ms 2>&1 | tee c.txt'
#alias mdl='make -j16 dependencies && cd obj-x86_64bi-linux && make -j16 TOOLS_VER=c3.4.5-p1 x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt'
alias mdl='cd /vob/ios/sys && make -j32 dependencies && cd /vob/ios/sys/obj-i86bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt'
alias mdu='cd /vob/ios/sys && make -j32 dependencies && cd /vob/ios/sys/obj-sp-unix && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias md='cd /vob/ios/sys && make -j32 dependencies'
alias ml='cd /vob/ios/sys/obj-i86bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms'
alias ml64='cd /vob/ios/sys/obj-x86_64bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt'
alias mi='make -j8 unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias mil='make -j8 LEGOFILTER=shr_crypto_ipsec_common.o unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias miln='make -j8 LEGOFILTER=shr_crypto_ikev2.o unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias c7200p='cd /vob/ios/sys && make -j16 dependencies && cd obj-g4-c7100 && make -j16 c7200p-adventerprisek9-mz 2>&1 | tee c.txt'
alias c3900='cd /vob/ios/sys && cd obj-m8500-c3900 && make -j16 c3900-universalk9-mz 2>&1 | tee c.txt'
alias c3900e='cd /vob/ios/sys && cd obj-i86bi-ifr && make -j16 c3900e-universalk9-mz 2>&1 | tee c.txt'
alias c880data='cd /vob/ios/sys && cd obj-m8300-c880 && make -j16 c880data-universalk9-mz 2>&1 | tee c.txt'
alias c2951='cd /vob/ios/sys && cd obj-m8500-c2951 && make -j16 c2951-universalk9-mz 2>&1 | tee c.txt'
alias c2900='cd /vob/ios/sys && cd obj-cn-c2900 && make -j16 c2900-universalk9-mz 2>&1 | tee c.txt'
alias c1900='cd /vob/ios/sys && cd obj-cn-c1900 && make -j16 c1900-universalk9-mz 2>&1 | tee c.txt'
alias c3750e='cd /vob/ios/sys/obj-ppc-c3750e && make -j32 c3750e-universalk9-mz 2>&1 | tee c.txt'
alias c3845='cd /vob/ios/sys && make -j8 dependencies && cd obj-sb-c3845 && make -j8 c3845-adventerprisek9-mz 2>&1 | tee c.txt'
alias c1841='cd /vob/ios/sys && make -j8 dependencies && cd obj-5k-c1840 && make -j8 c1841-adventerprisek9-mz  2>&1 | tee c.txt'
alias c2800nm='cd /vob/ios/sys && make -j8 dependencies && cd obj-7k-c2800 && make -j8 c2800nm-adventerprisek9-mz 2>&1 | tee c.txt'
alias c7200pl='cd /vob/ios/sys/obj-g4-c7100 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c7200p-adventerprisek9-mz 2>&1 | tee c.txt'
alias c3845l='cd /vob/ios/sys/obj-sb-c3845 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c3845-adventerprisek9-mz 2>&1 | tee c.txt'
alias c1841l='cd /vob/ios/sys/obj-5k-c1840 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c1841-adventerprisek9-mz  2>&1 | tee c.txt'
alias c2800nml='cd /vob/ios/sys/obj-7k-c2800 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c2800nm-adventerprisek9-mz 2>&1 | tee c.txt'
alias ll='ls -al'
alias     ctl='ct lsview | grep tapmahes'
alias     ctlo='ct lsview | grep $1'
alias     ctv='ct setview'
alias rs='/usr/bin/runsparc.real'
alias tc='tcsh'
alias vi='vim'
#alias ls='ls --color=always'



/***************************************
CISCO short cut command file
****************************************/

Command to bind F12 to a bash file:
bind '"\e[24~":"source ~/.keyshort\n"'

[bgl-ads-146]@~$ cat .keyshort
assert()
{
if [ "$ans" == "" ]
then
exit
fi
}

ShowVariousDirectories()
{
echo "1) /vob/ios/sys"
echo "2) /vob/ios/sys/obj-x86_64bi-linux"
echo "3) /vob/ios/sys/obj-i86bi-linux"
echo "4) /vob/ios/sys/obj-sp-unix"
read -s -n 1 ans
echo --------------
case $ans in
1) cd /vob/ios/sys;;
2) cd /vob/ios/sys/obj-x86_64bi-linux ;;
3) cd /vob/ios/sys/obj-i86bi-linux ;;
4) cd /vob/ios/sys/obj-sp-unix ;;
esac
}

SetView()
{
select ans in `ls /view`;
do
assert
echo -ne "\033]0;${ans:9}\007"
cleartool setview $ans
echo -ne "\033]0;Terminal\007"
break
done
}

CreateView()
{
        echo "Please enter the branch: (if you want to pull view from label, press enter)"
        read branch
        if [ "$branch" == "" ]
        then
                echo "Please enter the label:"
                read label
                echo "Please enter a tag (anything which you can remember):"
                read tag
                start_task -l $label -v /vob/ios -t $tag -d /ws/tapmahes-bgl
        else
                echo "Please enter a tag (anything which you can remember):"
                read tag
                start_task -b $branch -v /vob/ios -t $tag -d /ws/tapmahes-bgl
        fi
}

BINOS()
{
        echo "Please select build type:"
        echo "1) 1RU            2) RP2                  3) RP3"
        read -n 1 type
        case $type in
        1) type=1ru;;
        2) type=rp2;;
        3) type=rp3;;
        esac
        echo "Please enter the label:"
        read label
        echo "Please enter BINOS dir name (anything which you can remember):"
        read binosdir
        mkdir /nobackup/tapmahes/$binosdir
        cd /nobackup/tapmahes/$binosdir
#       acme nw -sb binos -proj main%$label
        echo On Success, set the matching view in IOS and please run the following command from /vob/ios/sys: mcp_ios_precommit -r /nobackup/tapmahes/$binosdir/ "GDB_FLAG=-g" "$type""_super"
}

ShowDiff()
{
        tempifs=$IFS
        IFS=$'\n'
        array=(`ct lsco -avobs -cview | awk '{print $5"@@"$7, $5}' | sed s/\"//g`)
        IFS=$tempifs
        i=0
        while [ $i -lt ${#array[*]} ];
        do
        echo "$i: ${array[$i]}" | cut -d " " -f 1,3
        let i++
        done
        while [ true ];
        do
        echo "Choose file num (Press Enter to Exit):"
        read ans
        if [ "$ans" == "" ]
        then
        break
        fi
        vimdiff  ${array[$ans]}
        done
}

ShowLablesList()
{
        echo "Branch : (default : t_base_2)"
        read branch
        if [ "$branch" == "" ]
        then
                branch=t_base_2
        fi
        echo "Search String (Just Enter for None) : "
        read searchstr
        if [ "$searchstr" == "" ]
        then
                cc_branch_labels -b $branch -v /vob/ios | more
        else
                cc_branch_labels -b $branch -v /vob/ios | grep $searchstr | more
        fi
}

ShowCleartoolOptions()
{
echo "1) Show View"
echo "2) Set View"
echo "3) Create View"
echo "4) Create BINOS Tree"
echo "5) Show Diff"
echo "6) Show Lables list"
echo "7) Show current Lable"
read -s -n 1 ans
echo --------------
case $ans in
1) cleartool lsview | grep tapmahes
echo --------------
cleartool pwv;;
2) SetView;;
3) CreateView;;
4) BINOS;;
5) ShowDiff;;
6) ShowLablesList;;
7) ct edcs;;
esac
}

LaunchRouter()
{
echo "1) IOU"
echo "2) IOU with GDB"
echo "3) IOL"
echo "4) IOL with GDB"
echo "5) IOL 32 bit"
echo "6) IOL 32 bit with GDB"
read -s -n 1 ans
echo --------------
case $ans in
1)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-sp-unix
        runsparc ./unix-adventerprisek9-ms -m1000 -n1000 $nvramid ;;
2)  cd /vob/ios/sys/obj-sp-unix
        runsparc /router/bin/gdb unix-adventerprisek9-ms.sun ;;
3)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-x86_64bi-linux
        ./x86_64bi_linux-jk9o3s-ms -m1000 -n1000 $nvramid ;;
4)  cd /vob/ios/sys/obj-x86_64bi-linux
    gdb-bleeding-64 x86_64bi_linux-jk9o3s-ms.sun;;
5)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-i86bi-linux
        ./i86bi_linux-adventerprisek9-ms -m1000 -n1000 $nvramid ;;
6)  cd /vob/ios/sys/obj-i86bi-linux
    gdb-bleeding i86bi_linux-adventerprisek9-ms.sun;;
esac
}

Compile_IOU_Minimal()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-sp-unix
export GDB_FLAG=-g
case $ans in
1)  make -j32 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  unix-adventerprisek9-ms 2>&1 | tee c.txt;;
2) make -j32 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  unix-adventerprisek9-ms 2>&1 | tee c.txt;;
esac
}

Compile_IOL_X64_Minimul()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-x86_64bi-linux
export GDB_FLAG=-g
case $ans in
1)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
2)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
esac
}

Compile_IOL_x32_Minimal()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-i86bi-linux
export GDB_FLAG=-g
case $ans in
1)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
2)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
esac
}

CompileCode()
{
echo "1) Make Dependencies"
echo "2) IOU Minimal"
echo "3) IOU Full"
echo "4) IOU Fast"
echo "5) Router Build (Make sure to be in Correct OBJ dir)"
echo "6) IOL x64 Full"
echo "7) IOL x64 Minimal"
echo "8) IOL x32 Full"
echo "9) IOL x32 Minimal"
read -s -n 1 ans
echo --------------
case $ans in
1)      cd /vob/ios/sys
        make -j32 dependencies;;
2)      Compile_IOU_Minimal;;
3)  cd /vob/ios/sys/obj-sp-unix
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g unix-adventerprisek9-ms 2>&1 | tee c.txt;;
4)  cd /vob/ios/sys/obj-sp-unix
        export GDB_FLAG=-g
        emake-aurora --env=ios unix-adventerprisek9-ms;;
5)      export GDB_FLAG=-g
        echo "Write the target name (Make sure you are in correct OBJ Dir) :"
        read target_router
        make -j32 GDB_FLAG=-g $target_router;;
6)      cd /vob/ios/sys/obj-x86_64bi-linux
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
7)  Compile_IOL_X64_Minimul;;
8)      cd /vob/ios/sys/obj-i86bi-linux
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
9) Compile_IOL_x32_Minimal;;
esac
}

ShowMainMenu()
{
echo "1) Cleartools command"
echo "2) Moving into Directories"
echo "3) Launch Routers"
echo "4) Compile code"
read -s -n 1 ans
echo --------------
case $ans in
1) ShowCleartoolOptions;;
2) ShowVariousDirectories;;
3) LaunchRouter;;
4) CompileCode;;
esac
}


ShowMainMenu;


#select ans in "Cleartool commands" "Moving into Directories";
#do
#assert
#echo $ans
#case $ans in
#"Cleartool commands") ShowCleartoolOptions;;
#"Moving into Directories") echo second menu;;
#esac
#done



Monday, October 6, 2014

Custom HTTP Server and adding 'custom http header attribute' while POST request

Well, python is used here to create a custom HTTP server which will behave like normal HTTP server for GET request but for POST request, it will send the received POST request header information back in response. Why done?  Just for fun but it can be used to do a lot more.

Python script:

import SimpleHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse
import logging

class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    
    def do_GET(self):
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
        return

    def do_POST(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(self.headers)
        return

if __name__ == '__main__':
    from BaseHTTPServer import HTTPServer
    server = HTTPServer(('', 8000), GetHandler)
    print 'Starting server, use <Ctrl-C> to stop'
    server.serve_forever()

Say script name is 'basehttp.py', you can run it using 'python basehttp.py'.

Here is the HTML Page  which play-around with this script.

<html>
<head>
<style>
div {
  border: 5px solid green;
}
</style>
</head>

<body>
<h1>This page will add the below 'Label(s)' into HTTP request header</h1><br>
<table>
<tr><td>Label1</td><td><input type="text" id="api-code1"></input></td></tr>
<tr><td>Label2</td><td><input type="text" id="api-code2"></input></td></tr>
<tr><td>Label3</td><td><input type="text" id="api-code3"></input></td></tr>
<tr><td></td><td><input type="submit" value="Submit" onClick='dojob()'></input></td></tr>
</table>
<br>
<div id="response"></div>
</body>

<script>
function dojob()
{
    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("response").innerHTML = "<h2> Header received on server was:</h2>";
        document.getElementById("response").innerHTML += "<pre>" + xmlhttp.response + "</pre>";
      }
    }

    xmlhttp.open("POST","test.html?t=" + Math.random(), false);
    xmlhttp.setRequestHeader("api-code1", document.getElementById("api-code1").value);
    xmlhttp.setRequestHeader("api-code2", document.getElementById("api-code2").value);
    xmlhttp.setRequestHeader("api-code3", document.getElementById("api-code3").value);
    xmlhttp.send();
}
</script>


Guess what is test.html here ? nothing, we just not using it in our POST request. Math.random() is used to invalidate the browser cache.

Thursday, September 18, 2014

The Linux Programming Interface - Kick Start

Well, for my Linux OS better understanding, I decided to learn it more using below book



It has around 63 chapters and 1556 pages. I target to read around 30 pages per day. Let's see how it goes ...

Target Start Date: 18th Sep
Target End Date:  18th Nov  ... Happy Reading :)

Wednesday, August 27, 2014

Three.js, first animation

So, i tried my hand on three.js to have a small animation... basically a CUBE having shadow, and camera is moving in a circular fashion around the cube.
Very basic but first one.

important points,
1) lights are very important, without that it will be black.
2) high light number produce more bright light

Code is here,
https://github.com/tapeshmaheshwari/JavaScript/blob/master/initial_experiment/first_example.html

Sunday, August 24, 2014

window.onload and addEventListener usage

main.html:
<script src="main.js"></script>
<input type="button" id="test" value="click here"></input>
<div id="display"></div>

main.js:
var button = {
counter : 0,
click : function() {
button.counter++;
document.getElementById("display").innerHTML = button.counter;
}
};

window.onload = function()
{
var b = document.getElementById("test");
b.addEventListener("click", button.click, false);
}


Important notes:

Without this onload function, putting 'addEventListener()' directly in global scope will give error, because we are attaching <script src="main.js"> before the <input type> for 'test'. So, JS will not get this element in DOM tree. hence, onload function will wait till document is not getting loaded fully and all elements are available in DOM tree.

Friday, August 22, 2014

Handmade UnitTest framework for JavaScript

Well, I was also needing a UT framework (a very simple one) and decide to write my own in JS.

At the same time, i realize that i need to have a public GIT repository to keep all my sample code, hence i have created this link,
https://github.com/tapeshmaheshwari/JavaScript.git


So, i wrote my first JS program which is a Unit Test Framework.
@ https://github.com/tapeshmaheshwari/JavaScript/tree/master/unittest


It looks like below and based on 'assert' function.


JavaScript Unit Test Framework



  • The first pass test case simulation
  • The first fail test case simulation
  • Add two numbers.
  • GitHub file/folder addition/deletion CLI

    Launch Git Bash program installed on your system.

    To connect to sum GIT repository
    git init
    git remote add origin https://github.com/tapeshmaheshwari/JavaScript.git

    To add a file/folder into repository
    git add test.html
    git commit
    git push

    To remove a file from repository
    git rm test.html
    git commit
    git push

    To checkout full repository
    git clone https://github.com/tapeshmaheshwari/JavaScript.git

    Thursday, August 21, 2014

    JavaScript ... first post

    I have decided to learn JavaScript a bit seriously. Why? because I think there is a lot of potential in this language. From mobile apps to gaming and animation to pretty dynamic UI, all can be done with JS.

    In short, JavaScript future is bright and if someone interested in web programming, it's the must language.

    Here are some good resources i found for Web programming:

    cofee console - fast way to write js code
    sublime editor - nice editor to write JS code

    Some code example,
    http://github.com/tkmagesh => "repositories" => Cisco-AdvJs-Aug-2014

    Some JS libraries:
    http://underscorejs.org/
    http://backbonejs.org/
    https://angularjs.org/

    Books:
    secretes of the java script ninja - reading this book now a days
    speaking java scripts
    A journey through java script mbc jungle 

    Unit test and tools:
    unit test: grant.js (complete echosstem for application workflow)
    bower - dependency managment
    unit test - jasmin , mokka , signon

    Extra:
    html5 websockets - a way for server to push data/event to client
    http://www.csszengarden.com -> cool example of same html and multiple css
    http://todomvc.com/  -> same program, multiple JS scirpt

    Sunday, August 17, 2014

    How to run a simple HTTP server using python

    python -m SimpleHTTPServer
    
    
    Just run this and root directly from wherever you are running this will become the core root directly and search for index.htm (or otherwise just do the file listing)

    Sunday, July 27, 2014

    My Suggestion to government (mygov.nic.in)

    Hi Sir,
    Thanks for initiating such a unique platform. My idea is for ‘accessing the digital services and technologies’ and how to make the change happen for good.

    Problem:
    1)      Physical/mental and economical harassment are always involved when dealing with most of the government departments/office.
    2)      There is huge corruption in almost all department and there is no ‘tracking/complaining’ system exists. Complaining in same department by approaching the next level senior is not a feasible solution as most of the times department has good terms among them (or they themselves may have share in corruption).
    3)      As of now, our government department process are not transparent. There are very few tracking system and ‘aam admi’ can’t raise much voice against the existing working style  and they don’t get proper information.
    4)      Aam admi has no idea of ‘clear rules and regulation’ and whatever is dictated by concerned department, becomes the rule. This system is prone to misusage and misguide the aam-admi.

    I see other views on this topic, but lets’ go step by step. First of all, we need to make the information available. Educating people or say providing terminal to every municipal is not a bad idea but needs lot of effort, investment and most importantly maintains to keep such things functional. In our country where even a ‘automatic railway platform ticket m/c’ is not maintained well (and I am talking about well-developed cities like Bangalore and Delhi), it’s difficult to see that such things can be maintained well at municipality level.

    So, what’s the first solution?
    1)      Provide the information at some centralized website/cloud/server. Advertise its purpose and potential usage on TV and with other media.
    2)      Educate the people on the same website on how to access the information.
    3)      Make sure accessing the information is very easy. Make sure logging issues in accessing information is also very easy.
    4)      Make it available via public internet. Let the people try to access the information on their own expense on either mobile/cyber café/office internet/home internet or from friends/neighbors.
    5)      As the ‘provided information’ is centralized, maintain it well (it means maintain the website function always UP and FAST). Let the people believe that ‘this system always works’. Faith is very important specially during initial stage of such programs.
    6)      Let the people upload what they see/feel on the same website even @ municipality/small government branch office level with proofs like ‘photos/videos’ (need more thought on proofs, I have few but they are more expensive. With the help of mobile now a days, it’s very easy to click PIC or generate video of incident).
    7)      Create a centralized monitoring team. Let them validate/verify the uploaded issues from public all over the place and generate a ‘automatic notice’ asking ‘give reasons’ to those government branch offices while keeping the complainer informed but hidden (if possible) from concerned department.
    a.       Hiding the identity (if possible) will make sure that people will not be afraid of complaining generic issues as they are anonymous to the department. There could be issues which were individual specific and for that it might be necessary to expose the identity of the person (which should be OK as the issues is specific to that identity).
    b.      Sending notice to department should made significant changes in the behavior of the staff as now they are ‘questionable for their act’. This is the biggest things missing in our system that government servants are not questionable by ‘aam admi’ if they are not doing their duty properly.
    c.       As it’s a ‘centralized team’ which is monitoring the complains, chances of biased ness is very less as the department and monitoring comity will not have any link.
    d.      The term ‘notice’ can be further discussed. In my opinion, government should prefer to raise a ‘bug’ for all such complaints (online), assign those bugs to ‘department in question’, and it’s department duty to keep a track of ‘issues logged’ against their department. Department should be able to provide the reasoning directly on logged bug (online and evident as well if possible). Complainer should be able to see them (so give ‘bug id’ to complainer as well), he should be able to do ‘cross arguments’ with concern department (with evident if needed). Let the ‘monitoring staff’ should be silently see their conversation till both provided all ‘pending information’ and ‘cross response’ to each other query (may be multiple rounds). The biggest advantage of such approach is that now ‘department and individual aam admi are discussing one-to-one, monitoring team is not busy in their case, and in-the-last based on their discussion and evident provided during discussion, they can easily reach to a conclusion of ‘which party is legally correct’ or if ‘further evidents are required’.
    e.      As it’s all happening online (no paper work or transfer of real document in 90% cases (if any party object the truthiness of uploaded Xerox proof, it might be important to show the real proof but in that case one party will lose immediately if found guilty)), both parties should be reply with-in a given time period, absence of that will considered as advantage of ‘up-to-date’ party. There might be some relaxation policies which can be further discussed.

    What all it takes to make it happen:
    1)      A online server provided by government (like mygov) where people can upload their issues and can generate the complaint number and discuss with concern department directly in the observation of ‘monitoring department’.
    2)      Individuals has to use internet on their personal expense (cyber café/personal gadgets) . But see, it’s very cheap by even travelling to concerned department. Mobiles are available everywhere, even in villages. Website should be light weight so that It can function in 2G network so that anyone can use it.
    3)      The main officer of all government branch department can be held responsible to keep a track of all the ‘bugs’ logged against his department. His duty could be to reach out the real officer (as they work in same office or phone), and provide the response. May be every department can take a normal internet connection (from private companies like airtel/vodaphone etc) with monthly 200/- (two hundred rupees plan, as of now it’s avilable), with a basic 2G/3G plan. Use a wifi modem, so that everyone on office can use their mobile to access the government website for bugs. Make the firewall rule on ‘router modem’ that people can access only ‘bug website’ to stop any misuse at all.

    I understand their might be many questions/challenges/difficulties in executing this plan, but I am open to discuss and provide further deep solutions if required. It’s just a basic idea and can be further refined.


    Regards,
    Tapesh Maheshwari.


    Tuesday, February 4, 2014

    How to redirect traffic from one IP to another IP


    /sbin/iptables -t nat -A PREROUTING -p icmp -d 10.106.210.176 -j DNAT --to-destination 10.20.1.2


    To view whatever is configured:

    /sbin/iptables -t nat -vnL --line-number  (with nat)
    /sbin/iptables -vnL --line-number           (without nat)



    To Delete/remove :
    /sbin/iptables -D FORWARD 1   (without nat and 'FORWARD' is the policy, replace accordingly from whatever is listed from above command output)

    another example to delete with nat:
    /sbin/iptables -t nat -D PREROUTING 1   (here 1, 2 ..3 are the line-numbers which will get listed from view command)

    .VIMRC file



    :set nocompatible
    :set bs=2
    :set expandtab
    :set tabstop=4
    :set shiftwidth=4
    :set showmatch
    :set mouse=a
    :set virtualedit=all
    :set nu
    syntax enable
    set hlsearch
    set incsearch
    set ignorecase
    set smartcase


    set t_Co=128
    highlight DiffAdd cterm=NONE ctermfg=Black ctermbg=Green gui=NONE guifg=Black guibg=Green
    highlight DiffDelete cterm=NONE ctermfg=Black ctermbg=Red gui=NONE guifg=Black guibg=Red
    highlight DiffChange cterm=NONE ctermfg=Black ctermbg=Yellow gui=NONE guifg=Black guibg=Yellow
    highlight DiffText cterm=NONE ctermfg=Black ctermbg=Magenta gui=NONE guifg=Black guibg=Magenta