tanketorsken.dk/categories/uncategorized/

Feeds

Maybe the best answer on stackoverflow

Was doing some random browsing when I found this answer on stackoverflow. It could very well be the most thorough answer on stackoverflow! :)

First major written assignment at dtu

I have finally decided on a subject for my first major written assignment at dtu. The title of my assignment is “Detection of human alertness using supervised learning”. I have to develop a program that given some 30 measurements of physiological and environmental factors can decide whether a driver is about to be inattentive. I am very excited and eager to get going.

The set of all polynomials with integer coefficients is countable

I have been up late, finishing my first written assignment for the course Mathematics 3 at DTU. By coincidence I found a very neat proof of the countability of the set of all polynomials with integer coefficients. The idea is to map every polynomial to a unique integer. The easy way to do that is to define a positional base-13 numeral system where the digits for 10, 11 and 12 is represented by the symbols “x”, “+” and “-”. That way, every polynomial, represents a unique integer in the base-13 system. Eg. the polynomial

  x^2 + x - 1  is the base-13 number

  xx+x-1  which (in base-10) equals

  10\cdot 13^5 + 10\cdot 13^4 + 11\cdot 13^3 + 10 \cdot 13^2 + 12\cdot 13 + 1 = 4 024 554  Every other polynomial maps to a unique integer in the same way. One small problem remains. The preimage of the mapping isn’t the whole set of integers, so what we know right now, is that the cardinality, of the set of polynomials, is less than or equal to the cardinality of the set of integers. No problem. The set of all zero-degree polynomials is a subset of all polynomials, and all zero-degree polynomials maps to a single integer and all integers is mapped by a single zero-degree polynomial. This implies that the cardinality of the set of all polynomials is greater than or equal to the cardinality of the set of integers.

The only possibility that remains is that the cardinality of the polynomials and the integers is exactly equal. Technically we need to show that the integers is countable, by mapping them 1-1 to the natural numbers, but that is trivial.

Paste from clipboard to gvim

Sometimes I need to paste something from the clipboard to gvim. The content of the clipboard is saved in the register *, so the command

"*p

does the job.

Remap keys in Ubuntu

I’ve just installed Ubuntu and wanted to remap a few keys system wise. The xmodmap command is useful for this task. First you need to find the keycode for the key you want to remap and the keysym that the key should be remapped to.

$  xmodmap -pk | less

When you have found the keycode and the keysym you just enter

$ xmodmap -e 'keycode <keycode> = <keysym>'

and then the key is remapped.

EDIT 08-04-2011:
Use the command xev to find the keycode for the key you want to remap. If I want to change the key that is the half fraction on my Lenovo I type in

$ xmodmap -e 'keycode 49=dollar'

Vi tar’ den en gang til

Jeg ved ikke hvor mange gange jeg har brugt disse kommandoer, men jeg bliver alligevel ved med at glemme dem! Grr…
Opret arkiv med

tar cvzf archivename.tar.gz foldernametotar

Udpak arkiv med

tar xvzf archivename.tar.gz

Underbevisthed

Skulle lige sikre mig at python 2.5 returnerede floats ved division, men var lidt distræt og endte med at skrive

from __future__ import decision

det kunne være pænt sejt hvis det virkede…

PHP compact funktionen

Jeg kan stadig finde nye små godbidder blandt phps funktioner. Nogen gange kommer jeg ud for en situation hvor en funktion har en række parametrer som den så skal samle i et array og sende videre:

function menu($items, $id, $show_submenus) {
    return render_partial('menu', array(
        'items' => $items,
        'id' => $id,
        'show_submenus' => $show_submenus
    ));
}

Repetitionen er rimelig tydelig, men jeg vil gerne have funktionen “menu” så jeg i min template kan skrive

<div class="some_wrapper">
    <?=menu($items, 'mainmenu', true)?>
</div>

istedet for

<div class="some_wrapper">
    <?=render_partial('menu', array('items'=>$items, 'id'=>'mainmenu', 'show_submenus'=>true)?>
</div>

Løsningen er en php-funktion jeg har overset indtil i dag. Compact tager et vilkårligt antal strenge. For hver streng undersøger den om der er en variabel med samme navn defineret i samme scope, som compact bliver kaldt. Hvis der er, bliver variablens værdi tilføjet til det array compact i sidste ende returnerer. Arrayet compact returnerer har variablens navn som key og variablens værdi som value. Lige hvad der skal bruges til at gøre min menu-funktion pænere.

function menu($items, $id, $show_submenus) {
    return render_partial('menu', compact('items','id','show_submenus'));
}

Lodrette streger i matricer i Latex

Sidder og skal have bikset en aflevering i operationsanalyse (nej det har ikke noget med hospitalsvæsenet at gøre) færdig. Jeg skal blandt andet skrive nogle matricer der skal have lodrette streger mellem nogle af kolonnerne. Fandt denne lille stump man bare skal smide i sin preamble

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

og vupti så kan man få lodrette streger ved at angive en ekstra parameter til matrix-environmentet.

\begin{bmatrix}[ccc|cc]
    2 & 1 & 2 & 1 & 0 \\
    1 & 2 & 3 & 0 & 1
\end{bmatrix}

WP-Latex installeret

Har lige installeret WP-Latex og skal lige tjekke at det virker:
\int_0^1 t^2\,dt
Det virker det jo til det gør. Og her:
  \sum_{n=1}^{\infty}\frac{1}{n!}