HOWTO Install MongoDB for PHP on Mac OS X

15 Aug, 2011 — Apple, HOWTO

MongoDB is a document-oriented database (among other things), and it’s especially convenient that the native document format is JSON. For various ongoing pet projects, I figured I’d give it a try to avoid the overhead of creating/maintaining schemas and having to flatten down my JSON objects to fit a relational model.

These instructions work for 10.7 Lion, 10.6 Snow Leopard and 10.5 Leopard. The steps outlined here ensure that your MongoDB installation integrates well with the rest of the system (Apache, PHP & launchd), is started automatically when the machine starts up, and makes it easy to upgrade later.

I read a lot of conflicting instructions on the Web about how to install MongoDB, and they’re either incomplete (most of them skip the part about making MongoDB run automatically at startup), and none of them satisfied the following requirements I had:

  • I should not need to install any software that’s already present on a stock Mac OS X installation (Lion, Snow Leopard or Leopard, at the very least.)
  • It should be relatively easy to upgrade the base version of MongoDB, so installing it via a package manager would be preferable to installing it from source.
  • The MongoDB server should be started up automatically through system-standard tools such as launchd — not manually every time I need to test something.

This tutorial assumes a virgin Mac OS X installation. If you already have a component installed, simply skip that step.

  1. Install XCode from the Mac App Store. It’s needed for MacPorts.

  2. Install MacPorts from macports.org. MacPorts is a package manager for Mac OS X that makes it easy to install and configure a lot of open-source software.

    Although MongoDB binaries are available from the MongoDB web site, I strongly recommend using the MacPorts MongoDB port. MacPorts ensures dependencies are installed correctly, and provides an easy way to upgrade all outdated packages at once.

Install and configure MongoDB


  1. Install MongoDB. Open a Terminal, ensure you’re using an account with Administrator privileges, and type:

          sudo port install mongodb

    That’s it, MongoDB is now installed. But there’s lots more to do to get it working.

  2. Create directories required by MongoDB.

          # The data directory.
          sudo mkdir -p /var/lib/mongodb/
    
          # The logs directory.
          sudo mkdir -p /var/log/mongodb/
  3. Create a config file. Put this in a new file at /etc/mongodb.conf:
          # This is an example config file for MongoDB.
          # Place it at /etc/mongodb.conf
          # Based on a sample provided at
          # http://www.mongodb.org/display/DOCS/File+Based+Configuration
          dbpath = /var/lib/mongodb
          bind_ip = 127.0.0.1
          noauth = true
  4. Configure a launchd LaunchDaemon. Put this in a new file at /Library/LaunchDaemons/org.mongo.mongod.plist.

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
            "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
          <plist version="1.0">
          <dict>
            <key>Label</key>
            <string>org.mongodb.mongod</string>
            <key>ProgramArguments</key>
            <array>
              <string>/opt/local/bin/mongod</string>
              <string>run</string>
              <string>--config</string>
              <string>/etc/mongodb.conf</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
            <key>KeepAlive</key>
            <true/>
            <key>WorkingDirectory</key>
            <string>/var/log/mongodb/</string>
            <key>StandardErrorPath</key>
            <string>/var/log/mongodb/output.log</string>
            <key>StandardOutPath</key>
            <string>/var/log/mongodb/output.log</string>
          </dict>
          </plist>
  5. Start MongoDB via launchd. Type in a Terminal window:

          sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist

You can stop reading now if all you need is MongoDB and don’t plan to use PHP with it. The MongoDB server will be automatically launched at startup.

Enable Apache and PHP5

  1. Start Apache. In System Preferences, go to Sharing, and then check the box next to “Web Sharing”.


  2. Enable PHP5 support in Apache. Open the Apache config file, /etc/apache2/httpd.conf, and locate the following line.

          # LoadModule php5_module

    Uncomment that line, so it reads:

          LoadModule php5_module
        
  3. Restart Apache. Type in a Terminal window:

          sudo apachectl graceful
        
  4. Test if PHP is working correctly. Create a new PHP file at /Library/WebServer/Documents/phpinfo.php and put in it:

          <?php
            phpinfo();
          ?>

    Browse to http://localhost/phpinfo.php, and you should see a long page showing your PHP configuration.

    Apache and PHP5 are now configured.

Install and Configure the PHP5 MongoDB driver.

  1. Install PEAR. PEAR is the PHP Extension and Application Repository, from which we’ll install the PHP5 MongoDB driver.

          $ cd /tmp
          $ wget http://pear.php.net/go-pear.phar
          $ sudo php -d detect_unicode=0 go-pear.phar

    You’ll be prompted with a default file layout. I changed this to install it in /usr/local/pear instead of under /Users/Admin.

          Below is a suggested file layout for your new PEAR installation.  To
          change individual locations, type the number in front of the
          directory.  Type 'all' to change all of them or simply press Enter to
          accept these locations.
    
           1. Installation base ($prefix)                   : /Users/Admin/pear
           2. Temporary directory for processing            : /tmp/pear/install
           3. Temporary directory for downloads             : /tmp/pear/install
           4. Binaries directory                            : /Users/Admin/pear/bin
           5. PHP code directory ($php_dir)                 : /Users/Admin/pear/share/pear
           6. Documentation directory                       : /Users/Admin/pear/docs
           7. Data directory                                : /Users/Admin/pear/data
           8. User-modifiable configuration files directory : /Users/Admin/pear/cfg
           9. Public Web Files directory                    : /Users/Admin/pear/www
          10. Tests directory                               : /Users/Admin/pear/tests
          11. Name of configuration file                    : /Users/Admin/.pearrc
    
          1-11, 'all' or Enter to continue:

    At this prompt, type 1

          (Use $prefix as a shortcut for '/Users/Admin/pear', etc.)
          Installation base ($prefix) [/Users/Admin/pear] :

    At this prompt, type /usr/local/pear

          Below is a suggested file layout for your new PEAR installation.  To
          change individual locations, type the number in front of the
          directory.  Type 'all' to change all of them or simply press Enter to
          accept these locations.
    
           1. Installation base ($prefix)                   : /usr/local/pear
           2. Temporary directory for processing            : /tmp/pear/install
           3. Temporary directory for downloads             : /tmp/pear/install
           4. Binaries directory                            : /usr/local/pear/bin
           5. PHP code directory ($php_dir)                 : /usr/local/pear/share/pear
           6. Documentation directory                       : /usr/local/pear/docs
           7. Data directory                                : /usr/local/pear/data
           8. User-modifiable configuration files directory : /usr/local/pear/cfg
           9. Public Web Files directory                    : /usr/local/pear/www
          10. Tests directory                               : /usr/local/pear/tests
          11. Name of configuration file                    : /Users/Admin/.pearrc
    
          1-11, 'all' or Enter to continue:

    At this prompt, type 11

          (Use $prefix as a shortcut for '/usr/local/pear', etc.)
          Name of configuration file [/Users/Admin/.pearrc] :

    At this prompt, type /etc/pearrc

          Below is a suggested file layout for your new PEAR installation.  To
          change individual locations, type the number in front of the
          directory.  Type 'all' to change all of them or simply press Enter to
          accept these locations.
    
           1. Installation base ($prefix)                   : /usr/local/pear
           2. Temporary directory for processing            : /tmp/pear/install
           3. Temporary directory for downloads             : /tmp/pear/install
           4. Binaries directory                            : /usr/local/pear/bin
           5. PHP code directory ($php_dir)                 : /usr/local/pear/share/pear
           6. Documentation directory                       : /usr/local/pear/docs
           7. Data directory                                : /usr/local/pear/data
           8. User-modifiable configuration files directory : /usr/local/pear/cfg
           9. Public Web Files directory                    : /usr/local/pear/www
          10. Tests directory                               : /usr/local/pear/tests
          11. Name of configuration file                    : /etc/pearrc
    
          1-11, 'all' or Enter to continue:

    At this prompt, type <Enter>

          Would you like to alter php.ini </private/etc/php.ini>? [Y/n] :

    At this prompt, type Y.

  2. Install the PHP MongoDB driver.

          sudo /usr/local/pear/bin/pecl install mongo
  3. Configure the system PHP to load that extension. Add this line to your php.ini. (If you don’t know where your php.ini file is located, go back to the phpinfo page that you created earlier, and you’ll find it on that page.)

          extension=mongo.so
  4. Restart Apache. To enable PHP5 with MongoDB support, restart Apache.

          sudo apachectl graceful

Test your installation.

  1. Create a simple test script. Create a PHP file at /Library/WebServer/Documents/mongodb.php

          <?php
            $mongoDB = new Mongo();
            $database = $mongoDB->selectDB("example");
            $collection = $database->createCollection('TestCollection');
            $collection->insert(array(test => 'Test OK'));
    
            $retrieved = $collection->find();
            foreach ($retrieved as $obj) {
              echo($obj['test']);
            }
          ?>
  2. Test the installation. Browse to http://localhost/mongodb.php. If you see the following output, then congratulations, MongoDB is properly installed and configured to work with PHP on your Mac. Happy developing!

          Test OK

If this worked well for you, or if it doesn’t work for your specific configuration, please let me know via the comments, and perhaps we can troubleshoot.

HOWTO Use custom DNS redirects to save browser keystrokes

Given the recent interest in DNS and its role in the public infrastructure of the Internet, sparked by the release of Google Public DNS, here’s a hack that can help you save keystrokes in the browser while accessing your favorite sites. Instead of typing in “youtube.com” or “twitter.com”, you can just type “y” or “t”. If you’re looking for a map of San Francisco, CA, you can type “map/sf” and jump to the right place in Google Maps.

A bright bold blinking marquee disclaimer before we start: this is advanced territory. If you don’t know what sudo is and why 127.0.0.1 is special, be careful following these instructions because you may unintentionally destroy your ability to do anything at all on the Internet — including looking up instructions for getting unstuck. Also, these instructions only apply to Mac OS X and Linux, or other UNIX variants.

Redirect custom DNS hostnames to frequently-accessed sites

The file /etc/hosts on your machine is consulted by the DNS resolver before making a request to a DNS server. The idea is to add new DNS entries to the hosts file on your machine, pointing short domains such as g and t to 127.0.0.1. Now, whenever you type g or t into your browser, the hostname will be matched from your /etc/hosts file, instead of receiving an NXDOMAIN reply (i.e., this domain does not exist) from an upstream DNS provider. Since this request is received by your own machine, you can then handle it to do whatever you want, including, but not limited to, redirecting the user to the intended destination.

This HOWTO assumes that Apache is installed and running on your system with PHP and mod_rewrite support.

Modify /etc/hosts

Open /etc/hosts in your favorite text editor, and add one line for each shortcut you’d like to set up. Leave everything else unchanged. (You will need to sudo edit this file.)

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 c # for Calendar
127.0.0.1 f # for Facebook
127.0.0.1 g # for Google Search
127.0.0.1 m # for Mail
127.0.0.1 map # for Maps
127.0.0.1 t # for Twitter
127.0.0.1 w # for Wikipedia
127.0.0.1 y # for Yelp
127.0.0.1 yo # for YouTube

255.255.255.255	broadcasthost
::1             localhost
fe80::1%lo0	localhost

You can test that this change worked, by typing in the address (e.g. http://g/ in your browser. Instead of seeing a page that says that your browser “can’t find the server ‘g’”, now you would see a page saying that your server isn’t configured correctly, or welcome to Apache, or whatever you would see if you typed http://localhost/ instead. If that worked, proceed.

Configure Apache to handle requests for unknown domains/URIs

Edit the following lines in /etc/apache2/httpd.conf. The following code shows an excerpt with lots of context around the line you need to edit. Locate the relevant section in your file.


#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Library/WebServer/Documents">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options +Indexes +FollowSymLinks +MultiViews

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All # <-- Change this from None to All

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

Locate your Apache root directory. It’s usually /Library/WebServer/Documents on the Mac or /var/www in Ubuntu. If you’re unsure, check where it is by issuing the following command in a terminal: (assuming you’re running Apache 2.x)

grep “DocumentRoot” /etc/apache2/httpd.conf

In that directory, save the following file. It should be named exactly .htaccess. (That’s htaccess with a period at the beginning, so it’s a hidden file on UNIX.) Save it as /Library/WebServer/Documents/.htaccess on Mac OS X or /var/www/.htaccess on Ubuntu.

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

RewriteCond    %{REQUEST_FILENAME} !-f
RewriteCond    %{REQUEST_FILENAME} !-d
RewriteRule    (.*) /index.php [L]

</IfModule>

The actual redirection script

Here’s the script that I use for redirection, but you can roll out your own, and do anything with each request you receive. (If you do something phenomenally awesome, I’d love to hear about it in your comments.) As you can see, it’s customized to the sites I frequent, including location preferences (e.g. the Yelp shortcut takes me to Yelp San Francisco directly. The search box is preconfigured for SF.)

Save this as /Library/WebServer/Documents/index.php (on Mac OS X) or as /var/www/index.php on Ubuntu.

<?php
  $uri = preg_replace('/^\//', '', $_SERVER['REQUEST_URI']);
  switch($_SERVER['SERVER_NAME']) {
    case 'c':
      redir('http://calendar.google.com/');
      break;
    case 'f':
      redir('http://facebook.com/');
      break;
    case 'g':
      redir('http://www.google.com/search?q=' . $uri);
      break;
    case 'm':
      redir('http://mail.google.com/');
      break;
    case 'map':
      redir('http://maps.google.com/?q=' . $uri);
      break;
    case 't':
      redir('http://twitter.com/');
      break;
    case 'w':
      if ('' === $uri) {
        redir('http://en.wikipedia.org/wiki/');
      } else {
        redir('http://en.wikipedia.org/wiki/Special:Search/' . $uri);
      }
      break;
    case 'y':
      if ('' === $uri) {
        redir('http://yelp.com/sf/');
      } else {
        redir('http://yelp.com/search?ns=1&find_loc=San%20Francisco,%20CA&find_desc=' . $uri);
      }
      break;
    case 'yo':
      if ('' === $uri) {
        redir('http://www.youtube.com/');
      } else {
        redir('http://www.youtube.com/results?search_query=' . $uri);
      }
      break;
  }

  function redir($url) {
    header('Location: ' . $url);
  }
?>

That’s it, now type your shortcuts into your browser instead of the longer URLs, and there you are. If you run into trouble, leave a comment and I’ll address it.

The only downside of this approach

Redirecting involves an additional HTTP request to your machine, which introduces additional latency. The request, however, is from your machine to your machine itself, so there’s no network involved. Personally, I feel that the keystrokes saved by the technique would have taken longer to type than the shortcuts I set via this method. But you don’t lose anything if you set this up and don’t use it — just continue to type entire URLs and you will never pay a latency penalty.

On-the-fly CSS Compression in PHP

8 Sep, 2009 — Design & Usability, HOWTO, Release

Web site optimization experts suggest that webmasters try to minimize the number and size of HTTP requests necessary to serve web pages. Web designers often use multiple CSS files because they are easier to manage, but this requires as many HTTP requests as there are CSS files.

This free script serves all your CSS files as a single HTTP resource, minified (by removing comments and extraneous whitespace), and gzip-compressed. It also requests browsers to cache the CSS content for at least a day before trying to fetch a new version.

The best part is that this does not pre-process the files, so it does not add any steps to your deployment process. It’s licensed free for commercial and non-commercial use, with attribution requested.

Grad School 101

29 Aug, 2009 — Academic, HOWTO, Life, Thoughts

This is a collection of tips compiled for a seminar series at Virginia Tech for Computer Science Grad Students in Fall 2008, compiled by Manas Tungare, with contributions from (in alphabetical order) Manuel Pérez-Quiñones, Rhonda Phillips, Pardha Pyla, Naren Ramakrishnan, Bill Schilit, and Andrea Wiggins.

Download Slides

Download PDF

1. Introduction

This document is extremely terse, so you don’t end up spending too much time reading it.

2. Getting Started

2.1. Classes

In your first few semesters of grad school, you will be required to take classes. They provide an opportunity to learn about new areas, and gain some depth in your area of focus. But grad school is not about getting an A in every class. Don’t ignore research in favor of getting good grades.

Be clear about the requirements of your program: you don’t want to discover that you missed taking a required class and have to take it towards the end of your Ph.D.

Quote from a professor (used with permission):

Students need to know what advisors do when writing a letter of recommendation. I get requests to write letters of recommendation, and all I can say is “s/he was in class frequently”. Students need to know this, not just to avoid that awkward moment of asking for a letter of recommendation that might not be the one they want, but also so this might serve as motivation for them to attend class. They can’t be shy. They need to be known by professors. Ask questions. Go to research group meetings. Read their papers, etc.

2.2. Choosing an Advisor

Find an advisor whose research interests closely match yours. This is obvious. What is not obvious is the next part: find an advisor whose work culture and personality match yours. You will be working with this person for the next several years, and if you do not enjoy a great working relationship with your advisor, things might get rough.

How do you find out about an advisor’s personality? Talk to their current students and ask around. You’ll need to read between the lines of such conversations, keeping in mind that because they work with that advisor, (1) they either genuinely love working with him/her or (2) they will not talk ill of him/her for fear of retribution.

Ask around: some advisors graduate students rapidly, while others are seldom around, so their students take longer to graduate. Some advisors will provide for frequent, short interactions (face-to-face, email, etc.); others will require you to have completed a significant amount of work before they agree to meet you in person. Some encourage independent work that is mentored sporadically; others may engage in more frequent collaborations. Hardly any will provide hand-holding-this is grad school.

Faculty members can be roughly classified in two very broad groups: senior versus junior. Junior faculty looking for tenure must publish prolifically, while senior faculty have more experience in the field-both are good qualities that will ultimately help you. Weigh these factors if you ever need to pick between one from each group.

Before entering into a long-term relationship with someone you’re interested in, a good way to figure out if you’re compatible is to … do an “Independent Study” with them. This is a no-commitment research-oriented one-on-one project. It’s OK to double up class projects or follow them up as independent studies – talk to the faculty member involved.

Understand what professors want/need from you: support for the primary area of research they are interested in, and willingness to take that research forward in meaningful ways. Funding for graduate students comes from research grants, and if you help write one, you may get the money that the grant brings in.

Here’s a quote from a faculty member (used with permission):

For example, I often email students things like “Hey, this conference call seems close to your work. What do you think?” A negative work student (which, I might add, I have learned to spot quickly and don’t often want working with me) will often reply “Interesting, do you really think we should publish there?” That is clearly the wrong answer. If I didn’t think we should publish there, then I wouldn’t have forwarded this to the student.

The other extreme student (which is typical of the students that I work with) replies: “Very interesting. I went to their website and looked at a couple of papers from last year. They definitely seem similar to my work. I have taken the liberty of jotting down some notes about possible papers that we could write. Let’s discuss these next time we meet. Thanks for sending it.”

2.3. Mentoring

Your advisor isn’t your only mentor; find a senior student in your program with similar interests (and, if possible, the same advisor) who is willing to give you some sage senior advice and help you avoid a few common pitfalls. Peer mentoring can be truly invaluable. Astronauts and professional athletes aren’t the only role models; find a high-performing person at the next higher rank from you and emulate their behavior.

Quote from a Ph.D. student:

When I was a Master’s student, I tried to adopt the practices of a successful PhD student, and it really paid off. As a PhD student, I try to meet the expectations for junior faculty so I’ll be better prepared for that role.

While a dissertation is a very individual activity, there are patterns that all grad students go through that are similar (that’s why Ph.D. Comics is funny). Cultivate early, a group of peers, including a few more advanced students, that have experienced the ups/downs of doing a Ph.D. This will help you survive the difficult parts and help you celebrate the high points along the way.

3. Research

3.1. Literature Review Basics

Any research project begins with a review of the existing literature in the field (or at least, that’s how it should be.) Be exhaustive while citing sources; do not open yourself up to claims of plagiarism, even if you are honestly pursuing your own research. Look up citations for stuff that seems like it may have been done before. Ask your peers (lab mates, professional colleagues at other institutions) if they are aware of any papers near your area.

Posting specific questions about related work to your social network is a good way to learn about work that might not have been widely cited. Some colleagues might offer you a sneak peak at unpublished work. Respect the confidentiality that is implicit in the sharing of such work.

3.2. Managing Research

Research requires as much management as pure effort. You must be able to manage your time, your resources, your sources, information you collect, information you come across, information you generate, samples of stuff you record from experiment participants, interview transcripts and recordings, videos, log files from computer software, etc. Make sure you store these items safely.

There is software to conduct every kind of research activity: pick the best tool for the job.

Word-processing programs that were once adequate for undergrad-level reports and essays cease to scale up to the demands of academic publishing. Consider LaTeX for academic writing: it is free software available for all major operating system platforms, and will not cause corrupt documents, a common occurrence with proprietary software that reads/writes undocumented binary file formats. The effort required to gain familiarity with LaTeX pays itself back several times over during an academic career.

BibTeX is a tool and file format for managing bibliographies, along with several applications that help manage BibTeX-formatted bibliographies. Keep a single library of bibliographic material starting from Day One. This will save you several hours when collating annotated literature to cite in a paper or article.

3.3. Communication

Do not underestimate the value of communication in research. Not only will you perform research by yourself, but you also will be required to talk about it with your advisor, discuss it to lab-mates, write about it in papers and articles, and present it at conferences.

Get feedback from your colleagues before communicating with a wider audience – many heads are better than one. You will be surprised at what other people will spot in your work that you had somehow managed to overlook. This applies equally to papers, talks, presentations, defenses and everything in between.

4. Conferences

Starting to write early on makes your writing better over time. Make your presence known in your research area: publish interesting stuff, but not for the sake of publishing something. Some call this the `least-publishable unit’ model of publishing and many disagree with it. Submit meaningful, completed works of research to the appropriate conferences and journals.

Be proactive in submitting to conferences: do not wait for your advisor to come across a CFP (`Call for Papers’). Subscribe to announcement lists in your field where a lot of CFPs get posted. Your advisor can help you locate these.

Attend conferences even if you’re not presenting during that particular year. It is important to stay abreast of research in your area. Often you will have to pay your own way to attend a conference in another country; this money is well-spent.

It is said that during conferences, hallways are where the action is, not the session rooms. That is where the networking happens. Meet people from your field: these are the same people whose work you build upon, who will build upon your work, and contribute to the same scholarly community. In addition, some of these may be interviewing you after you’re done, either as faculty search committee members or as industry researchers.

Attend smaller research meetings too: departmental get-togethers and seminars are not a distraction from your regular work, but a part of it. Don’t be left out!

If you’re in your second year or higher, prepare an elevator pitch. Be ready to talk to complete strangers about what you do. Prepare individual spiels for the following sets of audiences: your grandma/grandpa, your friend from high school who is pursuing a degree in fine arts, your friend from undergrad in Computer Science, your lab-mates, people in your research area, and finally, your advisor. These are sorted by increasing levels of awareness of the field and research experience. This means that you can dig into several levels of detail as the need arises (sometimes also known as the pyramid model of communication.)

4.1. Presenting at Conferences

A conference presentation is not a verbatim recitation of your paper. Often, the time available to presenters during a conference session is barely enough to whet the appetite of your audience and entice them to read the entire paper. Do not try to cram every single finding from your paper into the 20-minute talk.

Practice presentations before a crowd of your peers before you go to that big conference. There is no substitute for rehearsing. Do not ever read from your slides. Do not EVER read from your slides. There are numerous tips for how to be a better presenter and public speaker, far too many to include in this document.

4.2. Student Volunteer Opportunities

Check whether conferences of your interest waive registration fees and/or provide additional perks in exchange for volunteer service during the conference. If you feel you are capable, take up service positions and be of assistance to the community at large. Apply to be a Student Volunteer as soon as (or even before) you submit your paper. Often, deadlines for Student Volunteer applications are earlier than paper submission deadlines (though this varies by conference.) If accepted, the conference organizers will pay a significant part of your travel expenses (registration, hotel, etc.)

`SV’-ing also is a great opportunity to meet your peers. These are other students who will one day be your research colleagues, collaborators on grants, paper reviewers, co-authors and life-long friends. Meet them, keep in touch.

But remember that your academics come first; service should not come at the cost of your research output.

5. Internships

Internships offer students a perspective on where their skills might be useful outside of the academic realm. Even if you do not intend to pursue a career in industry, opting instead for an academic career, an internship provides a unique perspective into your own work and how it fits into the research community at large – something that a summer at school would not be able to provide.

Make sure you plan this with your advisor well in advance. Do not spring a surprise on him/her after you receive an offer and rent an apartment. Some advisors may prefer that you not go on an internship, but continue to work on your research so you may graduate earlier. Others encourage their students to pursue internships, while a few others may actively provide you leads for promising internship positions. Most research internships are gained either through your own research reputation, or through your advisor’s professional contacts. Thus, a conversation with your advisor on this topic should be held earlier rather than later.

Researchers from industry often scrutinize their intern candidates at conference presentations and other socio-professional venues. You might even receive a spot offer over a casual conversation with your would-be mentor if they are impressed with your work.

While the internship application process is not as rigorous as that for a full-time position, there are few positions and they’re filled as soon as a candidate with matching skills is found. Apply early. Quote from a Ph.D. student:

Don’t be afraid to pursue opportunities. I was always intimidated when I saw solicitations for fellowship applications, travel funding, student grants, awards, etc, but I learned that it doesn’t hurt to apply, and sometimes you’re more qualified than you think you are.

Some research institutions offer internships that do not involve rigorous research, but instead utilize your prototype-building skills to push their research agenda. If you’re in your early years of the graduate program, these are fine ways to get you the proverbial foot in the door and a deeper insight into that institution’s research program.

While at an internship, do not completely ignore the research you conducted back at school. Advisors will understand that your current time demands must favor your current employer, but a three month hiatus in school research can lead to problems resuming it once you’re back.

6. Networking

Know your community and try and get them to know you.

Solving an important research problem sitting in one’s windowless cubicle is good, but networking with peers at research conferences and other academic venues increases one’s chances of getting a real job.

Most academic networking happens at conferences. Make sure you carry business cards so you can exchange contact info easily if required. Though, quite often, you will end up exchanging cards with your peers – who also just got their cards printed! – you never know when you might meet someone who really would like to get in touch with you. Since most academic positions are filled via word-of-mouth, it’s always good to be easy to contact.

You may be invited to spontaneous group lunches or dinners with newly-made acquaintances, which often lead to excellent conversations to remember for a long time. After all, these are people from your own research field who have all congregated to exchange ideas with one another. (But of course, don’t be pushy or show up uninvited.)

If your advisor, committee members, or senior students are attending, they may introduce you to their acquaintances from other schools/companies.

Many advise removing your social networking profiles, such as Facebook or Twitter profiles. While this advice has some merit if your profile has objectionable content, that is likely not the most common case for this audience. As information grows, one’s social network is a valuable resource to be tapped into for relevant, up-to-date news from your field. Often, such nuggets might be found in your friends’ status updates. After several conferences I’ve been to, attendees have taken the initiative to start online groups to continue the conversation beyond the conference. It is a good idea to participate in these.

There also are networking conferences designed for specific audiences; if you are a woman, consider attending the Grace Hopper Conference. If you belong to a minority group in computer science, consider attending the Richard Tapia Celebration of Diversity in Computing. There are likely be others in your own field as well.

7. Preparing for the Real World

7.1. Tenure Track (Academic Positions)

For an academic position, you will be evaluated on your ability to chart your own research agenda, and pursue it to fruition. This includes coming up with hypotheses, conducting experiments and publishing your results. As the first two steps are opaque to an external observer, you are thus judged primarily based on your publication output. Whether you like it or not, it’s a publish-or-perish world.

Always keep an updated copy of your résumé and CV available online. A CV (curriculum vitae) is a complete record of your relevant accomplishments and forms part of your application dossier for academic positions.

If your university supports student involvement in school governance, become involved in governance committees. This may seem like a distraction from your studies, but it is excellent preparation for a faculty position in which you will be expected to contribute in service roles in addition to research and teaching.

Do as a student what faculty do: writing research grant proposals. You may start off by assisting your advisor in writing sections of their grant proposals that are related to your research. It is often possible to turn your dissertation proposal into a grant proposal. Even though students cannot be officially co-PIs (Principal Investigator) of a grant, the experience you will gain even from being a nameless contributor is priceless.

7.2. Industry Track (Research Laboratory Positions)

Industry values slightly different skills in budding researchers than does academia. Industry often runs on much faster timelines than academic research, especially in terms of bringing products from the laboratory to the mainstream. Thus, in addition to fundamental research, an industry researcher plays an important secondary role in “productizing” research ideas. This involves developing prototypes and working with development teams to implement these on a larger scale.

It is a belief among some graduate students that a career in industry limits one’s freedom in what you may work on. While it is true that an individual researcher’s broad research direction may need to align with the company’s strategic vision, there is often wide scope for researchers to define the specific problems they are interested in working on and pursue those with their team. It is often the case in academic (though lamentable) that choice of research direction is dictated by available funding opportunities.

8. Closing Statements

Take care of yourself first. Paper submissions, assignments and pending work can take their toll on your health if you ignore yourself. Make sure you eat well, on time, and maintain the energy that is the foundation of everything else.

Enjoy your time here. You’re doing this because you love it!

9. Resources

HOWTO Make your Mac speak over the Web

15 Jan, 2009 — Apple, Funny, HOWTO

Randall Munroe’s XKCD has inspired interesting product features in the past. A recent one has sent a lot of Mac users scurrying to set up an audio doorbell on their Mac Minis.

Here’s how you can do it.

The Source Code

<?php
if (isset($_GET['say'])) {
  $cmd = sprintf('say "%s"', preg_replace('/[^\w\d ]/', '', $_GET['say']));
  `$cmd`;

} else if (isset($_GET['up'])) {
  $cmd = 'set output_vol to output volume of (get volume settings)
  set volume output volume (output_vol + 10)';
  `osascript -e "$cmd"`;

} else  if (isset($_GET['down'])) {
  $cmd = 'set output_vol to output volume of (get volume settings)
  set volume output volume (output_vol - 10)';
  `osascript -e "$cmd"`;
}
?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
  <p><input type="text" name="say">
  <input type="submit" value="Say"></p>
  <p>Volume:
  <input type="submit" name="up" value="Up">
  <input type="submit" name="down" value="Down"></p>
</form>
<p>Hey Randall, here's how you
  <a href="http://xkcd.com/530/">change the volume</a>.<br/>
  &ndash;<a href="http://manas.tungare.name/">Manas</a>.
</p>

Where to Put It

Copy the code to a new file, name it “say.php” (or whatever else you want to call it) and put it in Macintosh HD /Library/WebServer/Documents/. Remember, this is the top-level /Library directory, not the one under your own user account. You also need to make sure that Web Sharing has been turned on under System Preferences > Sharing.

How to Use It

Open a browser, and type in:

http://localhost/say.php

from your own machine.

To do this from another machine connected to the same router, use the Bonjour name of your Mac (this can be found under System Preferences > Sharing.) E.g.

http://Manas-Desktop.local/say.php

To do this from a machine outside your router, you need to have configured your router correctly. And if you can do that, you don’t need me to tell how to do the rest of it.

Bonus feature: this script also lets you increase and decrease the volume. Perhaps then, Randall’s roommate might have heard him.

Screenshot

Warning: Security Issues

To achieve what this script does, it needs to take input from the Web and use it in a command that executes in a shell. The input is sanitized and I believe that such a risk is minimal. However, if you’re concerned about this possibility, do not install this script. You are responsible for what you do with this script and your machine. If you’re really concerned, put it inside an authenticated session.

Update: Added a command injection filter suggested by Mac OS X Hints user skicker.

Next Page »