## Posts

Showing posts from 2010

### sed for several different substitutions in one file

sed -e 's/a/A/' -e 's/b/B/' <old >new

### git merge --squash

Start out on branch master, then work on an experimental branch

$git checkout -b experimental Do a series of commits etc. If you decide that the experimental features should now be part of master, do the following:$ git checkout master $git merge --squash experimental$ git commit -a
The commit message automatically has a list of all commits in experimental.

### Syntax Highlighting on Blogger

If you change your template, don't forget to include the script tags for syntax highlighting! Follow these simple instructions from

Carter Cole

You can easily submit data in an html form via jQuery's $.post. But you need to do a little more to upload a file. I suggest the jQuery Form Plugin. Here is the HTML form: <html> <head> <title>Title</title> </head> <body> <form action="/test.cgi" enctype="multipart/form-data" method="post"> <input name="myFile" type="file" /> <div id="results"> </div> </form> </body> </html> This is the Javascript file myFrom.js:$(document).ready(function() { $('form').ajaxForm( { beforeSubmit: function() {$('#results').html('Submitting...'); }, success: function(data) { var $out =$('#results'); $out.html('Your results:');$out.append('<div><pre>'+ data +'</pre></div>'); } …

### What I just learned not to do:

to boldly split infinitives that no man had split before.

### My favorite words ...

... here's my list of words that I'm always struggling to come up with when writing a technical paper:

natural
emphasis
arising in
vital, crucial
innovative
foster
driving
instantaneous
challenge
all aspects of

### git status

git status --untracked-files=no

or

git config alias.stat "status --untracked-files=no"

and then

git stat

I'm trying to trace a bug in some big subversion repository, and decided to put the relevant files under git control. Let's see how that works.

### `require': no such file to load

I keep forgetting this:
require 'rubygems'

### LaTeX in HTML

MathJax

"MathJaxTM is an open source, Ajax-based math display solution designed with a goal of consolidating advances in many web technologies in a single definitive math-on-the-web platform supporting all major browsers."

### change ulimit permanently

When a user changes the limit of system-wide resources with
ulimit -St 36000
this is only valid, for as long, as he is logged in. To set a value permanently, he can edit his .bashrc

ulimit -St 36000

### How much cpu time in ulimits?

You can set the cpu time using ulimit, but to what?
On our 4 quad-core machine, we have set the soft limit to 80 minutes (4800 seconds) but allow the user to increase it to up to two days. On our company wide file server it is set to 20 minutes (1200 seconds).

### ulimit - high memory utilization

If you have too many high memory processes running, your machine probably won't like it. You can set the maximum CPU time per user in

This gives every user 80 minutes of cpu time. You can check with:

If a user needs more cpu (and is aware of that), he can increase it to up to two days but not more than that.

Be careful, ulimit specifies cpu time in seconds, limits.conf in minutes.

### Latex: .sty files

TeX will locate any file in ~/Library/texmf/tex or in a subfolder of this folder; LaTeX will locate any file in ~/Library/texmf/tex/latex or a subfolder of this folder.

For TeXshop on a Mac, .sty files are found in

and all its subfolders.
After placing a new file there, run

to update the entries.

### git checkout -b drunk

This should be safe.

### no /proc/cpuinfo on my MAC OS

Oh no :(

system_profiler SPHardwareDataType|grep "Processor Speed"

### M2: keeping track of your ring

When using a quotient ring, make it a global variable, otherwise you'll end up in the base ring. When you work with a list of polynomials, best store them as a 1xn matrix, this way, they're all in the same ring:

### git submodule

yea, submodules rock!

### Rings in M2 with "my variables"

M2 can easily create a ring with many variables

R = ZZ[vars(0..10)]

But I need my variables to be called x1, ..., x10 (in particular, not x_i)

l = apply(10, i-> value concatenate("x",toString i))

I make strings "xi" and applying value turns the strings into symbols, the correct input for a ring:

R = ZZ[l]
gens R

### Creation of a Bacterial Cell Controlled by a Chemically Synthesized Genome

Science Magazin

Slatest Latest

Die Zeit

Colbert
: What makes you think you can do a better job than God?

Craig Venter on the Colbert Report
2-27-2007

10-30-2007

### \@listctr undefined control sequence

When including special citation packages, but using

latex will complain and not compile the document

Just make sure you comment out the special package

trash the aux files, and you're good to go!

### Branching with git

git branch new-branch
git checkout new-branch

remote push/pull

### git-svn

You can make sure these changes were committed to the svn repository, by doing a svn up in a regular svn clone of the repo. To fetch changes from the svn repo, instead of svn up, do

### Installing Lapack on Suse

Unpack the tar file lapack.tgz.
Copy the Makefile and make it

### How to Make a Black & White PDF File

Open the image with Adobe Acrobat 9 Pro. In the Advanced Tab click on Print Production -> Preflight. Open the menu for PDF fixups by clicking on the triangle next to it and choose Convert to grayscale.

"500 Internal Server Error Sorry, something went wrong. A team of highly trained monkeys has been dispatched to deal with this situation."

I knew it! Monkeys can program.

### Perl 5.8 vs 5.10

Apparently this used to work in Perl5.8.9 but no in Perl5.10.0 anymore:

$line is empty when run with 5.10.0, but the correct data, when run with 5.8.9. In 5.10.0, omit the extra${}:

So be careful, when updating to Snowleopard (comes with Perl5.10.0) and your scripts don't work as expected.

### crontab

What you need to know:

Either use the
minute hour day month day-of-week format, or shortcuts like @daily. The script should be placed in /etc/cron with permission to be executable, i.e. 755.

### Simple website redirect with perl

For when you're too lazy to fiddle with mod_rewrite, you can use a simple Perl script to redirect file a.pl to b.pl.

Upload a file a.pl with the following content:

chmod a.pl with the right permissions - and, of course, make sure, Perl is supported.

### Nothing better than drunk programming...

well maybe one thing ...

### Setting up remote git repository

On your remote machine, create a new directory and start a new git repository.

On your local machine, or wherever you have the files, start a git repository, add the files you need, and commit them.

Now you have your files under revision control, but only locally, which is bad if your hard drive breaks or if you work from more than one machine. So add the repository on the remote machine as another remote directory and push to it.

To get the files on another machine, do

### converting files to .ps

You can use Preview -> print -> Save as PostScript to turn a pdf or jpg into ps. Only problem is, that the new image is the size of the paper you printed to, not the original image size. As on the picuture below, there's extra space added at top and bottom of the picture.

### Generating ps files from pictures

If you have, you can use Adobe Acrobat Pro on an image in pdf format and use "Save As" PostScript. If you don't have it, cross your fingers and hope that

works.

### No gain from brain training

I wish, we could always have 11,430 participants for a study as in this Nature article, "No gain from brain training".

### The edges of understanding, Arthur D Lander

"A culture’s icons are a window onto its soul. Few would
disagree that, in the culture of molecular biology that
dominated much of the life sciences for the last third
of the 20th century, the dominant icon was the double
helix. In the present, post-modern, 'systems biology' era,
however, it is, arguably, the hairball."
-- doi:10.1186/1741-7007-8-40

### A study of scientific publication ethics

Just went to a great talk about publication ethics. The next time you review a paper, use this easy tool (eTBLAST) to check for plagiarism. Just copy and paste the abstract to it.

"Identification of duplicate citations in the bio-medical literature
The project aims at identified highly similar citations (based on their abstract) to flag potential cases of unethical publications, using a text comparator algorithm named eTBLAST."

Right now it only searches medical databases (Medline, Pubmed, NASA, ...) but it will search the arXiv soon!

### Can a Systems Biologist Fix a Tamagotchi?

Here's a great paper that humorously lays out the challenges of reverse engineering.

"Another common inspection tool in biology is gene perturbation experiments. As already mentioned, this technique can provide useful information, but it is also used more blindly, e.g., by deleting in turn every single gene in an organism to see what happens. In software engineering, no one has ever seriously proposed to remove each instruction in a program in turn to see what breaks. One might have a slightly better chance of acquiring useful knowledge by removing all pairs or triplets of instructions, but this immediately becomes unfeasible."

### Merging multiple files columnwise

Here's a little parser script, to merge multiple files. Each file has a header and a time course. I need all time courses in a single file, next to each other.

basedir = "./MassSpectrum/" allData = [] # ms data from all files filelist = Dir.new(basedir).entries filelist.each {|f| if f !~ /\.txt/ # f is not a data file next end data = [] # ms data from this files massToCharge = 50 readData = false # set to true once we are reading in ms data File.open( basedir+f).each { |line| case line when /^SPECTRUM/ next when /raw/ data.push line.chop.rstrip puts ":#{line.chop.rstrip}:" next when /^Mass/ puts "starting" readData= true next end if readData # we are reading ms data, should go from 50 to 650 arr = line.split while arr.first.to_i != massToCharge # a mass to charge ratio was skipped data.push 0 massToCharge = massToCharge + 1 end …

Dear Igor,

no thank you, my (not yet written) thesis should not be published as a book. The individual sections have been published in different magazines, so it is available to a "wider audience" already. Let's save some trees and not turn every collection of written words into a book.

FH

Dear Hinkel Franz,

I am writing on behalf of the International publishing house, Lambert Academic Publishing.

In the course of a research on the The Department of Mathematics at Virginia Tech, I came across a reference to your work in the field of Mathematics.

We are an International publisher whose aim is to make academic research available to a wider audience.

LAP Publishing would be especially interested in publishing your dissertation in the form of a printed book.

Your reply including an e-mail address to which I can send an e-mail with further information in an attachment

will be greatly appreciated.

I look forward to hear from you.
Kind regards,
Igor Manole
Acquisition Editor

LAP LAMBERT A…

### Vim Spellchecking

Vim 7 has built in spellchecking. You can turn it on and off with and F11 and F10 .
To add a word to your dictionary, use zg. But even better, to delete a word from the dictionary, use zw (for wrong word).

### Caption before Label

If you need to reference a table in a latex document, make sure you set the caption before the label, otherwise the table will be incorrectly referenced as the section it is in.

\begin{table} \begin{center} \begin{tabular} {|l|r|} \hline Protein & number of functions\\ \hline Cln3 & 1\\ MBF&5\\ SBF&5\\ Cln1,2&4\\ Cdh1&15\\ Swi5&17\\ Cdc20\&Cdc14&7\\ Clb5,6&6\\ Sic1&339\\ Clb1,2&64\\ Mcm1/SFF&5\\ \hline \end{tabular} \end{center} \caption{Number of possible functions for each protein} \label{table:numFun} \end{table}

### Latex Table with multirow

If you ever have to make a table, where you need multiple lines for one entry, this is one way to do it:

\usepackage{multirow}
\begin{table} \makebox[\textwidth][c]{ \begin{tabular}{ccccccc c cccc} \multirow{2}{*}{Time} & \multirow{2}{*}{Cln3} & \multirow{2}{*}{MBF} & \multirow{2}{*}{SBF} & \multirow{2}{*}{Cln1,2} & \multirow{2}{*}{Cdh1} & \multirow{2}{*}{Swi5} & Cdc20 and & % This is the part to be split \multirow{2}{*}{Clb5,6} & \multirow{2}{*}{Sic1} & \multirow{2}{*}{Clb1,2} & \multirow{2}{*}{Mcm1/SFF}\\ &&&&&&& Cdc14 \\ % This is the second row \hline 1&1&0&0&0&1&0&0&0&1&0&0\\ 2&0&1&1&0&1&0&0&0&1&0&0\\ 3&0&1&1&1&1&0&0&0&1&0&0\\ 4&0&1&1&1&0&0&0&0&0&0&…

### scrolling inside screen

I love screen, I use it for everything (remote session, slime.vim). But sometimes I hate it. I can't scroll! Well, no that is not true. I didn't know how to scroll.

First you have to turn on the buffer. Create a .screenrc in your home directory with the following content:

# define a bigger scrollback, default is 100 lines defscrollback 10000

You can access the scrollback buffer by entering "copy mode", which is accomplished by typing
C-a ESC

Here is the full explanation.

Oftentimes I need to run long computations on a remote machine. Sometimes it's enough to just pipe the results into a text file

In many cases this is not enough, when something goes wrong, or when you need to work with the results, or when you're inside an important irb session and want to come back later. The thing to use then is screen. It allows you to come back, when the ssh connection has been closed, and find your old terminal just the way you left it.

When coming back to the remote machine, you can check on the results:

### Movies in Presentations

Shifting farther and farther away from blackboard talks, I sometimes need animated gifs or movies in my presentations.

And it works perfectly with Latex Beamerclass.

Here is a good tutorial for animated gifs like the one you see. Just make sure, that convert really converted the file to pngs, if not, use Preview and Save As to turn it into the right format.

Here is a wonderful tutorial on including movies. The movie is saved within the pdf file, so no fiddling around with multiple files when giving the presentation using an installed presentation system or a shared laptop.

Before giving the presentation, go through the slides, and click ok on the warning message about playing the movie, then give a wonderful talk!

I used Screen-O-Matic to create a movie. To get rid of the Watermark, you have to pay a small fee - or you make the movie bigger (i.e. longer from top to bottom) than your slide. When you include it in your tex document with

the bottom will be cut off so nobody sees the…
I'm sorry it's German, but it's just too funny:

"Diese Vermarktungsstrategie ist hochgradig sexistisch, wer jetzt meint, er könne sich endlich auch mal an einen Roman wagen und "Fucking Karlsruhe: Bekenntnisse eines deutschen Maschinenbaustudenten" verfassen, wird es schwer haben, einen Verlag zu finden." (spiegel.de)

### I wish I'd have more time reading

Weekend Reading: Ruby Best Practice Chapter 1, Driving Code Through Tests

Yes, I'm a little behind with my reading, but it was definitely worth while.

I was happy to find such a good chapter on testing, because most other books only cover trivial testing, but they don't show how to build useful tests.

What did I learn?
* use single tests for every different case. This results in better readability, and in case an assertion fails, I know exactly in which scenario it failed and all assertions in different tests, will be tried, so I'll know right away if all of them failed or just a particular one
* use tests more as a way to drive your software, not only as regression tests
* there's a when? Yes, switch-case is a case-when in Ruby
* goal for next time Ruby programming: force myself to use a stub/mock
* embedding tests in library files

For my math programming (Macaulay2) I rely heavily on tests: for every little function a handful of tests, and a few functional tests, …

### Screen for long remote tasks

use

to start a session named mySession on your remote machine. Start the things you want to run, for example a

close the shell by quitting terminal (don't Ctrl C out!)
When you come back, and want to see how far your make went, attach to the old screen with

If you don't remember what you called the session, try

### Macaulay2 Workshop

is happening soon. I hope to gain some new wisdom that will be worth sharing.

Macaulay2 is a software system for research in algebraic geometry - and it rocks, and we were very productive!

### obj.send in ruby 1.9

It might say here, that send doesn't work for private methods in Ruby 1.9, but that's not true anymore. You can also compare the 1.9 and 1.8.6 documentation - identical for obj.send.

### Git pushing to multiple repositories

If for some reason you have to push to multiple repositories, add an alias to your .git/config (obviously you don't want this in your ~/.gitconfig):

The exclamation mark runs the alias as a command, without an exclamation mark, it's assumed that you run a git command.

results in a change in your ~/.gitconfig

which you can delete with

or delete all aliases.

### Vim for irb

Ever used irb and wished you had safed your commands or could edit them using Vi? Ever tried something new in irb, and then had to painfully copy and paste it to the .rb file? Slime.vim from Jonathan Palardy will be your new best friend.

Slime.vim lets you send highlighted text to a different terminal. This means you can write a few commands, send them to a terminal running irb, notice you want to change something in your first command, modify that line in Vi and resend it to irb, and so on.

Put slime.vim into ~/.vim/plugins

In one terminal:

1. start a named screen

2. name the window

You'll be prompted for the window's name, "Set window's title to:"
irb_window
3. start irb

In a different terminal, start vi and type irb commands, highlight one or multiple commands (ESC V to highlight the current line, ESC vip to highlight a paragraph), type C-c C-c to execute the highlighted text in the other terminal. The first time you'll be prompted for session and window, en…

### Ruby gem for Optimal Control for Conway's Game of Life

\$ gem install optimal-control

http://rubyforge.org/projects/optimal-control/

My little gem to find an optimal control strategy for Conway's Game of Life is available. Documentation will follow ...

### Google Sites for quick and easy websites

I like my (stolen) design, but Google sites is just so much faster - and you barely know it's Google Sites admg.vbi.vt.edu.

And of course we can change the URL, just waiting on the CNAME changes.