Skip to main content

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, checking the full algorithm. Functional tests are so immensely helpful for math programming, because it's hard to test by hand, if a set of polynomials is exactly the same as expected.

Comments

Popular posts from this blog

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}

Uploading a file with JQuery

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>'); } …

Highlighting paragraphs in Latex

When revising a document, I often want to highlight my changes, so my collaborators can easily see what I changed.

\underline works for single words, but it puts everything in a horizontal box and long text isn't wrapped anymore.

Instead, I use the package soul and \ul to underline.
\usepackage{soul}
Or you can highlight text using \hl. This will underline the text unless you use the color package, then it turns into typical marker-highlight.
\usepackage{color}