Wednesday, April 10, 2013

git autocomplete on Mac OS X

I use a variety both Linux and OSX in my work. Since my recent adoption of git, I have been mostly logged in to our Linux box and had been enjoying the awesome git autocomplete features in bash. When I switched to my Mac though, I couldn't get this work - but my pinky refused to stop pressing the tab key.

Luckily, the folks at git have an autocomplete script ready to install on your machine. Here's what you have to do:
curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bash_profile

and Voila!

Thanks to Mike Pottyn for this: http://railslove.com/blog/2011/11/25/git-autocomplete-in-bash-on-a-mac

Cite as:
Saad, T. "git autocomplete on Mac OS X". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2013/04/git-autocomplete-on-mac-os-x.html

Thursday, January 31, 2013

Monday, September 17, 2012

XCode 4 Build Locations (Lion, Mountain Lion)

Apparently, the "most advanced" operating system in the world is not very friendly for power-users and developers.

The new xcode 4 has had a major rehaul. I just updated to mountain lion and the latest xcode (4.4.1). The first annoying feature that you will notice about xcode is the non-intuitive and complex user interface. I can't even find the console or the debugging tools... oh wait, they're placed at the bottom of the screen and they're practically invisible. Maybe it is time to read the documentation... but who has time for that?

In any event, I went ahead and tested a "Bonjour y'all!" code and it worked. but I could not locate the executable file in the project's directory. Are you serious? It turns out that XCode defaults to some location in your library. Fortunately, I just found a way to go back to standard operation and place your executable where it BELONGS:

  1. Open XCODE
  2. go to: Preferences
  3. Click on the "Locations" tab
  4. Change the path for "Derived Data" to relative and that should do it.
  5. If you want to be a bit more picky, click on Advanced
    1. select "Custom"
      1. Select "Relative to Workspace"
That last step will place your executable in its normal location.

Hope that helps.

Cite as:
Saad, T. "XCode 4 Build Locations (Lion, Mountain Lion)". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2012/09/xcode-4-build-locations-lion-mountain.html

Friday, September 14, 2012

Calling gnuplot from C/C++ on Mac OS X

Here's another way of calling gnuplot from Mac OS X.

First install gnuplot either from their website or using macports. I like the macports model because it installs all dependencies for you automatically.
  1. Install macports from: http://www.macports.org/ 
  2. Open up your terminal
  3. type: sudo port selfupdate (to update port names)
  4. type: sudo port install gnuplot
and Voila! you now have gnuplot installed on your mac. To test it type: gnuplot and you should enter the gnuplot environment. Another caveat that you have to bear in mind when using gnuplot on mac is that you have to tell gnuplot to use x11. You do this as follows:
  1. Open up your terminal
  2. type: gnuplot
  3. type: set terminal x11
Now to the fun stuff. Here's the code that I used before to call gnuplot for windows, but modified to work on Unix based systems such as Mac.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void plotResults(double* xData, double* yData, int dataSize);
int main() {
  int i = 0;
  int nIntervals = 100;
  double intervalSize = 1.0;
  double stepSize = intervalSize/nIntervals;
  double* xData = (double*) malloc((nIntervals+1)*sizeof(double));
  double* yData = (double*) malloc((nIntervals+1)*sizeof(double));
  xData[0] = 0.0;
  double x0 = 0.0;
  for (i = 0; i < nIntervals; i++) {
      x0 = xData[i];
      xData[i+1] = x0 + stepSize;
  }
  for (i = 0; i <= nIntervals; i++) {
      x0 = xData[i];
      yData[i] = sin(x0)*cos(10*x0);
  }
  plotResults(xData,yData,nIntervals);
  return 0;
}
void plotResults(double* xData, double* yData, int dataSize) {
  FILE *gnuplotPipe,*tempDataFile;
  char *tempDataFileName;
  double x,y;
  int i;
  tempDataFileName = "tempData";
  gnuplotPipe = popen("gnuplot","w");
  if (gnuplotPipe) {
      fprintf(gnuplotPipe,"plot \"%s\" with lines\n",tempDataFileName);
      fflush(gnuplotPipe);
      tempDataFile = fopen(tempDataFileName,"w");
      for (i=0; i <= dataSize; i++) {
          x = xData[i];
          y = yData[i];            
          fprintf(tempDataFile,"%lf %lf\n",x,y);        
      }        
      fclose(tempDataFile);        
      printf("press enter to continue...");        
      getchar();        
      remove(tempDataFileName);        
      fprintf(gnuplotPipe,"exit \n");    
  } else {        
      printf("gnuplot not found...");    
  }
} 


This code should run as is. Of course, feel free to take the plot function and use it in your own codes.

Cite as:
Saad, T. "Calling gnuplot from C/C++ on Mac OS X". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2012/09/calling-gnuplot-from-cc-on-mac-os-x.html

Thursday, June 23, 2011

The Maximum Entropy Method for Reconstructing Density Distriubtions

A summary of using the maximum entropy principle from information theory to reconstruct a PDF (or other distributions) given a finite number of moments. This is quite useful especially when using the method of moments in population balances or related stochastic transport processes. The document also includes some results from my code for reconstructing some bimodal and trimodal Gaussian distributions, beta, and log-normal distributions.

Download PDF

Cite as:
Saad, T. "The Maximum Entropy Method for Reconstructing Density Distriubtions". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2011/06/maximum-entropy-method-for.html