Saturday, November 24, 2012

Tuesday, October 2, 2012

.htaccess redirect

To redirect from abc.com to blog.abc.com, create a .htaccess  at the root directory of abc.com with the following line in it :

Redirect /index.html http://blog.abc.com

Sunday, September 2, 2012

Tuesday, July 31, 2012

Changing system locale in R for locale dependent time string readings

lct <- Sys.getlocale("LC_TIME")
lct
[1] "French_Canada.1252"
strptime(" 27 Jun 2011 19:57:18","%d %b %Y %H:%M:%S") #Does not work
[1] NA
Sys.setlocale("LC_TIME", "C") #Change the locale to C
[1] "C"
strptime(" 27 Jun 2011 19:57:18","%d %b %Y %H:%M:%S") #Now it works
[1] "2011-06-27 19:57:18"
Sys.setlocale("LC_TIME", lct)
[1] "French_Canada.1252"

Sunday, July 29, 2012

Debugging R : Catching warnings

withCallingHandlers(HL<-IDP_Read_Hydrolight512_Mfile(infile), warning=function(c) recover())

Accessing the contents of the special argument "..." in R

names(match.call())

also try ..1, ..2 etc

also try
dots <-match .call=".call" expand.dots="F)$...<!-----">

Friday, July 27, 2012

Multiple Y-axis in a R plot

Good and simple tutorial : http://www.r-bloggers.com/multiple-y-axis-in-a-r-plot/

Thursday, July 5, 2012

R graphic margins

R graphic margins http://rgraphics.limnology.wisc.edu/rmargins_sf.php http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/index.htm

Tuesday, May 15, 2012

Enable Skype Icon on Unity Notification Panel on Ubuntu 12.04 LTS

http://www.tautvidas.com/blog/2012/05/enable-skype-icon-on-unity-panel-on-ubuntu-12-dot-04-lts/

Wednesday, May 9, 2012

Nvidia driver does not install in Ubuntu 12.04 precise

Follow http://dragly.org/2012/05/04/installing-the-nvidia-driver-in-kubuntu-12-04/

Tuesday, May 8, 2012

Repairing grub by booting from the Ubuntu live-CD

I just installed the new version of Ubuntu (12.04). The installation went fine but the bootloader installation at the end did not work. When I turn on the computer, the new version of the ubuntu does not show in the old bootloader (grub2) menu. What to do? #Boot the computer with the Ubuntu live cd, mount the / partition under /home/ubuntu/a and issue the following command : sudo mount --bind /dev/ /home/ubuntu/a/dev sudo mount --bind /proc/ /home/ubuntu/a/proc sudo mount --bind /sys/ /home/ubuntu/a/sys sudo chroot /home/ubuntu/a #Then let grub2 create /boot/grub/grub.cfg by autodetecting the present OS'es sudo update-grub Found linux image: /boot/vmlinuz-3.2.0-23-generic Found initrd image: /boot/initrd.img-3.2.0-23-generic Found memtest86+ image: /boot/memtest86+.bin Found Windows 7 (loader) on /dev/sda1 Found Ubuntu 10.10 (10.10) on /dev/sda6 done #Exit from the modified chroot exit #Run grub-install sudo grub-install --root-directory=/home/ubuntu/a /dev/sda You should get the message : Installation finished. No error reported.

Wednesday, April 25, 2012

Syntax highlighting in Blogger with SyntaxHighlighter

http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

Wednesday, March 21, 2012

Compiling source code of netcdf4 on linux

First obtain szip libraries (from the link at http://www.hdfgroup.org/HDF5/release/obtain5.html)
wget http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz
tar -xzvf szip-2.1.tar.gz
cd szip-2.1

./configure --prefix=/home/acizmeli/opt
make 
make test
make install

Then obtain the hd5 source code  (again from http://www.hdfgroup.org/HDF5/release/obtain5.html)
wget http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz
tar -xzvf hdf5-1.8.8.tar.gz 
cd hdf5-1.8.8
./configure --prefix=/home/acizmeli/opt  --with-szlib=/home/acizmeli/opt/
(make sure that ./configure has recognized the szip libraries)
make
(or for parallel compilation : ) make -j -16
make install

Then obtain the netcdf4 source :
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.2.tar.gz
tar -xzvf netcdf-4.2.tar.gz
cd netcdf-4.2
CPPFLAGS=-I/home/acizmeli/opt/include/ LDFLAGS=-L/home/acizmeli/opt/lib ./configure --prefix=/home/acizmeli/opt/
make
make install

If there is a doxygen error, try adding --disable-doxygen

Sunday, March 11, 2012

Find nearest neighbours in a point cloud

From http://rwiki.sciviews.org/doku.php?id=tips:spatial-data:overlapping

library(spdep)
data(columbus)
#Extract coordinates from a data frame
coords <- columbus[,c("X", "Y")]
#For each point, determine the four closest points based on great circle distances:
knn.col <- knearneigh(as.matrix(coords), k=4, longlat=T)
knn.nb <- knn2nb(knn.col)
#What are the indices of the four nearest neighbours to point number 5?
knn.col$nn[5,]
#Equivalently:
knn.nb[[5]]
#Plot all points, then mark point number 5 by red, and its four nearest neighbours by blue:
plot(coords)
points(coords[5,], col="red", pch=19)
points(coords[knn.nb[[5]],], col="blue", pch=19)

Some beginner tricks with git

#################################################
Problem : error: Your local changes to the following files would be overwritten by merge: rfiles/BiOpticaR/Various/spacetime_ISIN.R
Please, commit your changes or stash them before you can merge.Aborting
#################################################
$ git pull
remote: Counting objects: 38, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 25 (delta 13), reused 1 (delta 0)
Unpacking objects: 100% (25/25), done.
From ssh://ekumen/home/acizmeli/GIT
   d63ba8f..cea6b9e  master     -> origin/master
Updating d63ba8f..cea6b9e
error: Your local changes to the following files would be overwritten by merge:
    rfiles/BiOpticaR/Various/spacetime_ISIN.R
Please, commit your changes or stash them before you can merge.
Aborting

Solution:
$ git reset --hard HEAD
HEAD is now at d63ba8f Moved all netcdf imagery functions in the fil......
$ git pull

#################################################
Problem :  Push rejected
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to.....
#################################################
Solution:
(From http://rip747.wordpress.com/2009/04/20/git-push-rejected-non-fast-forward/)

When trying to do a push to a repo, you might encounter the following error:
$ git push github master
To git@gitproxy:rip747/cfwheels.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to ‘git@gitproxy:rip747/cfwheels.git’
Don’t panic, this is extremely easy to fix. All you have to do is issue a pull and your branch will be fast-forward:
$ git pull github master
From git@gitproxy:rip747/cfwheels
* branch            master     -> FETCH_HEAD
Already uptodate!
Merge made by recursive.
Then retry your push and everything should be fine:
$ git push github master

#################################################
Problem : Automatic merge failed; fix conflicts and then commit the result.
#################################################
use :
git mergetool

Wednesday, March 7, 2012

Some time conversions in R

Form a "POSIXlt" object from a string :
tt = strptime("20100101","%Y%m%d", tz="GMT")

Compute the seconds since 1970 ((Internal storage format of the "POSIXlt" class)
as.double(tt)

Compute the days since 1970 (Internal storage format of the "Date class)
as.double(as.Date(tt))
or
unclass(as.Date(tt)) 

Convert an xts object into seconds since 1970
xx = xts(111, tt)
as.double(time(xx))

Convert an xts object into days since 1970
floor(as.double(time(xx))/60/60/24)

Construct a time object from different numeric components
ISOdatetime(year, month, day, hour, min, sec, tz = "")

Extract from a POSIXlt object the Year, month, day  etc information in numeric format :
class(a)
[1] "POSIXlt" "POSIXt"

a
[1] "2009-07-06 20:00:28"

c(a$year+1900, a$mon+1, a$mday, a$hour, a$min, a$sec)
[1] 2009    7    6   20    0   28

Convert a ESRI shapefile into GMT vector format

Use ogr2ogr to convert the shapefile into GMT vector format :

ogr2ogr -f "GMT" Hudson_bounds.gmt  Hudson_bounds.shp

Wednesday, February 29, 2012

Switch the layout of your keyboards

Handy switch if you need to change regularly between layouts of keyboards.


Setxkbmap is a tool to set the keyboard layout. In the options of the tool you're allowed to set a switch.

setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll be,us

sets the keyboard to belgium (be) and with alt+shift I can switch to a us layout.

You can find the explanation for the coding in:

/usr/share/X11/xkb/rules/xorg.lst

You might want to execute this command autocratically on login, so you don't have to type it all the time again.

create a file "setxkbmap.desktop" in "~/.config/autostart/"

nano  ~/.config/autostart/setxkbmap.desktop

and enter the setxkbmap command

[Desktop Entry]
Encoding=UTF-8
Name=sertxkbmap
GenericName=set keyboard layout
Comment=Switch with alt+shift the layout of your keyboard
Exec=setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll be,us

this file will be run every time you login to your system

Tuesday, February 28, 2012

Changing the filename extension in R

Filenames ending with *.bin or *.txt will be given the extension *.grd. Applies to a character array containing multiple strings

outFileName = gsub("\\.bin|\\.txt", ".grd", inFileName)

Saturday, February 18, 2012

Ubuntu keyserver

If you have a keyserver error after adding a new repository try doing
 
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
 
replace 16126D3A3E5C1192 with the key of the repository you just added.

Thursday, February 16, 2012

Free tool for resizing a windows partition - EASEUS

EASEUS is free and works like a charm. It resizes a windows NTFS partition smaller than the size allowed by the Windows' own partition manager.

Tuesday, February 7, 2012

Reloading an updated R package without quitting R

Let us say that we worked on the source code of the package Cops and we would like to reload it  without quitting R

Re-install the package from Terminal 1 :
R CMD build Cops; sudo R CMD INSTALL Cops_1.2.tar.gz


Reload the modified package from the R session already running in  Terminal 2 :
detach(package:Cops,unload=T); library(Cops)

Thursday, January 12, 2012

Openoffice menu fonts display garbage with Nvidia graphic card in Ubuntu

http://user.services.openoffice.org/en/forum/viewtopic.php?f=16&t=10183#p59220

1. Ubuntu: System > Preferences > Appearance > Visual Effects Tab > None.
2. Open Office: Tools > Options > OpenOffice.org Entry > View Entry > Uncheck "Screen font antialiasing."
3. Ubuntu: System > Preferences > Appearance > Visual Effects Tab > Normal/Extra.

Compiling rgdal in 64 bits Mac

from http://blog.fellstat.com/?p=46

Currently Rstudio is available for the Mac platform only in 64 bits. We like Rstudio and continue using it. In order to use rgdal package in 64 bits, we had to compile the rgdal package.

Forst the Mac .dmg file of PROJ.4 was downloaded from the link given above. Then the source code of the latest rgdal (as of today) was downloaded from the rgdal website.

We then compiled rgdal from within a shell script using the following command :

sudo R --arch x86_64 CMD INSTALL --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config --with-proj-include=/Library/Frameworks/PROJ.framework/Headers --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib' rgdal_0.7-5.tar.gz