Sec, blogmal!
09 2010



April '18



Tue, 21 Sep 2010

Monty Hall V2

Today I have a small puzzle for you. It was originally told to me by logix and is a nice variation of the Monty Hall problem.
If you've never heard about the Monty Hall problem before, you could check out the linked Wikipedia article.

In a new ("Let's-Make-A-Deal"-type) game show for couples, there are 3 curtains behind which are hidden a car, a car key, and a goat.

One member of the couple is designated the car-master:
- the car-master's goal is to find the car.
The other one is designated the key-master:
- the key-master's goal is to find the key.

If both partners succeed in their respective tasks, the couple drives away in their new car. If either one fails, the couple gets nothing.

The game begins with the car-master (at this point, the key-master is led out of the room and cannot observe the proceedings). The car-master has two tries to find the car (i.e., open any curtain; if the car isn't there, then open another curtain). If the car-master succeeds in finding the car, all open curtains are re-closed, and the key-master is brought back into the room. No communication whatsoever is permitted between the car-master and key-master at this point.

The key-master now has two tries to find the key (i.e., open any curtain; if the key isn't there, open another curtain). Assuming the couple plays optimally, what are their odds of winning the car?

Randomly picking works out to 4⁄9, i.e. about 44% – You can surely improve this, but how? And what is the best solution? Post your suggestions in the comments…

– Sec

posted at: 09:57 | Category: /pastimes | permanent link to this entry | 6 comments (trackback)

Sat, 18 Sep 2010

Firefox-Addons und die Icons

Als Nachtrag zu dem ersten Artikel.

Die Icons verschiedener Extensions im Statusbar wandern ja beim installieren neuer Extensions immer lustig hin und her. Im ersten Artikel hatte ich beschrieben wie man das von Hand reparieren kann.

Inzwischen geht das auch deutlich einfacher. Wie? Mit der Organise Status Bar Extension.

Yay, kein manuelles Gefummel mehr :-)

Und wenn ich schon mal über Firefox schreibe – meine aktuellen lieblings-Extensions:

Welche fehlen eurer Meinung nach?

– Sec

posted at: 13:18 | Category: /tidbits | permanent link to this entry | 4 comments (trackback)

Wed, 15 Sep 2010

Fixing the alternate screen problem

Many of you probably know the annoying behaviour of console-based programs like less or vi restoring the screen after exiting so that the text you just had there vanishes.
I never understood why you'd want that, and its commonly enabled by default on Linux machines.

The underlying feature is called alternate screen and basically its a feature of your terminal (be it xterm, gnome-term or even your console).

If you want to get rid of it, you have a few options:

Tell each and every program, not to use that feature.

A prime example is the less option -X.
This is useful as a quick ad-hoc solution, but not really feasible for everyday use - You don't really want to (re-)configure every program.

Tell your terminal not to enable this feature.

XTerm has an option located in the Ctrl+Middle mousebutton -Menu and is called Enable Alternate Screen Switching. Turn if off and all programs within will behave nicely.
If you want it for all your xterm windows, you can add something like this to your ~/.Xdefaults:

  XTerm*titeInhibit:  true
  UXTerm*titeInhibit: true

If you're using gnome-terminal, this is not for you. Gnome-terminal simply provides no way to disable this feature. Boo

Lie to your programs and say your terminal doesn't support it.

All (well-behaved) programs check if your terminal supports alternate screens before using them. This information is stored in the system terminfo or termcap database. Whether your system is using termcap or terminfo is an historical thing – Linux/SysV based systems tend to use terminfo, BSDish systems termcap.

This database has an entry for every terminal type your system supports. Your terminal is stored in the $TERM environment variable. Go and check your $TERM value. It is most probably xterm or something similar.

The capabilities for alternate screen are called ti and te in termcap and smcup / rmcup in terminfo. (Yay! for gratuitous differences). What we will be doing, is to override these by placing a suitably modified file in your $HOME.

For terminfo it works like this:

  infocmp -l $TERM > $TERM.src
  vi $TERM.src # remove the smcup= and rmcup= parts till the next ,
  mkdir ~/.terminfo
  tic $TERM.src

This dumps the current entry to a file, and compiles it into a file in ~/.terminfo/ after you modified it.

Termcap just uses plaintext files, so go look into your system termcap file (/usr/share/misc/termcap or similar), and find the entry for your current $TERM. On my system it looks something like this:

  xterm|xterm-color|X11 terminal emulator:\

copy that into ~/.termcap, and add :ti@:te@ at the beginning of the second line to disable these two capabilities. As you can see from my example on FreeBSD this is done by default for xterm and xterm-color.

That should fix it for you.

If you use screen

Lastly, if you are using screen, there is a simpler way to do it. Screen has a built-in feature to edit the termcap/terminfo for programs running inside. Simply add

  termcapinfo xterm* ti@:te@

to your ~/.screenrc (of course replace xterm with your $TERM in use before you start screen)

I hope this lengthy explanation did not bore you too much…

– Sec

posted at: 14:51 | Category: /tidbits | permanent link to this entry | 6 comments (trackback)

Mon, 06 Sep 2010

How to make a checklist in HTML

In my ongoing quest to get rid of unnecessary use of WinWord, I moved a two-page checklist into our internal wiki. Unfortunately I came across two problems while doing that:

  1. HTML <li>s don't support big empty circles. They default to black bullets, and the CSS {"list-style-type: disc;} only creates tiny circles.

    Unicode to the rescue: \x25EF, also known as \N{LARGE CIRCLE} or makes a fine replacement. Two lines of CSS to fix your list:

    ul { list-style-type:none; }
    ul li:before { content: "\25EF"; }

  2. No page breaks. The list was on two pages for a reason and I needed to keep it that way. That was easily fixed by inserting

    <br class="break" /> 

    and making the break with CSS:

    br.break { page-break-before: always; }

    My first attempt was to use a <hr> instead – but strangely enough it made Firefox print another empty page at the beginning when used inside our wiki.

Putting it all together for TWiki:

<!-- <pre> -->
<style type="text/css" media="all">
br.pagebreak { page-break-before: always; }
.patternTopic > ul { list-style-type:none; }
.patternTopic > ul > li:before { content: "\25EF"; }
<!-- </pre> -->

The .patternTopic makes it only apply within the article, and the > makes it only apply on the first level after that.

– Sec

posted at: 19:02 | Category: /tidbits | permanent link to this entry | 1 comment (trackback)
<< older

powered by blosxom
in 0.00 s