Author Archive

OS X panics when inserting USB memory

Posted on the March 17th, 2009 under Computers,Mac by Martin Bergek

Suddenly my Macbook started crashing whenever I inserted a USB memory stick. Not just crashed – it completely froze.

iousbfamily-crash

The problem report report listed a module called IOUSBFamily and I had a vague idea that I had changed that some time back for something that had to do with my iPhone.

iousbfamily-report

It turns out the solution to the problem was rather simple. Just log onto Apple Developer Connection and search for IOUSBFamily and whatever version of OS X you are running. In my case I searched for “IOUSBFamily 10.5.6″.

Download the Mac OS X USB Debug Kit file for your version of OS X. The .dmg file will include the kernel extension with logging enabled as well as the standard one. Install the one without “log” in the file name. Then restart your computer. The problem should now be solved.

  • Share/Bookmark

Count number of bits in a Ruby integer

Posted on the March 11th, 2009 under Computers by Martin Bergek

How would one count the number of set bits in an integer? If it was a C/C++ application I guess I would do a for-loop and shift out the bits and keep a running sum. I would be hard pressed to do it in less than three lines of code and would probably do it in five to include the curly braces.

Given the same problem and having to find a solution in Ruby I came up with this:

v.to_s(2).split(//).inject(0) { |s,i| s + i.to_i }

In other words; first convert the integer to a binary string and split the string into an array. Then use the inject method to start with zero (remember even numbers are objects in Ruby) and iterate over the array with a code block, adding each digit in the binary string to get the total sum.

  • Share/Bookmark

Target fix for Statpress Reloaded

Posted on the March 3rd, 2009 under Computers,Linux by Martin Bergek

Statpress Reloaded by Manuel Grabowski is a nice and simple plugin that helps to keep track of the hit rate to WordPress blogs and is something I personally use it for this site.

statpress

Apart from the fact that the plugin is a bit slow it miscalculates the monthly target hit rates. This has been mentioned to the plugin maintainer but until that fix gets added, here is a short description and fix.

The following sections in statpress.php are repeated in four places and is used to normalise the number of hits so far this month over the entire month.

/ date("d", current_time('timestamp')) * date('d', mktime(0, 0, 0, date('m', current_time('timestamp'))+1, 0, date('Y', current_time('timestamp'))))

However, this uses entire days which leads to incorrect results. The error is more predominant early in the month and early in the days.

I have replaced the above segment (four instances) with this:

/ (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * 86400 * date('t')

This uses seconds since the beginning of month as the basis for normalisation which is more precise. It is not perfect – among other things it will fail exactly on midnight on the first of each month due to a divide by zero.

  • Share/Bookmark

Messenger for Mac signing out each night

Posted on the March 2nd, 2009 under Computers,Mac by Martin Bergek

Every night at precisely 01.00 CET (00.00 GMT) Messenger for Mac signs me out. When this happens a manual intervention is required in order to sign back in. I just can’t figure out why this is happening. The error message is “The system is unavailable now so you have been signed out of Microsoft Messenger”. I am running Microsoft Messenger for Mac version 7.0.1.
messenger-signout
messenger-version

  • Share/Bookmark

Increase upload size to Drupal site

Posted on the March 1st, 2009 under Computers,Linux by Martin Bergek

If you run a Drupal site and want to upload big files you may have run into the default file size limit of 1 MB. While this is probably fine for most blogs it is way too small for most intranet deployments.

The limit for PHP is by default set to 2 MB for file uploads.

To increase this to 10 MB, add the following to the .htaccess file in your Drupal directory or to the Apache site definition:

php_value upload_max_filesize 10M
php_value post_max_size 20M

More information can be found here.

  • Share/Bookmark

Using Drupal to run an intranet

Posted on the February 26th, 2009 under Computers,Linux by Martin Bergek

I have been looking for ways to replace a Sharepoint driven intranet with something else. The driving force behind this has mainly been one of platform compatibility. Sharepoint is great if you use Office and Internet Explorer on Windows. For all other users it is a usability nightmare.

There are lots of hosted or shrink-wrapped solutions for sale but the market of intranet solutions is now so mature that I felt there had to be open source solutions.

I found Alfresco, LifeRay and a few others and installed most of them. I was perplexed, however, by the sheer amount of features that were enabled out of the box. I really prefer something that starts off light and can then expand according to my needs. KnowledgeTree felt lighter but didn’t do much more than document management and I knew I also wanted a wiki as well as forums.

For a while I tried to integrate KnowledgeTree with MediaWiki and phpBB for a best-of-breeds solution. I couldn’t get all of the them to play nicely together and allow users to authenticate using accounts from a Windows Active Directory.

drupalorg

In the end I settled on Drupal. Why? It starts off light but has a truck-load of modules that can be added. I like the structure of the code. And it feels fresh – perhaps almost too light. I would have liked to see some professional free themes targeted for intranets, they would have helped to sell in the concept internally in competition with professional offerings.

The question of the authentication integration with Active Directory was solved very nicely by the module “Webserver authentication” and adding HTTP authentication to the web site in Apache where the web server is configured to use the bindings provided by Samba‘s WinBind. The only thing to remember is to set the Drupal administrator to the the same login name as the administrator in the Windows domain. After that you should disable the log out menu option in Drupal. The only thing remaining is to add some Javascript code to be able to provide a link to make the browser forget the cookie in order to force a relogin.

  • Share/Bookmark

Serial temperature sensor hardware

Posted on the February 26th, 2009 under Gadgets by Martin Bergek

I have been monitoring the temperature in my house using 1-wire sensors for some time. The easy way is to get a T-Sense and a LinkTH from iButtonLink. That would set you back $70 plus $15 per additional temperature sensor.

There is a cheaper option and that is to build the sensor adapter yourself and to base it on software that can send data on the 1-wire network with the require timings for the 1-wire protocol. Digitemp is a free application that can do this for Linux computers. This post is not about digitemp but rather about how to construct the hardware.

temp-schematics

temp-ds18s20

It only takes four diodes and a resistor and it is actually quite possible to make everything fit inside a D-Sub connector. The schematics is shown above. Note that only four of the nine pins on the connector are wired and to avoid any misunderstandings those four pins are 2 (RXD), 3 (TXD), 4 (DTR) and 5 (GND).

One note about how to connect the sensor. The ground and signal pins should of course be connected with the corresponding pins from the serial port according to the schematics above. In addition to that, Vdd must not be allowed to float so it should be connected to signal ground.

temp-photo

Here is a bill of materials for this construction. The article numbers are from Elfa, a Swedish distributor. The total cost for a sensor with a three meter cable runs at 137 SEK which amounts to roughly €12 (tax not included).

Item Description Article Price
D1 6.2V Zener diode 1N5234 70-054-08 1.34
D2 & D3 Schottky diode 1N5818 70-102-67 3.47
D4 3.9V Zener diode 1N5228 70-053-58 1.37
R1 Resistor 1.5kΩ 60-724-66 3.89
Sensor DS18S20 73-775-00 62.50
D-Sub 9 poles female soldered 44-055-02 9.61
D-Sub cover 44-130-19 12.90
Cable LiHCH 2×0.25mm2 55-780-00 10.40/m
Heat-shrinkable tubing 4.8mm 55-058-23 7.61/m

  • Share/Bookmark

Saving a clip from YouTube

Posted on the February 26th, 2009 under Computers,Mac,Music by Martin Bergek

It’s gearing up to be a very nice spring for all die-hard fans of Depeche Mode. There are clips on YouTube of their next single – Wrong – and it totally rocks!

dm-wrong

So, how to get this onto my iPhone to be able to pass the time until April 20th when their next album “Sounds of the Universe” is to be released?

It turns out it to be quite easy. There are a number of Firefox add-ons that claim to be able to download content from YouTube. I imagine YouTube isn’t too happy about people downloading content and keep trying to shut down options to circumvent it. I found that the add-in “Fast Video Download” did wonders. The add-on adds the icon in the bottom-right corner of Firefox in the screenshot above.

isquint

The output from the add-on is the Flash video file with a .flv extension. This then needs to be converted to avi format. Now there are many applications that claim to do this and they all charge around $30-40. iSquint does a terrific job and it is for free. The applications has actually been discontinued but it is still available for download.

  • Share/Bookmark

Garmin Edge 705

Posted on the February 23rd, 2009 under Gadgets by Martin Bergek

Thanks to my brother I have taken up biking and will, together with him, participate in Vätternrundan, the traditional Swedish bike race over some 300 km which takes place on the second Saturday of June every year.

Little did I realise just how much of a gadget sport this is. I have now settled for a Nishiki Competition Carbon, an indoor trainer and some racing shoes.

To be able to track my progress, I also wanted to get a biking computer. My short list included various bike computers from Polar, Suuntu and Garmin. I ditched Polar and Suuntu when I read that they have poor Mac support. The question that remained was which Garmin model and in the end I settled on the Garmin Edge 705 with the biking kit.

Edge 705

Edge 705 sensors

Garmin Edge 705 with the biking kit comes with pulse, cadence and speed sensors. It also has a built-in GPS.

After having used it for a few weeks on my trainer I think it has a lot of nice features and it actually works quite well with my Mac for day to day activities like syncing exercises with the Garmin Connect online service. A Windows computer is required to manage the maps so before the snow melts and the roads are cleared of sand I will have to dust off an old Windows computer and fix that.

The interface is just as non-intuitive as one could expect from a non-Apple device, but it is not too bad. There are some things, however, where Garmin don’t seem to have finished their testing. One such thing is the handling of metric/imperial units. One of the first things I changed was to set it to use metric units. Even so, the preset distances for exercises are in multiples of miles, not kilometers. Fix it Garmin!

Garmin Connect

The online service Garmin Connect is a nicely designed solution that can play back old exercises. It reminds me somewhat of the Nike+ site. My only worry is that it appears a tad slow and I hope Garmin has designed and dimensioned it so that they do not run into the roof when more people start uploading their exercises.

All in all, this is a nice product that does the job. As far as cycling computers go I would give this a 4/5 rating. An easier and more consistent GUI and 100% Mac compatibility are the things I would like to see improved.

  • Share/Bookmark

Accessing an Oracle database from Perl

Posted on the February 23rd, 2009 under Computers,Linux by Martin Bergek

In the previous post I described how to install the Oracle Database 10g Express Edition on Ubuntu and to add some data. In this article I will show how to access that data from a Perl script.

I assume you already have Perl installed, together with the DBI framework for generic database support. We will need to add DBD::Oracle which is available from CPAN. To install this module, run this as root:

# perl -MCPAN -e shell
cpan> install DBD::Oracle

Two things are worth noting. First, the root user must have the same Oracle environment set as described in the previous article. Just issue ‘source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh’ to fix that. The second thing to note is that you will most likely get errors during testing of the newly built module which will prevent it from being installed. To override that you will need to add ‘force’ before the command, i.e.:

cpan> force install DBD::Oracle

Now, the groundwork is done and we just need to write the script. Save this in oracle_read.pl and make it executable.

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect( 'dbi:Oracle:xe',
      'scott',
      'tiger',
      ) || die "Database connection not made: $DBI::errstr";

my $sql = qq{ SELECT id,name,age FROM persons };
my $sth = $dbh->prepare($sql);
$sth->execute();
my($id, $name, $age);
$sth->bind_columns(\$id, \$name, \$age);

print "List of persons:\n";
while( $sth->fetch() ) {
    print "$name [$age]\n";
}
$sth->finish();
$dbh->disconnect;
  • Share/Bookmark