Thursday, December 5, 2013

Didn't Get The Job? Do This...

Thank you for letting me know you made a decision. I'm really happy you have found the right candidate for the job. The interviewing process with you was very inspiring and I meant what I said about wanting to work for your company. So, I was wondering if you could advise me on what I can do to be proactive and stay on your radar screen for any future opportunities?"


http://www.linkedin.com/today/post/article/20131205132758-7668018-when-you-don-t-get-the-job-do-this?trk=object-title

Tuesday, November 26, 2013

books to read

david and goliath
Miracle of Mindfulness by Thich Nhat Hanh

Saturday, October 19, 2013

clocking Intel i7 720QM ( poor performance fixed )

Recently i was facing problems with performance of my Lenovo W510 laptop. I was able to fix it and here is what i discovered.

1) I was using a low power adapter rather than the higher powered one which came along with the laptop. This have effect on the performance so use a higher power power adapter.
2) In the power options on my Windows Seven OS i changed my power profile to one of Maximum performance.
3) Finally use a utility like ThrottleStop to boost the CPU .



Make sure to uncheck the BD PROCHOT check box.

Thursday, October 3, 2013

Starting tomcat6: Error code 4

[root@vm-scim-dev logs]# service tomcat6 restart
Stopping tomcat6:                                          [  OK  ]
Starting tomcat6: Error code 4                             [FAILED]


I was able to solve this error by providing some disk space as the disk space was full causing this error.

Tuesday, September 24, 2013

Java thread wait notify alternate text print


package com.cisco;

import java.util.concurrent.locks.Lock;

public class Threads {

    private Object lock= new Object();
    private boolean flag = false;
    private Runnable thread1 ;
    private Runnable thread2 ;
    
    public static void main(String[] args) throws InterruptedException {
        Threads threads  = new Threads();
        threads.thread1 =  threads.new MyRunnable();
        threads.thread2 = threads.new MyRunnableT();
        Thread thread1 = new Thread(threads.thread1);
        Thread thread2 = new Thread(threads.thread2);
        thread1.start();
        thread2.start();
        try {
            thread1.join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("thread 1 joined");
        thread2.join();
        System.out.println("end");
        
    }
    
    class MyRunnable implements Runnable {

        @Override
        public void run() {
            for (int i =0 ;i<10;i++){
            synchronized(lock){
                System.out.println("I have the lock" + Thread.currentThread().getName());
                try {
                    if(flag==false)
                    {// if flag == false you wait for it to be true
                        
                        lock.wait();
                        // do whatever you want
                        //s et flag to false
                        flag = false;
                        lock.notify();
                    }    
                    else {
                        // flag is true so do whatever you want and then set it to false
                        // do what ever you want 
                        flag= true;
                        lock.notify();
                        
                        }
                    } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                }
            }
        }
        
    }
    
    class MyRunnableT implements Runnable {

        @Override
        public void run() {
            for (int i =0 ;i<10;i++){
            synchronized(lock){
                System.out.println("I have the lock" + Thread.currentThread().getName());
                
                    if(flag==true)
                        {
                        // do what ever you want and then set the flag to true
                        // and then notify the other thread.
                        flag = false;
                        lock.notify();
                        
                        }
                    else {
                        // if flag is true you wait for it to be false
                        // then do whatever you want and then set it to true
                        try {
                            
                            // do whatever you want
                            flag = false;
                            lock.notify();
                            lock.wait();
                            
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                
                }
            }
        }
        
    }
}

Tuesday, September 17, 2013

'ascii' codec can't encode character u'\u2019' in position 16: ordinal not in range(128)


http://stackoverflow.com/questions/3224268/python-unicode-encode-error

Likely, the problem is that you parsed it okay, and now you're trying to print the contents of the XML and you can't because theres some foreign Unicode characters. Try to encode your unicode string as ascii first:
unicodeData.encode('ascii', 'ignore')

HTTP Request with headers in Python

#!/usr/bin/env python

import requests
import xml.etree.ElementTree as ET

headers = {'key':'value'}

r = requests.get('www.google.com',auth=('username', 'password'),headers=headers)

print r.text

root = ET.fromstring ( r.text.encode('ascii','ignore'))

for xyz in  root.findall('POPULARITY_RECORD'):
        neoUrl = xyz.find('FIELD_VALUE').text
        print neoUrl
        httpstatus_neo = requests.get(neoUrl)
        print httpstatus_neo.status_code
# print r.text

Reading XML in python

#!/usr/bin/env python

import xml.etree.ElementTree as ET
import httplib
import urllib2
tree = ET.parse('popularity_response.xml')
root = tree.getroot()
print root
for popularity_record in root.findall('POPULARITY_RECORD'):
 print popularity_record.find('FIELD_VALUE').text
 try : 
  response =     urllib2.urlopen(popularity_record.find('FIELD_VALUE').text)
  print response.code
 except urllib2.URLError as e :
  print e
  continue

Tuesday, September 3, 2013

Configuring Oracle for Python

Configuring Oracle for Python
Python code for testing ORacle DB COnnectivity

# assuming python and pip are already installed
# installing the instantclient is usually where problems happen
# download the following files from oracle
# oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
# oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
# oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
# install the rpms
rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
# the sqlplus package isn't specifically needed, but is usually useful for testing and command line sql connections
# configure oracle env (modify exact path based on version of rpm you download)
vim /etc/profile.d/oracle
#!/bin/bash
LD_LIBRARY_PATH="/usr/lib/oracle/11.2/client64/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
TNS_ADMIN="/etc/oracle"
export TNS_ADMIN
ORACLE_HOME="/usr/lib/oracle/11.2/client64/lib"
export ORACLE_HOME
# copy/create your tnsnames.ora file
touch /etc/oracle/tnsnames.ora
# symlink headers to ORACLE_HOME to avoid "cannot locate Oracle include files" error
mkdir /usr/lib/oracle/11.2/client64/lib/sdk
ln -s /usr/include/oracle/11.2/client64 /usr/lib/oracle/11.2/client64/lib/sdk/include
# done. Install cx_Oracle
pip install cx_Oracle
----------------------------------------------------------------------------------------
import os
import cx_Oracle
import csv
SQL="SELECT * FROM SOME_TABLE"
# Network drive somewhere
filename="S:\Output.csv"
FILE=open(filename,"w");
output=csv.writer(FILE, dialect='excel')
# You can set these in system variables but just in case you didnt
os.putenv('ORACLE_HOME', '/oracle/product/10.2.0/db_1')
os.putenv('LD_LIBRARY_PATH', '/oracle/product/10.2.0/db_1/lib')
connection = cx_Oracle.connect('userid/password@99.999.9.99:PORT/SID')
cursor = connection.cursor()
cursor.execute(SQL)
for row in cursor:
    output.writerow(row)
cursor.close()
connection.close()
FILE.close()