Monday, February 17, 2014

Sql procedure to read data from mySQL DB

Learning :


mysql procedure to get the data from a table
************************************************************
DELIMITER $$
DROP PROCEDURE IF EXISTS sp_transpose_tickets $$
CREATE PROCEDURE sp_transpose_tickets ()
BEGIN
    select eladm.DiagnosisCode,eladm.PatientID from admission eladm;
END$$
DELIMITER ;





************************************************************
where admission== tableName


to see what is stored
*******************************
call sp_transpose_tickets()
*******************************

Friday, September 20, 2013

Run Rserve on eclipse Example java code

assuming that you have R installed , bring up the R console by typing 
R on console (in context of linux) 
install.packages("Rserve")
library(Rserve)
Rserve()
Wait for final message at console as below
Rserv started in daemon mode.
import org.rosuda.JRI.Rengine;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.REngineException;

class RServerHello {


Rengine rengi
import org.rosuda.REngine.Rserve.*; publi cne; // initialized in constructor or autowired

eption {
try {

RConnection c = new RConnect
public void helloRWorld() throws REXPMismatchEx cion();// make a new local connection on default port (6311)
org.rosuda.REngine.REXP x0 = c.eval("R.version.s
double d[] = c.eval("rnorm(10)").asDoubles(); tring"); System.out.println(x0.asString()); } catch (REngineException e) { //manipulation
new RServerHel
} } public static void main(String[] args) throws REXPMismatchException { RServerHello hwObj = lo(); hwObj.helloRWorld(); }
}
Download RserveEngine.jar and include that as an external jar at configure build path (Right click on your file at project explorer -> Build Path --> configure build path).
Your java code now should be free of all errors
Run!!!
It should just work

Tuesday, September 17, 2013

touchpad disabled after upgrading kernel to 3.4.0-030400-generic on Ubuntu 12.04 Dell Vostro-Solved

Recently i upgraded my kernel of Ubuntu 12.04 LTS from 3.2.xxx to 3.4 for some software installation , however found my Vostro Dell touchpad disabled and mouse non functional

Here are the commands which help me in getting back the control of touchpad
This command will reload the mouse driver

sudo modprobe -r psmouse
sudo modprobe psmouse proto=imps
Also this helps only to make it working in current session , to be able to have it working on every boot time as you would have already figured out , we need to add it to /etc/modprobe.d
Create a file like sudo vi mouse.conf
Add this as a content of file
options psmouse proto=imps
save it , hopefully you wont see the problem again , its like adding a service at stratup as per windows definition.

Manish

Thursday, August 29, 2013

install sqldeveloper on Ubuntu 12.04 LTS

1.download the oracle from Oracle main Site …Geek alert- Nah no command for this , you need to go register and download !!!
2.sudo apt-get install alien (Most probably this would have got already installed while installing oracle)
3.Logically you have  a rpm now so you got to change it to the format ubuntu understands it right ? Alient is your saviour to get that bit done

sudo alien --scripts -d sqldeveloper-3.2.20.09.87-1.noarch.rpm

4.Install sql developer from the deb package you have
sudo dpkg -i sqldeveloper_3.2.20.09.87-2_all.deb

5.Create the following directory in your home folder, this where it's going to store path to the jdk in the next step:
cd /home/$username(The system name variable)
say in my case cd /home/manish
  1. mkdir .sqldeveloper/
Run the sql developer from shell it is gonna ask it to feed path of java Do that , see 
echo $JAVA_HOME and feed that as input
mostly it is going to look like this
/usr/lib/jvm/java-6-openjdk
sudo /opt/sqldeveloper/sqldeveloper.sh

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