Thursday, April 25, 2013

Installing and Running MongoDB on Mac

So, I think that mongoDB instructions are not complete enough to install it on Mac. Here is what I did to install mongoDB:

  • Download it from http://www.mongodb.org/downloads
  • Move the files to where you like it to be installed:    mv -n mongodb-osx-[platform]-[version]/ /PATH/TO/NEW/LOCATION/
  • Decompress the files: tar -zxvf mongodb.tgz
  • Make a data directory: sudo mkdir -p /PATH/TO/DATA/FOLDER/db
  • Allow mongoDB to access this directory: sudo chown `id -u` /PATH/TO/DATA/FOLDER/db
  • Create a log directory: sudo mkdir -p /PATH/TO/DATA/FOLDER/db
  • Create a config file for it in the /etc folder: sudo vi /PATH/TO/LOG/FOLDER/mongod.log
  • Fill in the configurations: 
#mongod config file
#replica setreplSet=replA
#start mongod in shardsvr modeshardsvr=true
#where to loglogpath=/PATH/TO/LOG/FOLDER/mongod.log
#log overwritten or appended tologappend=true
#fork and run in backgroundfork=true
#override portport=27018
#path to data filesdbpath=/PATH/TO/DATA/FOLDER/data/db
  • Configure: mongod --config /etc/mongod.conf
  • Run the server: /PATH/TO/MongoDB/BinFolder/mongod
  • Run the client: /PATH/TO/MongoDB/BinFolder/mongo
That's it! Of course you can add the bin folder to $PATH to make it easier for you to access and run mongoDB. Have fun creating cool databases! 

P.S. I have Mountain Lion and mongoDB 2.4.1

Wednesday, January 30, 2013

Loading a file into Jena

Ok, so I got so many exceptions like:

com.hp.hpl.jena.shared.DoesNotExistException
com.hp.hpl.jena.shared.JenaException: java.net.UnknownHostException:
com.hp.hpl.jena.shared.JenaException: java.net.MalformedURLException: no protocol

First of all, you need to give a URL of file, not a path to file, to Jena. Second, at some cases, like mine, just adding the string "file:" or "file://" to the beginning of your file address doesn't work. BUT, getting the file's URI and converting it to String works perfectly, even though it returns the same string as if you have appended the file address with "file:".

So, if you're struggling over reading some files into Jena, as I did, give this a try:

String url = new File(fileAddr).toURI().toString();
TDBLoader.loadModel(model, url, true);

Sunday, January 20, 2013

MSE of Non-Zero Elements in Matlab


Suppose you have a predicted matrix and a ground truth matrix. You want to find MSE (Mean Squared Error) of only non-zero elements in your prediction. Here is what you do:

[i j k]= find(truth);

f = (sparse(i,j,k)-sparse(i,j,predicted(find(truth)))).^2;

MSE=sum(f,2)./sum(f~=0,2);



The following counts (size of) the nonzero entries in each row of a matrix without loop:

c = sum(f~=0,2);


spconvert does the reverse of full command :)

Tuesday, January 8, 2013

Setting Group Permission of a Folder in Linux


make sure user is in the group:
sudo usermod -a -G <group-_name> <some_user>

set the correct permissions on group:
sudo chgrp -R <group-_name> <folder>
sudo chmod -R g+w <folder>

make sure all new files and directories created under <folder> are owned by the group:
sudo find <folder> -type d -exec chmod 2775 {} \;  


Find all files in <folder> and add read and write permission for owner and group:



sudo find <folder> -type f -exec chmod ug+rw {} \;