eject
Fri, 03 Jun 2011 23:21 categories: codeA friend of mine recently gave me her Huawei E1550 umts modem and as many
others it first presents itself to the operating system as a usb cdrom drive.
It will only switch to serial modem mode when the cdrom is ejected. For this to
happen you can fire the eject
command and you are done. Since I was curious
how linux would eject a cdrom and how eject
really works I investigated and
found that I can replicate the eject
behavior with this C snippet.
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <linux/cdrom.h>
int main() {
int ret, fd;
fd = open("/dev/sr0", O_NONBLOCK);
if (fd == -1) {
perror("open");
return EXIT_FAILURE;
}
ret = ioctl(fd, CDROMEJECT, 0);
if (ret == -1) {
perror("ioctl");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
or alternatively with this python oneliner:
python -c "import fcntl, os; fcntl.ioctl(os.open('/dev/sr0', os.O_NONBLOCK), 0x5309, 0)"
css media queries
Thu, 02 Jun 2011 04:44 categories: blogWhen 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.