Wednesday, August 22, 2012

Monday, May 14, 2012

Finding intersection of two regression lines using R


Suppose m1 and m2 are 2 regression models created using lm() in R, then try
cm <- rbind(coef(m1),coef(m2)) # Coefficient matrix
c(-solve(cbind(cm[,2],-1)) %*% cm[,1])
which would give you the point of intersection.

Tuesday, March 6, 2012

protect(): protection stack overflow

How to solve this?

Start command line R setting the following option:
--max-ppsize

by default it is set to 50000
but you can change it to any value up to 500000.
More details at http://stat.ethz.ch/R-manual/R-devel/library/base/html/Memory.html

Monday, March 5, 2012

Securing Mac's Single User Mode

Despite Mac's glory for user interactivity, its single user mode gives virtually anyone root access.

To secure this, for Mac 10.5 and above, do the following:

1)Add the password for the root user at single user mode by typing the following using any admin user
sudo passwd -i file root

2)Open the profile file of the root using:
sudo pico /var/root/.profile
and add the following:
if ["$TERM"="vt100"];
then
/usr/bin/lock -p -t 86343727
fi

3) Also remember to download the lock binary either from
tech.tedthepenguin/lock.zip or
get it from 10.4 or
email me and I will send it to u
and add it to the /usr/bin folder since it is unavailable since 10.5

Monday, February 27, 2012

Backup failed hard disk data on Mac

I recently encountered a Mac that would not boot properly. However, it did boot into single-user mode and allowed access to the file system via the command line interface. Since I had recently purchased an external, portable USB drive, I wanted to offload my important files to the USB drive before reformatting and reinstalling a fresh system. Here are the steps I took:

  • Connect USB drive to Mac and boot into single-user mode (cmd-s)
  • At prompt type:
    /sbin/mount -uw /

    then hit return

  • At prompt type:
    /sbin/fsck -fy

    then hit return

  • At prompt type:
    ls /Volumes

    then hit return. This should provide a list of mounted volumes. It’s likely that your USB drive will not show. If this is true, then you will need to create a sharepoint in the /Volumes directory. You do this by using this command (in this case, we are creating a directory called “usb”):

    mkdir /Volumes/usb

    then hit return

  • Next we need to identify the disk number of the USB drive. This is done with this command:
    ls /dev/disk*

    then hit return. The system will list the disks like this:

    disks1 300x14 Mounting USB Drive in Single User Mode

In most cases, the USB drive will be the last disk number listed (in this case: disk0s3).

  • Now, to mount this disk to your sharepoint, type the following command:
    /sbin/mount_msdos /dev/disk0s3 /Volumes/usb

    then hit return. NOTE: In this case, we are using disk0s3 since it is the last listed. Yours will likely be different. Also note that my Western Digital USB drive uses the msdos format. Yours may not.

  • If this is mounted properly, you will be able to see the contents of your USB drive by using this command:
    ls /Volumes/usb

    then hit return

  • If you have successfully mounted the USB drive, you may now copy files using thecpcommand. (In this example, I will copy a file named “testfile” and assume the Mac has a volume named MacHardDrive.) For example:
    cp /Volumes/MacHardDrive/testfile /Volumes/usb/

    then hit return.

You can use this method to copy entire directories from your ailing Mac to the USB drive. In my case, I copied the entire user account directory over to the USB drive so I would keep settings, mail, music, pictures, and files in my Documents directory.