Tuesday, August 27, 2013

Install latest version of R on Ubuntu [if you have some version already installed and getting ERROR: dependencies ‘mclust’, ‘flexmix’ are not available for package ‘fpc’ on R studio]

I had R 2.0.14 on my ubuntu 12.04 LTS and was trying to use the command 
install.packages("fpc")

ERROR: dependencies ‘mclust’, ‘flexmix’ are not available for package ‘fpc’

That is where is realized that my R version is old to have these packages and hence the obvious solution is to uninstall and install latest R 

These details i found on StackOverflow  and it worked for Me

Uninstall old R
sudo apt-get remove r-base-core
Adding deb to sources.list
sudo nano /etc/apt/sources.list    
deb http://cran.rstudio.com/bin/linux/ubuntu precise/
precise is your ubuntu name (may be different)
Add key to sign CRAN packages
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
Add specific PPA to the system
sudo add-apt-repository ppa:marutter/rdev
sudo apt-get update
sudo apt-get upgrade
installing
sudo apt-get install r-base
From R to check version
version
should give you
version.string R version 3.0.1 (2013-05-16)
Credit Anando Mahto (StackOverflow member)


Thursday, June 6, 2013

python connection with mysql DB and data fetch on Linux(Ubuntu)


At first check the installation of python by firing this command on console


>$mysql -h 127.0.0.1 -u root -p
 password: *******

PS:Here my installation of mysqldb is as a root user which is true in most of the cases as mysql come pre packaged with ubuntu 12 , (i am not sure about the earlier versions but u can always test it by firring a simple command  which mysql  and figure out if you have already mysql installed)

an empty result ensures that you do not have mysql installed where as the result pointing to a bin location represents that you already  have mysql.

Any way there are millions of web pages already available on how  to install mysql on ubuntu so i will not get on to it and try to stick to the blog headline which is connection of python script to mysql db to fetch data. (U also need to worry about python installation if it is not part of distribution of linux package you are using.
  
any way : 

I assume now you have a working mysql and have created a DB and a basic table with some data in it
(create simple table with one id and one data column to keep it simple)

Now 
save this script as a python script

mport MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="root", # your username
                      passwd="******", # your password
                      db="TestDB") # name of the data base

# you must create a Cursor object. It will let
#  you execute all the query you need
cur = db.cursor()

# Use all the SQL you like
cur.execute("SELECT * FROM NODEJSTEST")

# print all the first cell of all the rows
for row in cur.fetchall() :
    print row[0]

This should be able to return you all the columns from your table 

Error:             if you get in to error of mysqldb not recognised

sudo apt-get install python-mysqldb

Running this will get you out of this error . Some time it appears some time it does not hence i have not included it as a part of regular work. It is also possible that the system it worked , was already configured for it (i work on dev set up which is used by many developers so can not really tell ), so may be its a necessary step. You might want to even do it as a regulr step if you dislike errors :) 

Mail me if you do not find the steps working and we shall work together to get it working


         









Sunday, March 24, 2013

setting "rm" to move files (and folders) to trash-"rm -rf" Undo

Step1. sudo apt-get install trash-cli

Trash-cli:This package provides a command line interface trashcan utility compliant with the FreeDesktop.org Trash Specification. It remembers the name, original path, deletion date, and permissions of each trashed file

Step2sudo gedit /usr/local/bin/trash-rm

in Ubuntu 10.04 i found it to be sbin than bin so command might be 

sudo gedit /usr/local/sbin/trash-rm

Step 3
Paste this content 
#!/bin/bash
# command name: trash-rm
shopt -s extglob
recursive=1
declare -a cmd
((i = 0))
for f in "$@"
do
case "$f" in
(-*([fiIv])r*([fiIv])|-*([fiIv])R*([fiIv]))
tmp="${f//[rR]/}"
if [ -n "$tmp" ]
then
#echo "\$tmp == $tmp"
cmd[$i]="$tmp"
((i++))
fi
recursive=0 ;;
(--recursive) recursive=0 ;;
(*)
if [ $recursive != 0   -a  -d "$f" ]
then
echo "skipping directory: $f"
continue
else
cmd[$i]="$f"
((i++))
fi ;;
esac
done
trash "${cmd[@]}"

Save and Exit

Set Correct executable rights on the created file
Step:4
sudo chmod +x /usr/local/bin/trash-rm


Step 5:
gedit ~/.bashrc


Step 6:
alias rm = "trash-rm"
Step7:$bash
Re run bash on linux terminal to re run the bashrc

Step8:

Try by creating a file and then using rm -rf "createdFile.txt"

find that file in Trash 













Tuesday, March 19, 2013

ECLIPSE Shortcut for converting lower case to upper and vice versa

Just a quick short cut which is very useful for developers to convert the selected lower case text to Upper case and vice versa

Lower case: CTRL+SHIFT+Y (CMD+SHIFT+Y on Mac OS X)
Upper case: CTRL+SHIFT+X (CMD+SHIFT+X on Mac OS X)

The good thing here is you can select one or multiple characters/word/lines by using Using + ->/<-/DownArray and then convert all of it at once.

Sunday, December 2, 2012

Android Installation problem [Can not complete the Install ] Solved


Problem
Cannot complete the install because one or more required items could not be found.
  Software being installed: Android Hierarchy Viewer 18.0.0.v201203301601-306762 (com.android.ide.eclipse.hierarchyviewer.feature.group 18.0.0.v201203301601-306762)
  Missing requirement: Android Hierarchy Viewer 18.0.0.v201203301601-306762 (com.android.ide.eclipse.hierarchyviewer.feature.group 18.0.0.v201203301601-306762) requires 'org.eclipse.core.runtime 3.6.0' but it could not be found

Please note same message for  "Android DDMS","Android Development Tools" and  "Android Traceview"

Or Duplicate Repository problem where as creating the new Android Project option doesnt appear 


Head over to Help -> Install New Software. Click on Available software sites. Delete the Android repo. Uncheck Indigo & Eclipse updates & recheck them. Now head back to Help -> Check for updates. Once done, add the Android repo again. Accept the license & you should be good to go.
(Had to do the same yesterday after getting Indigo)
Source: StackOverFlow: Pasting here as this Solution worked for me after trying a lot of solutions posted over net 

Sunday, August 26, 2012

TCS fiasco and How to keep your account safe while changing mobile no


  24th August and the morning news came out as Techie steals Rs 49L from 3 bank accounts in Chennai. This news was definately worth the attention as while working with multiple service /Product companies techies like me  do get exposed to sensitive information. Here is what heppned in short and how the fraud was done



TCS Fraud protype

















                         

 Now the account and details related to it are in total unsafe hands and is     exposed to the variety of fraud which can be done . Now though the likelihood of having access to Bank DB is very less but even a person in million having access  to bank DB with malicious intention can give any bank a very hard time. The only way for the bank to trace back in these situation is to trace  the user            Machine IP where query was executed and me myself being a techie can say it for sure , its a cake walk to  mask my IP and give the Bank guys even a harder time trying to trace the origin of fraud.
  The point worth mentioning in this TCS fiasco is ,the techie was caught only becasue he/She  gone greedy and started withdrawing large amounts. However if they had kept a little control on their greed, it was close to impossible to figure out . And we will never know if the employee had done small such malicious activity in past and the amount was not big enough to draw attention of bank officials.

  Looking at the pattern however , it exposes the seriousness with which customer's private data is maintained, and the low level of security practises banks follow in order to save their customers hard earned money.this also brings the necessity  of a strong and capable Real Time online fraud monitoring system where multiple such incidents are coded as  a part of online transaction as well as card swipe process and is capable to stop transaction in any of the possible fraud scenario and is part of core banking system . 

  it will be interesting to see in indian market where changing the mobile number  is such a common process , if one gets access to telecom DB and does a intersection and imaginary scenario something like this 

The received out put list is the list of customer whoose transaction should be immideatly blocked until the new number is updated other wise in a matter of second and effort of two software engineers (One working for Bank and one working for Telecom ) is capable of adding multiple zeroes in the 49Lakh amount fraud..
  For customers , they should immediately give standing instruction to bank/Credit card company to stop doing any sort of transaction unless  they have a working number again.The process might look a little cumbersome to follow but as we all know it for a fact that its always  “better to be safe than sorry“.











Sunday, June 24, 2012

Count The No of Inversion in merge Sort

Algo:

 i have followed to do the same


  1. Merge sort array A and create a copy (array B)
  2. Take A[1] and find its position in sorted array B via a binary search. The number of inversions for this element will be one less than the index number of its position in B since every lower number that appears after the first element of A will be an inversion.
    2a. accumulate the number of inversions to counter variable num_inversions.
    2b. remove A[1] from array A and also from its corresponding position in array B
  3. rerun from step 2 until there are no more elements in A.
Here’s an example run of this algorithm. Original array A = ( 14, 8, 12, 3, 2)
1: Merge sort and copy to array B
B = (2,3,8,12,14)
2: Take A[1] and binary search to find it in array B
A[1] = 14
B = (2,3,8,12,14)
14 is in the 5th position of array B, thus there are 4 inversions. We know this because 14 was in the first position in array A, thus any lower value element that subsequently appears in array A would have an index of j > i (since i in this case is 1).
2.b: Remove A[1] from array A and also from its corresponding position in array B (bold elements are removed).
A = ( 14, 8, 12, 3, 2) = (8, 12, 3, 2)
B = (2,3,8,12,14) = ((2,3,8,12)
3: Rerun from step 2 on the new A and B arrays.
A[1] = 8
B = ((2,3,8,12)
8 is now in the 3rd position of array B, thus there are 2 inversions. We know this because 8 was in the first position in array A, thus any lower value element that subsequently appears would have an index of j > i (since i in this case is again 1). Remove A[1] from array A and also from its corresponding position in array B (bold elements are removed)
A = (8, 12, 3, 2) = 12,3,2
B = (2,3,8,12) = 2,3,12
Continuing in this vein will give us the total number of inversions for array A once the loop is complete

Try to code as per Algo , it gives a complete result
i am not sharing code as its against the fair code Stanford rule and will share only once the date for submitting assignment is expired
however am okay if u need any help in completing this exercise and Java is teh language i prefer to code in