Overview

September 10, 2009

Here you will find information on building a variety of software packages I find useful in my work on linux (both 64 and 32 bit systems) and OS X. This post serves as a useful entry point to the site for those who found there way here. The “Platforms” tab above has information on how I set up different platforms before installing the various packages.


Apple’s Xcode and std::getline

April 20, 2010

Anyone writing C++ code will want to read in a file and do something with the data contained within. That is usually simple:

#include <iostream>
#include <fstream>
using namespace std;
int main () {
	ifstream readfile("example.txt", ifstream::in);
	string line;
	if(!in.is_open()){
		cerr << "File not found!" << endl;
	} 	else {
	 	getline(readfile,line);
		cout << line << endl;
	}
	readfile.close();
	return 0;
}

For some reason that no one seems to comprehend Xcode sets preprocessor flags which are inconsistent with the standard libraries it ships with. Specifically:

_GLIBCXX_DEBUG=1
_GLIBCXX_DEBUG_PEDANTIC=1

Fortunately this can be easily fixed on a per-project basis by removing the offending lines from Project>>Edit Active Target “…”>>Preprocessor Macros. The easiest way to find it is to search for ‘preprocessor’ in the Active Target configuration. It should look something like the image below when done.

A more pervasive and lasting solution is to edit the project templates in ‘/Developer/Library/Xcode/Project Templates.’ You can find exactly which template are offending using the following command:

find '/Developer/Library/Xcode/Project Templates' -name "project.pbxproj" -exec grep -l "_GLIBCXX_DEBUG=1" \{\} \;

You will want to remove the two offending definitions in code that resembles that below:

GCC_PREPROCESSOR_DEFINITIONS = (
	"_GLIBCXX_DEBUG=1",
	"_GLIBCXX_DEBUG_PEDANTIC=1",
);

Hope this saves others time.


Blocking Ads via hosts file

November 30, 2009

I finally got fed up with all the annoying flash ads slowing down every site I browse and decided to do something about it. I am on a Mac and strongly prefer Safari to Firefox which has its own solution (AdBlock) which means there is no simple download solution. Plus if you use multiple browsers then you will have to find multiple solution UNLESS you black list all the bad guys. Fortunately, the folks at MVPS have done all the hard work for us by creating a list of the bad guys.

There are a few problems with their ready made file for use with a non-Windows machine: First, it has the MS carriage return. Second, it uses 127.0.0.1 (localhost) instead of nothing (0.0.0.0) meaning each request gets routed to you so if you do have a web server running it might be odd. So I wrote a short script which downloads and reformats the file.

#!/bin/sh
origloc="${HOME}/tmp/hosts.original"
blacklist="http://www.mvps.org/winhelp2002/hosts.txt"
#blacklist="http://someonewhocares.org/hosts/zero/hosts"
bltmp="${HOME}/tmp/hosts.txt"
if [ ! -f ~/tmp/hosts.original ]; then
cp /etc/hosts ${origloc}
fi
cd ~/tmp && /usr/bin/curl -o ${bltmp} ${blacklist} && /bin/cat ${origloc} > ~/tmp/hosts && /usr/bin/sed -e 's/127\.0\.0\.1 localhost//' -e 's/^127\.0\.0\.1/0.0.0.0/g' ${bltmp} | /usr/bin/tr -d '\r' | /usr/bin/grep -v "^#" | /usr/bin/grep '0\.0\.0\.0' >> ~/tmp/hosts && sudo /bin/mv ~/tmp/hosts /etc/
sudo /usr/bin/dscacheutil -flushcache

This script will copy the original /etc/hosts to ~/tmp/hosts.original so if you experience a problem then it MAY still be there. I would suggest making a copy of /etc/hosts in a more constant location and pointing this script to there so it can be run just as an update.
The last line is for Mac OS X only, the other line is a monstrosity which only proceeds to the next step if successful in the previous. This script should ask you for your password since it is overwriting an important system file (/etc/hosts). For some reason the WordPress formating for code doesn’t properly treat whitespace so you may have to add it back into the if statement. Disclaimer: I provide no warranty whatsoever for the above script.
UPDATE 2009-11-30: Another site offering a well maintained hosts file is someonewhocares.org, they have multiple different files available using localhost(127.0.0.1) and nothing (0.0.0.0). The script has been updated to allow for easy changing of input file.


Momentum Scrolling on OS X 10.5.8

November 12, 2009

If you have a new Apple Magic Mouse on OS X 10.5.8 momentum scrolling is not available by default but can be trivially enabled. Simply open a Terminal (Applications>>Utilities>>Terminal) and enter the following line:

defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseMomentumScroll -bool true

All in one line and hit return. That is it.

Momentum scrolling is what is used in the iPod/iPhone interface when scrolling: when you scroll and contact is lost the scrolling continues with the momentum of your scroll as contact was lost. This is very handy when scrolling through many lines.

You can find more information on the Magic Mouse at Apple’s site.


S/MIME Certificates in OS X

October 9, 2009

S/MIME Certificates are a great way to make sure people know when email is actually from you and let them easily encrypt email they send to you. Finding a free certificate authority which is included in most browser and OS list of validated root certificates, however, can be difficult. I found two: Thawte and StartSSL both are discussed below.

Thawte’s “Personal E-mail Certificates” site. While still operational now (October, 2009) it will stop validating certificates in November 2009. Since this option has effectively disappeared I searched around for an alternative and found “StartSSL.” This post will cover how to open an account at StartSSL, validate an email address, request a certificate, and get Apple Mail to use that certificate.

OS X support of S/MIME certificates is great. Properly setup sites can give OS X new certificates which are added virtually by default to the correct email account and will thus be used to sign/encrypt email as needed. One such site was Thawte’s, unfortunately StartSSL makes this process MUCH more difficult.

First things first what do you need to get started. On OS X you need two browsers, yup stupid I know but it makes things easier in the long run. For some reason I cannot fathom, StartSSL’s site does not load properly in Safari the first time you try, that is if you click here with Safari and it behaves like mine then you can’t actually complete a request for an account because the drop down boxes do not work.

StartSSL Main

Open up the StartSSL main page in Firefox since it doesn't work in Safari.


Head over to StartSSL’s site using Firefox and you should see something like the above image. Click on the icon labeled “Express-Lane.” This should take you to the following page which I couldn’t get to work in Safari. Fill in the information requested as in the example image below.
StartSSL Account Creation

Fill in the information requested making sure to get the email correct since this is needed to proceed.


When you click “Continue” there is no user feedback for some time (the page does not change, nothing. really rather unprofessional.) However, you should receive an email in the address you provided shortly. Once you get that email the page should have updated to a page requesting the Validation number given in the email. Enter it and click Continue.

The next page should be for generating a private key. Select “High Grade” and click continue, it will generate a certificate and then offer to install the new certificate in your browser. Click “Install.” Firefox will tell you it is installed and you should back it up (which you should and will need to do.) The next page will ask you for a Domain you want to validate. You can ignore this page or go through it if you know what you are doing.

Firefox Certificate Backup

Backup certificate to secure location using a difficult password.


Next you need to back up the private key. In the Firefox Menu Bar goto Firefox>>Preferences>>Advanced>>Encryption and click on the “View Certificates” button (the correct page looks like the one in the image above.). This will bring up a new window with a few tabs, go to the “Your Certificates” tab and select the Certificate labeled “StartCom Ltd.” or “StartCom Free Certificate Member” and click the “Backup…” button. Save this to a file you can find with a password you can remember and keep it in a safe place, it is important to back up and will be needed below.

Wherever you saved the Certificate back up, click on it in Finder; this will attempt to import the key into your keychain. I suggest adding it to the default keychain “login” which is unlocked when you log into the computer. If you want to be extra safe add it to a different keychain with a different password.

Enter the email address used to create the account here.

Enter the email address used to create the account here.

Find the certificate in the keychain you saved it to and right click on it, select “New Identity Preference…” (see picture above) this brings up a small dialog with a text box, enter the email address you used to create the account into this box. This should be all you need to get up and running with a single email account capable of using S/MIME signing and encryption. If you want to make things a little easier you can also select the key associated with the Certificate and add “Mail” (and or “Safari”) to the list of “Always allow access by these applications” list.

If you want to use Safari to add more email addresses to your StartSSL account you can do so by going to their site and clicking “Authenticate” you should be presented with a list of available certificates from your Keychain, select the StartCom certificate and continue (allowing access to the keychain if needed). Go to your “Control Panel”, which should look like the page below, and follow the directions for validating and creating Certificates for any other email addresses you may want to use with this account.

Adding more email addresses

Adding more email addresses

Once you have created a Certificate it should be downloaded to your machine and you can add it to your Keychain in the same manner as with the first one described above. Remember to set the “New Identity Preference.”

And that is it.


healpy

October 2, 2009

Healpy is a great way to make and display healpix maps. If you have need of an equal area sky projection and want to use python this is where to start.

Installation is pretty simple for all platforms I have installed it on:

python setup.py install --prefix=$EXTDIR

Direct dependencies:
python
numpy
matplotlib
pyfits


pyminuit2

October 2, 2009

Pyminuit2 is a python interface to the Minuit2 package which comes with ROOT. It can be installed without ROOT but requires that the user install the stand alone Minuit2 package. Here I assume you have followed the installation procedure for ROOT found here.

Pyminuit is very easy to use and appears to converge much faster than scipy.optimize.fmin which is the other option for minimizing functions in my setup. You can get more information on the setup here.

Installation of pyminuit2 is very simple. Obtain the code via an svn checkout:

svn checkout http://pyminuit2.googlecode.com/svn/trunk/ pyminuit2-read-only

or download the latest tagged release from the google code site. The svn checkout seems to the preferred method right now and that is what I used. It only has 15 revisions so the code is stable and seems to have no issues. After obtaining the code enter the directory with the contents (if you checked out with the svn checkout command above it would be just “pyminuit2-read-only”) and attempt a build:

python setup.py build_ext --inplace

Then enter the build directory (“buid”) and some of the examples listed here near the bottom of the page. If those work and you don’t get any errors then your system should be good to go. Next just install the egg from inside the “pyminuit2-read-only” directory:

python setup.py install --prefix=$EXTDIR

Direct dependencies:
python
ROOT


CUPS on OS X

September 30, 2009

So I am visiting some colleagues who have a CUPS server and insist that it is “Apple crap” and should work with my Macbook; but it doesn’t. So I have to add the printer using the hardware driver which annoys my colleague since he doesn’t want users messing up the hardware (understandably). Since I just wanted to print I just do it anyway and print the paper I wanted.

That was yesterday, since I don’t like annoying people I figure I will see what the net has to say about it. Turns out that by default OS X 10.5 doesn’t look for CUPS shared printers because CUPS has been replaced with Bonjour sharing. But it is extremely easy to turn on; In a terminal window enter the following:

sudo cupsctl BrowseProtocols='"cups dnssd"'

This command tells the printer browser to look for dnssd(Bonjour) AND cups shared printers (sudo is needed since you are editing configuration files with this command so care should be taken). Then you have to wait for a bit as CUPS servers only send information periodically. Voila, you should see all the printers shared in the “Default” tab of the add printer settings.

If you want to revert back to the original Bonjour ONLY browsing then run the command:

sudo cupsctl BrowseProtocols='"dnssd"'

Apple has a little info on this on their website but it doesn’t really advertise that it works with many linux/unix systems.
Link


Word of warning

September 10, 2009

It appears that WordPress has some issues where two “-” symbols (often used a prefix for larger than single character flags in programs) is rendered as a single “-” instead of two. As such a few of the block quoted sections will not work when copied then pasted into a command line. The truly nefarious aspect of this is that it often looks right but just doesn’t work. In the end the only option is to retype all the “-” symbols. Sorry!


CRPropa

December 3, 2008

CRPropa is a numerical framework developped mostly at the APC, and whose goal is to simulate the propagation of UHECRs and their secondaries on large distances.”

First follow setup directions here. You will need to have the following installed: ROOT and CLHEP.

  1. Get source and unpack it.
  2. Configure: $ ./configure –prefix=$EXTDIR -with-cfitsio-include=$EXTDIR/include –with-cfitsio-library=$EXTDIR/lib –with-root=$ROOTSYS
  3. Make: $ make -j2
  4. Test: $ make check
  5. Install: $ make install

Here is a block quote version for easier cut/pasting:

./configure --prefix=$EXTDIR -with-cfitsio-include=$EXTDIR/include --with-cfitsio-library=$EXTDIR/lib --with-root=$ROOTSYS
make -j 2
make check
make install

Direct dependencies:
ROOT
CLHEP


Follow

Get every new post delivered to your Inbox.