Wednesday, October 2, 2013

Reshape data in R



hsb2 <- br="" faq="" header="T," hsb2.csv="" http:="" r="" read.table="" sep="," stat="" www.ats.ucla.edu="">hsb2[1:10,]
l <- br="" hsb2="" reshape="">  varying = c("read", "write", "math", "science", "socst"),
  v.names = "score",
  timevar = "subj",
  times = c("read", "write", "math", "science", "socst"),
  new.row.names = 1:1000,
  direction = "long")

l[1:10,]
 
l.sort <- br="" id="" l="" order=""> 
l.sort[1:10,]

l.sort

w <- br="" l.sort="" reshape="">  timevar = "subj",
  idvar = c("id", "female", "race", "ses", "schtyp", "prog"),
  direction = "wide")
 
w

w[1:10,]

Saturday, September 7, 2013

Restoring iPod when you forgot your passcode

1. Connect your iPod to the computer where you normally sync your iPod.
2. Make a backup of the iPod (you will use this later when your restore the contents of the iPod)
3. Restore to factory setting, see: http://support.apple.com/kb/ht1808

Friday, June 28, 2013

Calculate Normal Distribution Using R



#:************************************************************************
#: Author: Alex Madriaga
#: Date: 06/06/2013
#: Time: 11:11:11
#: File: dnorm.r
#: Status: Working using the data in C:/workspace/ecdf/d176m.csv
#: Version: 0.98
#: Description: Latest version of the normal distribution for R scripting
#: Revision history:
#:
#:************************************************************************

# load the csv file, ignoring the header
mainDir <- "C:/workspace/ecdf"
setwd(mainDir)
mainDir <- getwd()
rawCSVFile <- "d176m.csv"
rsm <- read.csv(rawCSVFile,header=TRUE)

# check structure and convert vector values to numeric
str(rsm)
rsm$HEAP <- as.numeric(rsm$HEAP)

# calculate the mean and standard deviation
mean <- mean(rsm$HEAP)
sd <- sd(rsm$HEAP)

#plotting the density function of a normal distribution
heap <- rsm$HEAP

# plot the data
plot(heap, dnorm(heap, mean, sd), type="l")


Bash Script using Flags and Options


#!/bin/bash

#:########################################################################
#: The option-string
#:
#: The option-string tells getopts which options to expect and which of them
#: must have an argument. The syntax is very simple . every option character
#: is simply named as is, this example-string would tell getopts to look
#: for -e, -d and -m:
#:
#: getopts fAx VARNAME
#:
#: When you want getopts to expect an argument for an option, just place
#: a : (colon) after the proper option flag. If you want -e to expect an
#: argument (i.e. to become -e ENVIRONMENT ) just do:
#:
#: getopts ed:m VARNAME
#:
#:########################################################################

function checkParam()
{

  # if no paramter was supplied, show usage
  text="Usage: $0 -e ENVIRONMENT -d DATE_FILENAME.TXT -m METRIC_FILENAME.TXT" 
  [ $# -eq 0 ] && { echo "$text"; exit 1; }

  # parse the flags and options
  while getopts "e:d:m:" opt; do
    case $opt in
      e)
        echo "-$opt $OPTARG $OPTIND $OPTERR was triggered!" >&2
        env=$OPTARG
        ;;
      d)
     echo "-$opt $OPTARG $OPTIND $OPTERR was triggered!" >&2
        fdate=$OPTARG
        ;;
      m)
     echo "-$opt $OPTARG $OPTIND $OPTERR was triggered!" >&2
        fmetric=$OPTARG
        ;;
      *)
        echo "Invalid option: -$opt $OPTARG $OPTIND $OPTERR" >&2
        ;;
    esac
  done

  # show the flags and options that were parsed
  echo "Environment: [$env]"
  echo "Date filename: [$fdate]"
  echo "Metric filename: [$fmetric]"

  # Check the given files exist #
  [ ! -f "$fdate" ] && { echo "Error: $fdate file not found."; exit 2; }
  [ ! -f "$fmetric" ] && { echo "Error: $fmetric file not found."; exit 2; }

  # Check the given files are not empty #
  [ ! -s "$fdate" ] && { echo "Error: $fdate file is empty."; exit 2; }
  [ ! -s "$fmetric" ] && { echo "Error: $fmetric file is empty."; exit 2; }
}

#: ## [ MAIN ] ###
checkParam $@



Sunday, June 23, 2013

Enable SSH on WD MyBook

Link
       

To login use /UI/login, example: http://192.168.1.150/UI/login

Open Mybook UI go to Import / Export Current 
Configuration (under Utilities)

Export the current configuration, open the file, update: 
ssh_enable="disabled", to ssh_enable="enabled", import 
the configuration file

After reboot SSH is enabled.

Default is root / welc0me as per other WD devices.

Change root password right away.


If you want to enable SFTP, modify /etc/ssh/sshd_config 
and add the user who needs to access through SFTP. 
For example: “AllowUsers root malex” enables the user 
“malex” to connect to the device by both ssh and sftp.

Twonky is available at port 9000, example: http://192.168.1.150:9000
FTP when enabled is available using the user you created.

Saturday, June 22, 2013

Load a CSV file and plot the normal distribution curve



# load the csv file, ignoring the header
mainDir <- "C:/workspace/ecdf"
setwd(mainDir)
mainDir <- getwd()
rawCSVFile <- "heap.csv"
rsm <- read.csv(rawCSVFile,header=TRUE)

# check structure and convert vector values to numeric
str(rsm)
rsm$HEAP <- as.numeric(rsm$HEAP)

# calculate the mean and standard deviation
mean <- mean(rsm$HEAP)
sd <- sd(rsm$HEAP)

#plotting the density function of a normal distribution
heap <- rsm$HEAP

# plot the data
plot(heap, dnorm(heap, mean, sd), type="l")


Wednesday, June 19, 2013

Theory on Cross- over ratio of powers

My theory is that the ratio of the electrical power with respect to the software power is constant .Thus, the economics of cost is easily computed in terms of monies.

Theory on Electrical power vs. Soft power

The power consumed by the server and all the devices connected to the whole application platform expressed in electrical Watts is proportional to the power generated by the server expressed in S-WATTS or soft watts or watts subscript small s. This power must also be equal to the power consumed by the users at the receiving end.

Tuesday, June 18, 2013

Theory on Powet factor correction on JVM

Having understood that the JVM is indeed comparable with an AC generator, we are now able to calculate the power factor and efficiency of the server using the vast theories and formula in electrical engineering.

Calculation of R on a system

To measure the R constant of the system, we need to conduct several heap samples at varying number of users. Then calculate the R constant based on the empirical data. That is, R is equal to HSU divided by users.

Potential difference in JVM using VIR model

The potential difference across a server can be calculated using the electrical engineering equation V = IR. The equivalent equation on the JVM is T=HU.

JVM Capacity Model using I^2 R

The electrical engineering equation of power I^2R can be used to calculate the capacity of the server expressed in H^2U, where H is heap memory used in MB and U can be the number of users connected to the servers.Thus Capacity (C) = H^2U. The unit is HSU (Heap Squared Users.

Phase angle differences between the heap and the CPU utilization

When applications are loaded, the tendency of the server is to react accordingly. The question now arise as to which one will react first to the load- the HEAP memory or the CPU usage. My theory is that one of them will be the first and the second will be having a phase angle difference with the other. The sample calculation will be shown later.

Theory on Harmonics In Java-based applications

I discovered yesterday that the heap memory usage of a certain java application  behaves like a triangular waveform and thus can be calculated using RMS values to determine the HEAP at any point in time during runtime. Thus, the frequency of the heap cycles can be described in hertz and heap as Heap-RMS. Having known this behavior, the detection of heap memory leak is possible. Consider a server at no load for a significant amount of time is tested for memory leak. The integral of all d(h)/dt from h(i) to h(f) from t(0) to t(f) must be equal to zero. Even a small delta will indicate a creaping memory leak The calculation will be shown later.

Saturday, June 15, 2013

Hosting your code in sourceforge.net

Steps on hosting your code at sourceforge.net

1. Create an account here: https://sourceforge.net/user/registration
2. Use sftp, WinSCP or Altap Salamander
   Using sftp below:

    linuxuser@localhost:~$ sftp your_user_name@frs.sourceforge.net
    The authenticity of host 'frs.sourceforge.net (216.34.181.57)' can't be established.
    RSA key fingerprint is 06:b0:b0:ca:b0:ca:ca:ca:ba:00:b0:b0:ca:b0:b0:ca.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'frs.sourceforge.net,216.34.181.57' (RSA) to the list of known hosts.
    your_user_name@frs.sourceforge.net's password:
    Connected to frs.sourceforge.net.
    sftp> ls
    sftp> exit
    linuxuser@localhost:~$
3. My account is here: http://azmadriaga.users.sourceforge.net/

Some useful Windows and Linux Programs

Navigate iPad filesystem

i-Funbox

Home: http://www.i-funbox.com/


Description: No Jailbreak SSH, Manage files on your iPhone/iPad just like Windows Explorer on your PC, but in a more robust and friendly way

Simple yet visually awesome code editor and highlighter 

Context 

Home: http://www.contexteditor.org/ 
Highlighters: http://www.contexteditor.org/highlighters/ 

Description: ConTEXT is a small, fast and powerful freeware text editor, developed to serve as a secondary tool for software developers.

Securely delete file using command-line-interface (CLI) in Windows  

SDelete 

Home: http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx 

Description: SDelete implements the Department of Defense clearing and sanitizing standard DOD 5220.22-M, to give you confidence that once deleted with SDelete, your file data is gone forever. Note that SDelete securely deletes file data, but not file names located in free disk space.

Securely delete file using command-line-interface (CLI)  in Linux

SRM: Secure-Delete 

Home: http://techthrob.com/2009/03/02/howto-delete-files-permanently-and-securely-in-linux/
Install: apt-get install secure-delete
Description: This tool is basically a more advanced version of the “shred” command. Instead of just overwriting your files with random data, it uses a special process – a combination of random data, zeros, and special values developed by cryptographer Peter Gutmann – to really, really make sure your files are irrecoverable. It will assign a random value for the filename, hiding that key piece of evidence.


Recover deleted files in Windows/Linux/Mac

TestDisk

Home: http://www.cgsecurity.org/wiki/TestDisk
Description:TestDisk is powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

Split and merge pdf documents, it's free, open source and platform independent

PDFsam

Home: http://www.pdfsam.org/
Description:PDFsam basic is a simple, platform independent software designed to split and merge pdf files. It’s stable, completely free and It should cover most of your needs.

A UI version of diff in Windows

WinMerge

Home: http://winmerge.org/
Description:WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.


Password keeper

KeePass

Home: http://keepass.info/
Description:KeePass is a free open source password manager, which helps you to manage your passwords in a secure way. You can put all your passwords in one database, which is locked with one master key or a key file.

Passwork keeper for Android phones

Pocket

Home: http://www.appbrain.com/app/pocket/com.citc.wallet
Description:Pocket allows you to safely store all your sensitive data such as bank account details and passwords on your phone. Pocket is also useful for remembering all those bits and pieces of information in one place from frequent flier numbers to contact lens prescriptions.


Fast Image Resizer

adionSoft Fast Image Resizer

Home: http://adionsoft.net/fastimageresize/
Description:Resize images to any size quickly and in high quality. Can read JPG, BMP, GIF, PNG, TIFF and HD Photo (.wdp, .hdp) files. Writes JPG, BMP or PNG files. Compatible with Windows XP, Vista, Windows 7, Windows 8 and Mac OS X 10.6



Tuesday, June 11, 2013

Calculating ECDFS using R



        # store this current column to a variable
        pcs <-rsm[[colnam]]

#-- additional implementation
#        pcs2 <- pcs[!duplicated(pcs)]
#        pcs <- pcs2

#        pcs3 <- pcs[ pcs != 0 ]
#        pcs <- pcs3

#--
     # sort the data and store the sorted value to a new variable
        sortpcs <- sort(pcs)

        # calculate the CDF score based on the number of rows
        ecdfpcs <- (1:length(sortpcs))/length(sortpcs)

        # create a data frame from the data
        svrCdf <- data.frame(sortpcs,ecdfpcs)

#-- additonal implementaion
        stop("Message")
        warning("Message")
#--

# hard code the specific directory
        dir <- "c:/amadriaga/a_r"
        setwd(dir)
        dir <- getwd()
        print(dir)
        svrCdfCsvFile <- sprintf("%s/ecdfs_%s_norm.csv",dir,colnam)
        write.csv(svrCdf, file=svrCdfCsvFile, row.names=FALSE)
        print("Successfully completed R script.")



Adding Legend in R using Column names

# add legend to the graph
 legend("topright", legend = c(headerNames[2:length(headerNames)]),
        col=2:length(rsm), pch=20, lty=1,
        lwd=0.75, bty="n", cex=0.75)

Adding Gridlines in R Manually using abline()

  # vertical grid lines
  xMin <- 0
  xMax <- 10
  xStep <- 1
  for (x in seq(xMin, xMax, xStep)){
   print (x)
   abline(v=(seq(x,100,25)), col=195, lty="dotted")
  }
  # highlight on x=4 and x=5
  abline(v=(seq(4,100,25)), col="red", lty=1)
  abline(v=(seq(5,100,25)), col="red", lty=1)

  # horizontal grid lines
  yMin <- 0
  yMax <- 1
  yStep <- 0.1
  for (y in seq(yMin, yMax, yStep) ){
   print (y)
   abline(h=(seq(y,100,25)), col=195, lty="dotted")
  }

  # highlight at y=0.8
  abline(h=(seq(0.8,100,25)), col="red", lty=1)

Determine Column Number based on Column Names

    # print the column name
    print ( colnam )

    # print the number of columns, this is not changing
    print ( counter <-length(rsm) )

    # determine the column number based on the column name
    # and store to a variable
    columnNumber <- which( colnames(rsm)==colnam )

    # print the column number
    print ( columnNumber )

Reading CSV and printing the headers

# Read the raw data
rsm <- read.csv("c:/amadriaga/a_r/rawServerMemory.csv")

# Save the column names to array
headerNames <- colnames(rsm)

# Get count of columns
print (length(rsm))

# Loop on column headers and print the header names
for (colnam in names(rsm)[ 1:length(rsm) ] ){
    # print the column name
    print ( colnam )

    # print the number of columns, this is not changing
    print ( counter <-length(rsm) )

    # determine the column number based on the column name
    # and store to a variable
    columnNumber <- which( colnames(rsm)==colnam )

    # print the column number
    print ( columnNumber )
}

Friday, May 31, 2013

A simple VBA in Excel 2010 to import each CSV file as a tab in XLS

Sub ImportAllCsvInDirectory()
'
' Copied from: http://www.excelforum.com/excel-programming-vba-macros/504512-import-multiple-csv-files-into-current-workbook-as-separate-sheets.html
'
Dim MyPath As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook

'Fill in the path\folder where the files are
'on your machine
'MyPath = "c:\Data"
MyPath = GetFolder("c:\")


'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.csv")

'If Not FilesInPath = False Then
If FilesInPath = "" Then
MsgBox "No files to consolidate"
Exit Sub
End If

On Error GoTo CleanUp

Application.ScreenUpdating = False
Set basebook = ThisWorkbook

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _
basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If
CleanUp:
Application.ScreenUpdating = True

SaveAsNewFile

End Sub


'
' Copied from: http://www.mrexcel.com/forum/excel-questions/294728-browse-folder-visual-basic-applications.html
'
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
    .Title = "Select a Folder"
    .AllowMultiSelect = False
    .InitialFileName = strPath
    If .Show <> -1 Then GoTo NextCode
    sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing

End Function

'
'
Sub SaveAsNewFile()
    Dim wb As Workbook
    Dim NewFileName As String
    Dim NewFileFilter As String
    Dim myTitle As String
    Dim FileSaveName As Variant
    Dim NewFileFormat As Long
  
    Set wb = ThisWorkbook
  
    'Use following code to set to workbook other than this one
    'Set wb = Workbooks("My Test Save As File.xlsm")
  
    If Application.Version >= 12 Then   'Version 12 is xl2007
      'Note: If file extension not included in B18 then concatenate it
      'NewFileName = wb.Sheets("Sheet1").Range("B18").Value & ".xlsm"
      NewFileFilter = "Excel Macro-Enable Workbook (*.xlsm), *.xlsm"
      'The value 52 is substituted in next line for the constant _
       xlOpenXMLWorkbookMacroEnabled because earlier versions of _
       excel will not recognize the constant and code will error.
      NewFileFormat = 52
    Else
      'Note: If file extension not included in B18 then concatenate it
      'NewFileName = wb.Sheets("Sheet1").Range("B18").Value & ".xls"
      NewFileFilter = "Excel 97-2003 Workbook (*.xls), *.xls"
      'Because xlNormal is an earlier version constant, later versions _
       of excel will recognize it.
      NewFileFormat = xlNormal
    End If
  
    myTitle = "Navigate to the required folder"
  
    FileSaveName = Application.GetSaveAsFilename _
            (InitialFileName:=NewFileName, _
             FileFilter:=NewFileFilter, _
             Title:=myTitle)
    If Not FileSaveName = False Then
      wb.SaveAs Filename:=FileSaveName, _
                    FileFormat:=NewFileFormat
    Else
      MsgBox "File NOT Saved. User cancelled the Save."
    End If

End Sub

'
'
Sub OpenFile()
Dim sFilename As String

sFilename = Application.GetOpenFilename("Excel files (*.xls), *.xls")
If Not sFilename = False Then
Workbooks.Open sFilename
Else
      MsgBox "File NOT Saved. User cancelled the Save."
    End If
End Sub

Thursday, May 30, 2013

Creating the SD image for Raspberry Pi using Mac OS X

1. Download the image: 2013-02-09-wheezy-raspbian.img from 2013-02-09-wheezy-raspbian.zip into /Users/alexm/Downloads and unzip it.


2. Insert the SD card into the slot on Mac

3. Verify the disk number assignment of the SD card

ALEXs-MacBook-Pro~$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            419.0 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:       Microsoft Basic Data BOOTCAMP                80.2 GB    disk0s4
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *16.0 GB    disk1
   1:             Windows_FAT_32                         58.7 MB    disk1s1
   2:                      Linux                         1.9 GB     disk1s2

4. Unmount the sd card
ALEXs-MacBook-Pro~$ umount /dev/disk1
umount: /dev/disk1: not currently mounted

5. Unmount again using the diskutil
ALEXs-MacBook-Pro:~$ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful

6. Write the image into the sd card, note, it may take several minutes, take a coffee break.
ALEXs-MacBook-Pro:~$ sudo dd bs=1m if=/Users/alexm/Downloads/2013-02-09-wheezy-raspbian.img of=/dev/disk1

106+0 records in
105+0 records out
110100480 bytes transferred in 75.611085 secs (1456142 bytes/sec)

7. Once completed, eject the sd card.
ALEXs-MacBook-Pro:~$ diskutil eject /dev/disk1
Disk /dev/disk1 ejected

8. Remove sd card and insert into the raspberry pi.

9. Connect all accessories on the raspberry pi and power on.

10. After reboot, you may be able to modify the configuration by opening a terminal and using
the rasp-config:

pi@raspberry$ raspi-config



How to enable X11 Forwarding with SSH on Mac OS X Lion for Raspberry Pi

Steps in getting an X-terminal from Raspberry Pi Using Mac OS X

1. Enable X11 Forwarding with the “X11Forwarding yes” option set in “/private/etc/sshd_config” for your SSH daemon on Mac in order to receive X11 client request back from  raspberry pi through ‘ssh‘ with the -X option set.
    user@mac~$ vi /private/etc/sshd_config
    uncomment and set to yes "X11Forwarding yes"

2. Allow remote client to use Mac's display
    user@mac~$ xhost +

3. Login into the raspberry pi with -X option to install packages
     user@mac~$ ssh -X pi@192.168.1.10

4. Install packages on the raspberry pi
     pi@raspberrypi ~ $ sudo apt-get install libnss3
   pi@raspberrypi ~ $ sudo apt-get install x11-apps

5. Set display
 
 pi@raspberrypi ~ $ export DISPLAY=192.168.1.12:0

6. Open x11 terminal from raspberry to the Mac
  
 pi@raspberrypi ~ $ x-terminal-emulator
 
 OR
   pi@raspberrypi ~ $ lxterminal

7. Test xclock or xeyes
 
 pi@raspberrypi ~ $ xclock
 
 OR
   pi@raspberrypi ~ $ xeyes

8. From another terminal on Mac, you may directly execute

user@mac~$ ssh -X -f pi@192.168.1.10 xcalc -bg yellow -fg blue
pi@192.168.1.10's password:
user@mac~$ ssh -X -f pi@192.168.1.10 xeyes -bg white -fg blue
pi@192.168.1.10's password:


                 

Tuesday, May 28, 2013

Oracle sqlplus and instant client on Mac OS/X without DYLD_LIBRARY_PATH

Oracle sqlplus and instant client on Mac OS/X without DYLD_LIBRARY_PATH

URL: http://blog.caseylucas.com/2013/03/03/oracle-sqlplus-and-instant-client-on-mac-osx-without-dyld_library_path/

Posted on
I recently needed to get sqlplus (11.2) running on a mac (10.8.2). Oracle supports this via their instant client. For basic sqlpus, you need the lite oracle instant client and oracle sqlplus instant client packages. If you try to run sqlplus after unzipping the files, you probably will see an error message similar to:
$ ./sqlplus
dyld: Library not loaded: /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib
Referenced from: /Users/clucas/apps/instantclient_11_2/./sqlplus
Reason: image not found
Trace/BPT trap: 5
This error can be fixed using one of the following methods:
  1. Move all the executables and supporting library files to locations which are searched by default (/usr/lib and /usr/bin.)  See this stackoverflow answer.
  2. Set your DYLD_LIBRARY_PATH environment variable so that the sqlplus executable can find required oracle libraries and so that those libraries can also find their dependencies.
Both of these will work, but I didn’t really like them because (1) I’m not a fan of installing (and having to remember how to clean up) various files into /usr/* and (2) DYLD_LIBRARY_PATH can affect everything else you run.
You can use otool to see the library locations embedded in the executables and libraries. Ex:
$ otool -L sqlplus
sqlplus:
/ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib (compatibility version 0.0.0, current version 0.0.0)
/ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 (compatibility version 0.0.0, current version 0.0.0)
/ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
I assume those /ade/… paths are from the machine oracle used for building the instant client software.  We can replace these with @executable_path in order to have the dynamic loader find the libraries in the same directory where the executable is found. We want to end up with something like:
$ otool -L sqlplus
sqlplus:
@executable_path/libsqlplus.dylib (compatibility version 0.0.0, current version 0.0.0)
@executable_path/libclntsh.dylib.11.1 (compatibility version 0.0.0, current version 0.0.0)
@executable_path/libnnz11.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
Assuming you also adjust the libraries in the same directory, you’ll be able to run sqlplus just by having it in your PATH.  You can run the following script in the directory where sqlplus is located.  It will change all of the oracle dynamic library references to use @executable_path instead of the /ade/… full path:
#!/bin/sh
# script to change the dynamic lib paths and ids for oracle instant client
# exes and libs

# proces all the executable files in this directory
find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print | while read exe
do
    echo adjusting executable $exe
    baseexe=`basename $exe`
    otool -L $exe | awk '/oracle/ {print $1}' | while read lib
    do
        echo adjusting lib $lib
        baselib=`basename $lib`
        if [ "$baseexe" = "$baselib" ]
        then
            echo changing id to $baselib for $exe
            install_name_tool -id $baselib $exe
        else
            echo changing path id for $lib in $exe
            install_name_tool -change $lib @executable_path/$baselib $exe
        fi
    done
done
Once the script is run and it changes the libs and executables, you can just add the directory holding sqlplus to your path and run sqlplus. No need to set any other oracle environment variables like ORACLE_HOME. Here’s the whole thing:
$ mkdir example
$ cd example
/Users/clucas/apps/example
$ unzip ~/dl/instantclient-basiclite-macos.x64-11.2.0.3.0.zip 
Archive:  /Users/clucas/dl/instantclient-basiclite-macos.x64-11.2.0.3.0.zip
  inflating: instantclient_11_2/BASIC_LITE_README  
  inflating: instantclient_11_2/adrci  
  inflating: instantclient_11_2/genezi  
  inflating: instantclient_11_2/libclntsh.dylib.11.1  
  inflating: instantclient_11_2/libnnz11.dylib  
  inflating: instantclient_11_2/libocci.dylib.11.1  
  inflating: instantclient_11_2/libociicus.dylib  
  inflating: instantclient_11_2/libocijdbc11.dylib  
  inflating: instantclient_11_2/ojdbc5.jar  
  inflating: instantclient_11_2/ojdbc6.jar  
  inflating: instantclient_11_2/uidrvci  
  inflating: instantclient_11_2/xstreams.jar  
$ unzip ~/dl/instantclient-sqlplus-macos.x64-11.2.0.3.0.zip 
Archive:  /Users/clucas/dl/instantclient-sqlplus-macos.x64-11.2.0.3.0.zip
  inflating: instantclient_11_2/SQLPLUS_README  
  inflating: instantclient_11_2/glogin.sql  
  inflating: instantclient_11_2/libsqlplus.dylib  
  inflating: instantclient_11_2/libsqlplusic.dylib  
  inflating: instantclient_11_2/sqlplus  
$ export PATH=$PATH:~/apps/example/instantclient_11_2
$ sqlplus 
dyld: Library not loaded: /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib
  Referenced from: /Users/clucas/apps/example/instantclient_11_2/sqlplus
  Reason: image not found
Trace/BPT trap: 5
$ cd instantclient_11_2/
/Users/clucas/apps/example/instantclient_11_2
$ changeOracleLibs.sh 
adjusting executable ./adrci
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./adrci
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./adrci
adjusting executable ./genezi
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./genezi
adjusting executable ./libclntsh.dylib.11.1
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing id to libclntsh.dylib.11.1 for ./libclntsh.dylib.11.1
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./libclntsh.dylib.11.1
adjusting executable ./libnnz11.dylib
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing id to libnnz11.dylib for ./libnnz11.dylib
adjusting executable ./libocci.dylib.11.1
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libocci.dylib.11.1
changing id to libocci.dylib.11.1 for ./libocci.dylib.11.1
adjusting executable ./libociicus.dylib
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./libociicus.dylib
adjusting executable ./libocijdbc11.dylib
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./libocijdbc11.dylib
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./libocijdbc11.dylib
adjusting executable ./libsqlplus.dylib
adjusting lib /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib
changing id to libsqlplus.dylib for ./libsqlplus.dylib
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./libsqlplus.dylib
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./libsqlplus.dylib
adjusting executable ./libsqlplusic.dylib
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./libsqlplusic.dylib
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./libsqlplusic.dylib
adjusting executable ./sqlplus
adjusting lib /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib
changing path id for /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib in ./sqlplus
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./sqlplus
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./sqlplus
adjusting executable ./uidrvci
adjusting lib /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1
changing path id for /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 in ./uidrvci
adjusting lib /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib
changing path id for /ade/b/2649109290/oracle/ldap/lib/libnnz11.dylib in ./uidrvci
$ sqlplus

SQL*Plus: Release 11.2.0.3.0 Production on Sun Mar 3 22:38:28 2013

Copyright (c) 1982, 2012, Oracle.  All rights reserved.

Enter user-name: ^C
$ cd ..
$ sqlplus

SQL*Plus: Release 11.2.0.3.0 Production on Sun Mar 3 22:38:40 2013

Copyright (c) 1982, 2012, Oracle.  All rights reserved.

Enter user-name: ^C

Wednesday, May 22, 2013

Updating GNU packages in Mac OS X

The Mac OS X 10.7.5 (Lion) may not have the latest version of the GNU tools like bash, sed, etc. However, they can be updated by downloading the source and compiling them on Mac.

The first step is to download the command_line_tools_for_xcode_4.5_os_x_lion.dmg and install it on your Mac OS X. Login here: Developer's Login.  After that, you can update the following:

1. The bash from 3.2 to 4.2.
    1.1. Download source here: bash-4.2.tar
    1.2. Untar and open a terminal
    1.3. Compile and install using: ./configure; make; make install

2. The sed from 3.2 to 4.2.
    2.1. Download source here: sed-4.2.2.tar
    2.2. Untar and open a terminal
    2.3. Compile and install using: ./configure; make; make install


Friday, February 22, 2013

RSA Client Failed - Error loading desktop client?

Source: https://community.emc.com/message/634487 

RSA Client Failed - Error loading desktop client?
SecurID.exe is trying to load desktopclient.dll, which is depending upon QtGui4.dll, which by itself is depending upon QtCore4.dll, both usually installed in C:\Program Files (x86)\RSA SecurID Token Common (on a 64-bit Windows). Under certain circumstances (don't know exactly when and why) another copy of QtCore4.dll might get installed in C:\Windows\SysWOW64, which is missing one entry point (in my case there was a version 4.8, copyright by Nokia, but SecurID.exe build 4.1.1.836 is using version 4.4 of this library). Obviously there is a bug in desktopclient.dll causing the attempt to load the version in SysWOW64 instead the one in its own Common directory, which causes the client to fail...

But the good news, I found a work around:

Copy QtCore4.dll from C:\Program Files (x86)\RSA SecurID Token Common into C:\Program Files (x86)\RSA SecurID Software Token and voila, SecurID.exe runs perfectly fine.

Please RSA/EMC dev guys, fix this issue. Actually, there is a flag in LoadLibraryEx called LOAD_WITH_ALTERED_SEARCH_PATH… You might want to read this article, too: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx ;-)