Tag Archive for 'ubuntu'

Favorite USB wireless card for Ubuntu?

Dear LazyWeb,

Do you have a favorite USB wifi network card for a laptop running Ubuntu?

Sincerely, Xaprb

Technorati Tags:, ,

You might also like:

  1. Ubuntu on Dell Inspiron 1501
  2. Anyone want to help build RPMs of Maatkit?
  3. Why I (still) like Gentoo
  4. How to set up Gentoo wireless networking on AMD64
  5. Credit card expiration dates should conform to standards

How I built the NOW_USEC() UDF for MySQL

Last week I wrote about my efforts to measure MySQL’s replication speed precisely. The most important ingredient in that recipe was the user-defined function to get the system time with microsecond precision. This post is about that function, which turned out to be surprisingly easy to write.

The manual section on user-defined functions provides very good instructions on how they work and how to build them. But just for the record, on Ubuntu 7.04 on an AMD64 machine, all I had to do was install the libmysqlclient15-dev package, and I was then able to compile the UDF with no further ado. Also for the record, MySQL header files have some dependencies they shouldn’t that break building against a downloaded tarball. So don’t be surprised if you have troubles building against anything but Ubuntu’s provided header files.

Here’s the source, which I basically cribbed from a NOW_MSEC() function I saw in a bug report somewhere. Really, there’s not much to it besides the basic skeleton of a UDF, with a few lines to actually get the system time. And I actually believe if I took another ten minutes to learn about strftime(), there’s probably no need to do it in two steps; I could probably do the whole thing with one strftime() call and save a little memory and time. But that’s what I get for copying and pasting code of unknown quality:

#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>

#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

extern "C" {
   my_bool now_usec_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
   char *now_usec(
               UDF_INIT *initid,
               UDF_ARGS *args,
               char *result,
               unsigned long *length, char *is_null, char *error);
}

my_bool now_usec_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
   return 0;
}

char *now_usec(UDF_INIT *initid, UDF_ARGS *args, char *result,
               unsigned long *length, char *is_null, char *error) {

  struct timeval tv;
  struct tm* ptm;
  char time_string[20]; /* e.g. "2006-04-27 17:10:52" */
  char *usec_time_string = result;
  time_t t;

  /* Obtain the time of day, and convert it to a tm struct. */
  gettimeofday (&tv, NULL);
  t = (time_t)tv.tv_sec;
  ptm = localtime (&t);   

  /* Format the date and time, down to a single second.  */
  strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm);

  /* Print the formatted time, in seconds, followed by a decimal point
 *      and the microseconds.  */
  sprintf(usec_time_string, "%s.%06ld\n", time_string, tv.tv_usec);

  *length = 26;

  return(usec_time_string);
}

The installation looks like this:

baron@tigger now_usec $ make
gcc -fPIC -Wall -I/usr/include/mysql -shared -o now_usec.so now_usec.cc
baron@tigger now_usec $ sudo cp now_usec.so /lib
baron@tigger now_usec $ mysql test
mysql> create function now_usec returns string soname 'now_usec.so';
Query OK, 0 rows affected (0.00 sec)

mysql> select now_usec();
+----------------------------+
| now_usec()                 |
+----------------------------+
| 2007-10-23 10:28:13.862116 | 
+----------------------------+

For those who have reached this page via Google searches and are looking for more information, you should check out the MySQL User Defined Function Library project. Lots of good UDFs there.

Technorati Tags:, , , , , ,

You might also like:

  1. How fast is MySQL replication?
  2. More alternatives to openxml
  3. A bug in Microsoft SQL Server’s replace() function

How to set up dual monitors in Ubuntu on Dell Inspiron 1501

It took me about five minutes to get dual monitors working on my Dell Inspiron 1501 under Ubuntu 7.04. Here’s how I did it.

  1. I tried the xorg driver, which had been working fine on just the laptop display, but it wouldn’t work; I could get either the external display or the internal display to show, but not both. If you get it working, post a comment and let me know.
  2. I enabled the proprietary driver via Ubuntu’s Restricted Drivers Manager.
  3. I read the Gentoo Wiki page on dual monitors.
  4. As root, I ran
    aticonfig --initial=dual-head --screen-layout=above -v
  5. I rebooted.

At the moment, I’m typing into Firefox on the laptop monitor. My Dell 1800FP monitor is perched right above it; it’s the same width in pixels, and almost the same physical width. I have no windows open on that monitor, but I do have a nice background image! XFCE configures the backgrounds for each display separately.

I’ve been using this setup for about a week now. It’s not flawless, but the flaws don’t get in my way much. Here are the problems I’ve noticed:

  1. The driver is proprietary. Okay, this is a major flaw.
  2. The driver doesn’t work perfectly. Occasionally a weird defect in the screen image appears and won’t go away until X is restarted. It looks like a bar code and usually shows up near the bottom right of one of the monitors, often right over the clock in my system tray.
  3. If I log out of XFCE, my system hangs and I have to use the Alt-PrntScrn keys to shut it down and restart it.
  4. When I start my laptop, only the display on my laptop shows anything (perhaps the login screen isn’t dual-monitor capable). As soon as I log in, both monitors become active. While this is happening, my mouse randomly jumps between the top-left corner of the two monitors.
  5. The two monitors are running two different X displays. I’m not crystal-clear on how this should normally work, but I get the idea Xinerama isn’t the same as this and should work better (I don’t know if I can set up Xinerama with the proprietary driver, but I don’t think so). This has a variety of side effects:
    1. Windows I open on one display can’t be moved to the other (oddly, I can drag and drop between displays, which I didn’t expect).
    2. I can’t alt-tab to the other display.
    3. When I click on a link in Thunderbird, if Firefox is running on the other display, it says Firefox is already running but not responding, and refuses to open the link. I can’t get Firefox running on both displays at once.
    4. My XFCE panel on the laptop display doesn’t show windows on the other display. I tried creating a panel for that display too (XFCE recognizes that there are two displays and lets me place the panel on either one), but I couldn’t place it at the bottom of the display. When I chose to place it at the bottom, it seemed to place itself 768 pixels from the top (the external monitor is 1280×1024, but the laptop display is 1280×768). So I placed it at the top of the display, added a taskbar applet to it, and voila I had what I wanted — but when I rebooted, the panel showed up on the laptop display again.

Otherwise I haven’t noticed any troubles. Anyone who has suggestions on these issues, feel free to post a comment!

Technorati Tags:, , , ,

You might also like:

  1. Ubuntu on Dell Inspiron 1501
  2. Firefox vs. Opera on slow hardware
  3. Favorite USB wireless card for Ubuntu?
  4. How much memory does MySQL Enterprise Monitor’s agent use?
  5. How to prelink mozilla-firefox-bin

Ubuntu on Dell Inspiron 1501

I recently bought a Dell Inspiron 1501, which I got a great deal on thanks to the fine people at DealNews. The base system was $449 shipped, and I chose to upgrade the processor to dual AMD64s. But I didn’t buy the system that came with Ubuntu pre-installed; for whatever reason, the one that came with Windows offered a special discount (normally the Windows tax for otherwise identical machines appears to be around $150, and I’m certainly not going to run Windows).

Therefore, I was not sure Ubuntu would support all the hardware. It’s the same story it’s been for as long as I’ve been using computers: hardware manufacturers withhold specifications from the Free Software world, so there is always a chance something will be a trouble. The good news is, I’ve only noticed two very minor incompatibilities out of the box.

One is that the Fn+arrow keys won’t change my screen brightness, at least under XFCE. Strangely, my ancient Dell laptop had no trouble with that. I assume the old one was a hardware-controlled feature and this one needs some software support, but I could be wrong.

The other thing is the built-in wireless card, which isn’t supported with Ubuntu 7.04’s drivers out of the box. However, I quickly found a set of drivers for the Broadcom Corporation Dell Wireless 1390 card, and was up and running shortly thereafter. The only thing I had to do after installing the drivers was press the Fn+F2 key, which turns the card on.

Otherwise everything works brilliantly.

And now for a rant: click through to that page about the drivers, and you’ll see an example of what I consider the Ubuntu sudo disease. There’s even a screenshot of someone typing sudo uname -a and using sudo to remove a file he didn’t create with sudo. I think unfortunately, Ubuntu’s policy of allowing one to run any command with sudo has created a crop of people who don’t understand what should and shouldn’t be privileged; some of them seem to believe that ’sudo’ is what you type at the beginning of every command. It completely defeats the purpose and circumvents the security gained by not running as root. For my part, when I want to administer my system, I become root, do what I need to do, and then quit again. I rarely sudo any command other than sudo su -.

But that’s just me.

Technorati Tags:, , , ,

You might also like:

  1. How to set up dual monitors in Ubuntu on Dell Inspiron 1501
  2. Favorite USB wireless card for Ubuntu?
  3. How to set up Gentoo wireless networking on AMD64
  4. Firefox vs. Opera on slow hardware
  5. Credit card expiration dates should conform to standards