Sunday, May 3, 2015

Vagrant up in the cloud (DigitalOcean)

It's quick and easy to start your virtual machine in the cloud if you use vagrant. Like, 55 seconds fast. I find it especially handy for toy projects that I need on the web quickly or when I don't want another virtual machine to gobble up resources on my laptop. I'm going through the steps for DigitalOcean. It's similarly easy for Amazon Web Services (AWS), but I find their web interface somewhat discombobulated.

A word on pricing: if you use the cloud for a small project it's basically free. A full day on Digital Oceans costs 16 cents. That's (hopefully) less than you tip on a cup of coffee. There are a lot of online coupons that'll get you through the first few months. AWS offers a full year for free, see http://aws.amazon.com/free/.

I'm assuming that you have vagrant installed and a Vagrantfile already written or generated with vagrant init. Ok, let's get started! First, download the vagrant plugin.

vagrant plugin install vagrant-digitalocean

Sign up on http://www.digitalocean.com. Digital Ocean is a cloud hosting provider. Once signed in, click on API at the top and generate a token.


Copy and paste the token. Now you have to tell vagrant who you are on Digital Ocean. Add the following to the vagrant file and delete any other line that specifies your base image, i.e.,  override.vm.box =... Replace 'YOUR TOKEN' with the token you just copied. Careful, do not push the Vagrantfile with your token to GitHub! 

  config.vm.provider :digital_ocean do |provider, override|
    override.ssh.private_key_path = '~/.ssh/id_rsa'
    override.vm.box = 'digital_ocean'
    override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"

    provider.token = 'YOUR TOKEN'
    provider.image = 'ubuntu-14-04-x64'
    provider.region = 'nyc2'
    provider.size = '512mb'
  end
And you're ready? 55 seconds, I told you! Start your machine in the cloud by running
    vagrant up --provider digital_ocean
To find the IP of your machine, you can ssh into it and run ifconfig.
    vagrant ssh -c ifconfig

Or you can find the IP on the DigitalOcean website under Droplets. This is also the place to see which instances (Droplets) you have running and to configure them.

If you specified some kind of web service in your vagrant file, you (or anybody else) can access it under this IP. (I used a node-hello-world example). 

The only user preconfigured on the digital_ocean.box is root, not vagrant. You can delete a personal access token on the DigitalOcean website. This is very useful, if the token ended up in your git history.



Friday, July 18, 2014

mod_rewrite vs CNAME changes

I thought I could be smart and redirect to a google sites project, instead of changing the CNAME entries. I had to learn that a mod_rewrite to a different url always does a visible redirect to the substituted url, so no faking that it's not a google site.



PHP Opcodes

First, what is an Opcode? It's a compiled form of a PHP script, similar to Java bytecode. Or, more precisely, from php.net

"When parsing PHP files, Zend Engine 2 generates a series of operation codes, commonly known as "opcodes", representing the function of the code."

<?php
  $a = "Hello ";
  $b = "World\n";
  echo $a . $b;

For a script like this, the opcodes look like that:

number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   2     0  >   ASSIGN                                                   !0, 'Hello+'
   3     1      ASSIGN                                                   !1, 'World%0A'
   4     2      CONCAT                                           ~2      !0, !1
         3      ECHO                                                     ~2
   5     4    > RETURN                                                   1

branch: #  0; line:     2-    5; sop:     0; eop:     4
path #1: 0,

Translate Sourcecode to op_array

Whoa. Now, how do you get the opcodes, i.e., op_array? You need a PHP extensions, like VLD (Vulcan Logic Disasembler). If you have pecl installed, you can download, build, and install it in one step by running

> sudo pecl install vld 
 
If you get an error message about a stable version, try running

> sudo pecl install vld-0.12.0

Now that you have installed it, you need to load it. In your php.ini, add the following, best if you put it close to extension=modulename.extension.

;  for op code
extension=vld.so

You find your php.ini by running
 
> php --ini
Configuration File (php.ini) Path: /usr/local/zend/etc


To generate the opcodes, all you need to do now is run the script with the following parameters (-d for ini entries)

> php -d vld.active=1 -d vld.execute=0 -f helloWorld.php

Tuesday, November 1, 2011

Math job search

Phil Grizzard's detailed description of his job application process.

A Longtime Math Grad Student's Job Search Experience

Totally worth reading if you're on the job market soon. Thanks for sharing!

Friday, August 26, 2011

GitX and Finder in MacOs

GitX is a cool tool to visualize your git branches. It automatically assumes all files ending in .git files are git applications. When you browse files in Finder, anything ending in .git is now not a folder anymore, and clicking on it will launch GitX. Very annoying. I assumed I could just right click the file and set Open with to finder, but you can only change it to other applications, you can't tell your Mac that foo.git is a folder, not a git application. Instead, I edited the file /Applications/GitX.app/Contents/Info.plist (sudo!). Remove the following line inside CFBundleTypeExtensions

<string>git</string>



...
<key>CFBundleTypeExtensions</key>
      <array>
          <string>git</string>
          <string></string>
      </array>

...

And then run
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -u -r -f /Applications/GitX.app/

It should say
ThrottleProcessIO: throttling disk i/o

Reopening Finder, and foo.git is a nice folder again.

Wednesday, August 10, 2011

Thunderbird notification pop-up

Every time I get an email, Thunderbird shows a little pop-up on my screen, saying x new emails from xxx. Oftentimes, I have co-workers look at my screen, they don't need to know everytime I get an email that it's from Amazon, Zappos, Banana Republic, or Victoria's Secret. So, here's how you turn it off:
  1. Click Edit and select Preferences
  2. Click Advanced
  3. Select the General tab
  4. Click the Config Editor button
  5. Search for biff
  6. Set mail.biff.show_alert to false

Saturday, July 9, 2011

Book recommendation: A PhD Is Not Enough: A Guide To Survival In Science

I've recently read this small book, I devoured the 128 pages within two hours. Thought written in 1993, I think it is still highly accurate.

Feibelman, a physicist,  describes several cases of unsuccessful scientific careers, despite hard work and intelligence. He points out the problems and gives advise how to avoid them.

Every scientist should read his book early in grad school, refresh his memory when finishing grad school, and again when mentoring graduate students.

A PhD is Not Enough on Amazon



Friday, July 8, 2011

Academic Job Search: Writing a good CV, research statement, and teaching statement

I won't give you boring details of how you should format your CV, there's enough resources out there that give you much better advise than I ever could, instead I will tell you what you can and should do during graduate school, to generate the content for your CV and statements.

Please keep in mind that I was specifically looking for post doctoral research positions in mathematical biology. If you want to land a teaching or tenure position, some rules might be different.

Job Application Timeline
  • Academic Jobs beginning fall 2011 (June – September)
  • Deadlines for postdocs: as early as November 2010
  • Asked for letters: September 2010
  • CV, Research Statement, Preprint/publications/thesis
  • Draft of Research Statement August/September 2010
  • CV: first version in 2008, career services, periodically updated
  • Jobs are advertised on https://www.mathjobs.org/
  • http://notable.math.ucdavis.edu/wiki/Mathematics_Jobs_Wiki
  • Discussed everything with my advisor, proof-read by advisor, several friends proof-read my statements, department head, career services
  • Compared CV and statements to those of other mathematicians

Application Process
  • Through http://mathjobs.org
  • Cover letter
    • Name of position and school
    • find department head’s name
    • Possible collaborations/groups, i.e. Mathematical Biology, Symbolic Computation
  • Mention possible collaboration in research statement
  • Mention possible new curriculum/teaching methods/undergraduate research in teaching statement
  • 1-3 hours per application
  • ~30 applications
  • 5-10 applications to specific research positions not in Academia:
    • Research Hospitals, pharmaceutical companies, Microsoft Research, Cancer Systems Biology Group
    • Application directly to senior researcher 

Create Content for your Research Statement
  • Talk to your advisor (and other faculty) about your goals
  • Participate in conferences and workshops
    • Explore local options
      • SIAM seminar
      • Department Math Seminars,  Physics seminar, Graduate student speaker series, Symposium, … (read all announcement emails!)
    • Workshops (NSF math institutes)
    • Poster presentations
  • Leadership role (SIAM, SGTA, student organization, organize a seminar…)
  • Letters of recommendation
    • 2-3 research letters, 1 teaching letter
    • Knows you and your work in detail
    • Well known
    • Your advisor can suggest letter writers!

Create Content for your Teaching Statement

  • “Show, don’t tell”
    • I’m the best teacher in the world.
    • My section scored highest, best rating on evaluations, …
  • What have you accomplished that distinguishes you from other teachers?
    • Teaching large/higher-level course?
    • Anything that’s not standard curriculum (Mathematica)?
    • Review sessions/material for all sections?
    • Tutoring? Volunteering with high school events/girls’ math day/Kids’ Tech University? 
    • Do something special now, so you can write about it, when you apply 
  • Tell GTA supervisor about your career goal, he/she might have “special tasks” for you 
    • Special course to teach 
    • Special leadership roles as senior TA
  • Be a good colleague 
    • Be on time, be prepared 
    • Participate in department events (Visitors’ day, peer mentoring, …) 
    • Be friendly and helpful to your fellow colleagues (share notes, offer to substitute, …) 
    • (especially in a small department) you are hired as a team member, not a 9-5 teacher 

My Advice
  • Have a goal, know what’s necessary to accomplish it, work towards that goal
  • Take any help you can get, don’t be afraid to ask
  • Good Luck!

I hope this article makes you start thinking about your CV before you actually have to write one! 
 

Latex: Table of Content problems with Bibliography and Index

When creating a table of content (TOC) , bibliography and index are not listed when created with \bibliography and \printindex. This is how you get them to appear in the TOC with the correct page numbers.

\cleardoublepage
\addcontentsline{toc}{chapter}{Bibliography}
\bibliographystyle{plain}
\bibliography{../all}

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Index}
\printindex

Latex: Centering table larger than textwidth

Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth.

% allows for temporary adjustment of side margins
\usepackage{chngpage}

\begin{table}
    \begin{adjustwidth}{-.5in}{-.5in} 
        \begin{center}
        \begin{tabular}{|c|}
            \hline
And here comes a very long line. And here comes a very long line. And here comes a very long line.  \\
            \hline
        \end{tabular}

        \caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. }
        \label{myTable}
        \end{center}
    \end{adjustwidth}
\end{table}