css media queries

categories: blog

When I learned about css media queries from Debian Developer Vincent Bernat's blog I made a few changes to the css of this site as well.

I increased the content width from 600px to 700px and made use of this construct throughout the css:

media screen and (max-width: 700px) {#content {width:100%;}}

This piece will overwrite the width property of the content div from static 700px to variable 100% of the window size and by that consuming whatever the sub-700px-width screen size leaves for the main content. The positive effect of this measure is that on screens below a width of 700px, no horizontal scrolling will be needed to read the main content. It will be cramped in whatever is offered. This is of course most usable on mobile devices. Horizontal scrolling will only be needed to access the main menu. I could put the menu at the bottom but decided that scrolling sidewards will be less hassle than scrolling to the bottom of a page.

I not only changed the content width for screens below 700px width but also adapted margins and paddings from 1em to barely noticeable 1 pixel.

Try to resize your browser window to below 700px to see the effect - it's pretty nifty and works without any javascript on browsers that understand that css property.

View Comments

rxvt-unicode font size

categories: blog

It is simple to change the font size of rxvt-unicode via an entry in ~/.Xdefaults:

URxvt*font:             xft:DejaVu Sans Mono-8

But it is also possible to change the font on the fly via this escape sequence:

printf '\33]50;%s\007' "xft:DejaVu Sans Mono-8"

While playing around with that I also found out that it is very simple to change the font of any other terminal you know the PID of, by just doing something like:

printf '\33]50;%s\007' "xft:DejaVu Sans Mono-8" > /proc/$pid/fd/0

where $pid is the process id of the shell you are running.

View Comments

mandelbrot

categories: blog

A very nice minimal code size implementation of the Mandelbrot algorithm by Ken Peril I found here

main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}

It is very interesting to see what techniques where applied to minimize the amount of source code bytes. When I tried out the code, not knowing what pattern it would output I was very find to see a Mandelbrot pattern printed to my terminal :)

The code translates to this which outputs the exact same bytes:

#include <stdio.h>

int main(int argc, char **argv)
{
int k,x,y;
float i,j,r;
char *chars;
chars = " .:-;!/>)|&IH%*#";
for(y=-15;y<16;y++) {
puts("");
for(x=1;x<=84;x++) {
i=0;
r=0;
for(k=0;k<112;k++) {
j=r*r-i*i-2+x/25.0f;
i=2*r*i+y/10.0f;
if (j*j+i*i>=11) {
break;
}
r=j;
}
putchar(chars[k&15]);
}
}
puts("");
return 0;
}

y and x iterate over rows and colums on the terminal. They are scaled by 1/25 and 1/10 respectively. 112 is the maximum iteration number and only has the requirement of being divisible by 16 (the number of characters for the ascii art). A difference to the original algorithm is the -2 in calculating j but this is just to shift the x values to the right on output. Alternatively one could also just iterate x eg from -50 to 34 instead from 1 to 84 which would give a similar output. To compensate for the shift and to also draw points close to the border 11 was chosen as a good stopping criterion for beautiful output. Normally one would check for jj+ii being less than or equal to 4 but this would mean that for border points the algorithm would terminate in the 1st iteration, painting those points the same as the ones that do not lie in the Mandelbrot set.

View Comments

sirf/nmea protocol switch

categories: blog

For my touchbook i recently bought a Navilock USB GPS-Modul NL-302U SIRF III containing a SiRF III chip that are known for their excellent quality.

This is how the baby looks on the inside:

navilock gps

And this is how it looks when attaching it to my linux box:

[40538.052593] pl2303 2-1.2.1:1.0: pl2303 converter detected
[40538.054396] usb 2-1.2.1: pl2303 converter now attached to ttyUSB0

Bus 002 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Unfortunately instead of the widely understood ASCII based NMEA 0183 protocol those chips are using the proprietary, binary SiRF protocol. Luckily the gpsd guys are hosting a pdf documentation of that protocol. Reading that documentation one can also find out that it is possible to switch between NMEA and SiRF modes.

Reading and displaying data from a serial port is most convenient with:

apt-get install python-serial
/usr/share/doc/python-serial/examples/miniterm.py /dev/ttyUSB0 9600

And writing to serial is quickest with:

from serial import Serial
tty = Serial("/dev/ttyUSB0", 9600)
tty.write(message)

or

python -c "from serial import Serial; Serial("/dev/ttyUSB0", 9600).write(message)"

According to section 1.2.3 of the documentation the following message needs to be written to switch from NMEA to SiRF binary mode at 9600 baud:

message = "$PSRF100,0,9600,8,1,0*0C\r\n"

Switching from the default SiRF binary mode to NMEA is more involved but described in section 2.2.2.

Numbers are 7 bit and in big endian notation:

pack = lambda x: chr(x>>8)+chr(x&0xff)

Every message has a start and end sequence

start = "\xa0\xa2"
end = "\xb0\xb3"

The payload is assembled with help from the documentation (only GGA, GSA and GSV messages enabled, 9600 baud)

payload = "\x81\x02\x01\x01\x00\x01\x05\x01\x05\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x25\x80"

Calculate 15 bit checksum:

checksum = sum(map(ord, list(payload))) & 0x7fff

Calculate the length of the payload

length = len(payload)

Assemble message:

message = start + pack(length) + payload + pack(checksum) + end

And after sending it as explained above the device will gladly output NMEA data.

View Comments

git colors!

categories: blog

wheeee! colors!

I was especially in the need of colors for git-diff.

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.ui auto
git config --global color.interactive auto
git config --global color.grep auto

one can certainly overdo it but I love colored output on my terminal :)

View Comments
« Older Entries -- Newer Entries »