Category Archives: Computers

Yosemite desktop clock

yosemite-desktop-clock

The desktop is a very underused resource on many computers. It often just sits there as a backdrop to files and folders. But using the tool Geektool on OS X the desktop can be put to very good use.

Personally have have a big clock in the lower left corner of my desktop. I have done this by just dragging two shell script boxes from the Geektool application. In these two I run the following two shell commands respectively:

date '+%A, %b. %d'
date '+%H:%M'

yosemite-desktop-clock-boxes

I use the font Lucida Grande regular and set the font colour to white. For the date I use the size 24pt and for the clock 96pt. I then set the clock to update every ten seconds and the date to update every five minutes. With this I could potentially disable the clock in the menu bar but I have chosen to keep it there for those times that the desktop clock is obscured by windows.

In addition to this I also use this method to display an always up-to-date text based todo list right on the desktop of my various computers.

Switch BU-353 to NMEA mode

BU-353 is a nice little USB based GPS receiver that I use for several types of project. Straight out of the wraps it defaults to outputting NMEA data at 4800 baud which is exactly what I want. However, it also supports the SIRF binary protocol and may switch to that format. This can happen if you connect it to a system that uses gpsd. That daemon supports both the NMEA and the SIRF protocol but will switch the GPS to the latter if it can.

So how do you switch it back? Maybe you can just leave it be and the supercap inside will discharge and it will revert to its default settings. The FAQ kind of hinted at that. However, I wasn’t patient enough to see if that works so I needed a quicker option.

It turns out that if you use Windows it is not too difficult. You can follow any one of several guides on the net, for instance this, straight from the horse’s mouth.

But I needed a way to do this from Linux and this is how.

First make sure you have gpsctl in your path. If it is not installed you can install it by running:

sudo apt-get install gpsd-clients

I am doing this on an Ubuntu system but it should work on most Debian derivatives.

Then connect your BU-353 and type (assuming that your GPS device turns up at /dev/ttyUSB0):

sudo stty -F /dev/ttyUSB0 4800
sudo gpsctl -n -D 4 /dev/ttyUSB0

Then it should be back on NMEA.

Run script on USB device insertion

Udev is a device manager for the Linux kernel and can be of great help to trigger activities when devices are added or removed. Once such scenario could be to run a script when the user connects a USB memory stick.

The first thing necessary to write udev rules is to have information about the device to create filters. However, I had a hard time finding information about what filters were available when I wanted to write a set of matching rules that would not cause a number of false triggers. To do this use the following command (replacing the device name to whatever device you want information about):

udevadm info -a -n /dev/sdb1

The following is an example of a command that can be used to run a script whenever a USB device is inserted.

ACTION=="add",KERNEL=="sd?1",SUBSYSTEM=="block",RUN+="/usr/bin/usb_insert %k"

The parameter %k to the script will be converted by udev to the device that caused the event. Note that the line is wrapped here but must be stated as a single line in the system.

Access Windows servers from OS X

After a hiatus of a couple of years I have recently come back to working with Windows servers – besides OS X and various Linux distributions, which have been my usual working tools lately. I realised that my old tools to access Windows servers would no longer do the trick. The Microsoft Remote Desktop Connection Client for Mac was never really very good but I had become used to Cord and it, too, would no longer work.

RDP problem

Apparently the problem is due to a difference in protocols between the client and the server and the two couldn’t negotiate properly on what protocol to use. I first tried to modify the server to default to the old RDP protocol and not try TLS. I even kept a virtual Windows client at hand to run whenever I felt a need to connect to a remote Windows server.

It turns out the absolutely best solution in these cases is to use the Microsoft Remote Desktop app, available on the Mac App Store for free. It is truly a great application for this purpose and allows the user to keep a list of servers and connect to them quickly and easily. For the ultimate in user experience, run the Windows terminal full screen and use the three finger swipe to quickly switch between the remote server and the local OS X system. Sweet!

Git and Textmate

Since I started using git (and when using svn before that) I have always typed commit messages on the command line using the -m switch. While that works the usability is not exactly fantastic. The funny thing is that it is very easy to change. I do all my development on OS X and my text editor of choice is Textmate. With that combination it is just a matter of issuing the following command:

git config --global core.editor "mate -w"

This will also make it easier to abide by best practices about how to write commit messages.

Snappier virtual Ubuntu

The use of Unity as the default interface for later versions of Ubuntu is a welcome addition for some as it makes better use of limited screen sizes. But when Unity 2D was discontinued in Ubuntu 12.10 it caused problems for people, like myself, who keep a virtual Ubuntu installation at hand for those tasks that require a Linux system. Running Ubuntu 12.10 or later on VirtualBox will often result in terrible performance, making it virtually useless.

One solution is to stay with Ubuntu 12.04. But another solution is to fallback to the old interface. Luckily, this is very easy to do by installing the package gnome-session-fallback.

sudo apt-get install gnome-session-fallback

After having installed the package just log out. When logging in select the Gnome Classic interface from the login page. Subsequent logins will use the same interface as the previous session. It is also possible to change the default interface.

sudo /usr/lib/lightdm/lightdm-set-defaults -s gnome-classic

Create bootable Ubuntu USB stick

I don’t create bootable USB sticks that often but every time I do it I think that it’s harder than it really is and start to search the web for walkthroughs.

This post could also simply be written: Look at the Ubuntu download page.

Here is the process for OS X:

  1. Download ISO file of the operating system you want to put on the USB stick
  2. Open the terminal
  3. Convert the ISO file using the convert option of hdiutil: hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso
  4. Run diskutil list to get the current list of devices
  5. Insert the USB stick
  6. Run diskutil list again to determine the device node assigned to your USB stick
  7. Unmount the USB stick: diskutil unmountDisk /dev/diskN
  8. Write the image to the USB stick: sudo dd if=/path/to/disk.img of=/dev/rdiskN bs=1m
  9. Eject the USB stick: diskutil eject /dev/diskN

Install rmagick gem in OS X 10.8

When installing the rmagick gem under OS X 10.8.1 (Mountain Lion) I got the following error on a system using RVM, Ruby 1.9.2 with ImageMagick installed through Brew.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
...
checking for stdint.h... *** extconf.rb failed ***
...

The error appears to be due to some issues with the OpenMP implementation in OSX. The solution that worked was to uninstall ImageMagick, then reinstall it without OpenMP support:

brew uninstall imagemagick
brew install imagemagick --disable-openmp

Since I didn’t have X11 on this computer I got warnings about missing X11 and had to dismiss a number of dialogs during compilation. But it went through and seems to be working. At least I could then do a bundle install on my Rails application.

Your own URL shortener

I use mostly bit.ly for shortening URLs but sometimes you don’t want to be dependent upon a public site, even if it is big and popular. I needed to install a custom URL shortener and this is what I did.

Firstly, my requirements were that it should be lightweight and simple. I didn’t expect that many hits on the URLs and even though I am a big fan of Ruby on Rails the idea of spinning up a Rails site just to dish out a HTTP redirect didn’t sound like a great idea. Instead I went for PHP backed by a MySQL database.

Now, searching for URL shorteners written in PHP results in a large number of hits and it can be pretty daunting to know which to pick. Shortly and Yourls were frequently present in listings of popular shorteners so I decided to setup those and benchmark them. However, the Shortly web site turned out to be unavailable so in the end I settled on just installing Yourls.

Yourls supports both public and private mode of operation. In private mode a password is required to administer it. In my case I wanted to make it simple and allow everyone at the company to manage the URLs but disallow access to the management facilities from the Internet. However, Internet users still need to be able to resolve the URLs. I solved this via conditional rewrites in the Apache configuration, like so:

	Alias /s/ "/srv/www/shortener/"
	RewriteCond %{REQUEST_URI} ^/s/admin
	RewriteCond %{REMOTE_ADDR} !^192\.168\.(\d+)\.(\d+)$
	RewriteRule ^/.*$ - [F]
	RewriteCond %{REQUEST_URI} \+$
	RewriteCond %{REMOTE_ADDR} !^192\.168\.(\d+)\.(\d+)$
	RewriteRule ^/.*$ - [F]
	RewriteCond %{REQUEST_URI} ^/s/[index.php]?$
	RewriteCond %{REMOTE_ADDR} !^192\.168\.(\d+)\.(\d+)$
	RewriteRule ^/.*$ - [F]

The above is from the config file for the corporate web site, lodging the URL shortening under the /s/ subdirectory of the web site. There are three rewrite rules:

  • Preventing access to the admin pages for external clients
  • Preventing access to the link statistics for external clients
  • Preventing access to the link creating page for external clients

By default Yourls will create sequential links starting from one and going up. This makes it trivial to guess other links which is not what I wanted. Fortunately, it turned out to be very simple to create random links by following the instructions found on this page.

I am quite happy with the result. I wish the default web GUI would come with different themes but since it is only used when administering the links it doesn’t really matter. I will continue to use bit.ly but Yourls is definitely a keeper.

Convert Rails 3 project to use jQuery

Rails 3 supports unobtrusive javascript to decouple the content from the logic in a way similar to how CSS has helped web designers to decouple the content from the layout.

By default Rails 3 comes with Prototype. But more and more people are switching to jQuery. The project Rails-3-jQuery on Github simplifies the process of switching out the Prototype support to jQuery. It includes jRails that provides drop-in replacements for Prototype and Scriptaculous helper methods to make it a seamless transition.

To update a project, just issue the following command in the project root

rake rails:template 
   LOCATION=http://github.com/lleger/Rails-3-jQuery/raw/master/jquery.rb

For more information on the project, check the project page on Github.