All posts by Martin Bergek

Authenticate using Office 365

This is a extension to a previous post about creating a Rails web site that uses external OAuth providers to authenticate users. Until now the Rails template supported Facebook, Twitter, LinkedIn and Google OAuth providers. Lately I have added Office 365 support to the template available on Github. This could be useful for e.g. companies that want to develop web sites for internal applications and allow their internal users to log on using their standard accounts.

Azure portal

  1. Go to portal.azure.com & log in
  2. Expand “more services” and select “active directory”
  3. Choose “applications” and click “add” at the bottom (or click on ”
    Add an application you’re developing” if you are viewing the domain overview)
  4. Give your web application a name
  5. Enter a Sign-On URL and an App ID URL (e.g. http://example.com/users/sign_in). It is not obvious what the App ID URI should be but it seems to work fine to use the same as the Sign-On URL
  6. Configure the app and modify the reply URL to be e.g. http://example.com/users/auth/office365/callback/
  7. Copy the Client ID and add it to the Rails template
  8. Select duration under “keys”, press save and then copy the generated key to the Rails template

Finally, deploy your web site and hopefully it should work.

The time is 9:41

You may have noticed that the iPhone time on Apple presentations is always 9:41. How come? This goes back to when Steve Jobs launched the iPhone in 2007. At the time the time displayed was 9:42 and it was subsequently used for all promotional screenshots until the iPad was launched when the time was changed to 9:41.

Having a static time for all screenshots is good as it makes it easier to produce screenshots for presentations at different times and be able to combine them without the time jumping around. In addition it is also a nice historic reminder of the launch of the iPhone.

This is all very well, but how do you go about producing screenshots that mimic this behaviour. One option is to connect the iPhone to a Mac via USB and then run QuickTimePlayer on the Mac and start a recording. This will force the time displayed on the iPhone to 9:41, blank out any operator name and change the signal strength to maximum.

This works fine but requires a physical device. This can be tricky when submitting apps to the App Store and you have to provide screenshots for all various screen sizes. Another alternative is to download SimulatorStatusMagic, a free Xcode project on GitHub, compile it and install it in the various Xcode iPhone simulators.

Running the app in the simulator shows a GUI that allows the user to set the time, or use the default 9:41 time. Then switch to any other app in the simulator and take whatever screenshots are required.

Missing recipients when emailing group in OS X

Sometimes when emailing a group from the contacts application in OS X El Capitan one or more of the addresses will be missing from the recipient list in the mail application. The missing recipients can be added manually to the recipient list but they will be silently dropped when the mail application expands the group into its members.

It is very unclear why this happens but a workaround seems to be to delete the mail addresses from the failing recipient and add them again. After that, the group expands to the full list of members.

Still broken unison brew

I wrote in an earlier post about how the brew build of unison is broken due to it defaulting to ocaml 4.02. Back then it was possible to checkout an old version of ocaml but since then changes to brew seem to have closed that option. Instead of being able to use brew to install a particular version of unison I had to install it from source and include the correct version of ocaml. This is how I did it.

First uninstall any existing brew installations of unison and ocaml

brew unlink unison
brew unlink ocaml

Then download ocaml 4.01 and compile from source.

wget http://caml.inria.fr/pub/distrib/ocaml-4.01/ocaml-4.01.0.tar.gz
tar -xvzf ocaml-4.01.0.tar.gz
cd ocaml-4.01.0
./configure
make world.opt
sudo su
umask 022
make install
exit

Finally, download unison 2.40.102 and compile from source

wget http://www.seas.upenn.edu/~bcpierce/unison/download/releases/unison-2.40.102/unison-2.40.102.tar.gz
tar -xvzf unison-2.40.102.tar.gz
cd unison-2.40.102
make UISTYLE=text

The unison binary is in the current directory. Just copy it to a location within your path and you should be set to go.

Featured photo by Kuba Bożanowski (https://www.flickr.com/photos/jbozanowski/4132669334/).

Got a beeping disk? Don’t despair!

I had a power outage a couple of weeks ago and when the power came back up I noticed that one of my servers made a strange beeping sound that I had not heard before.

My first thought was that all the data was lost. I knew that there are professional services that may be able to recover data but that they are typically very expensive. This was a private server and most of the data had been backed up anyway so paying that sort of money to salvage the disk was not an option I considered.

As it turns out, this particular issue is actually quite simple to solve by almost anyone. The only thing you need is a T6 torx screwdriver, a clean surface, a toothpick, a steady hand and some luck. It also helped that the data was not extremely valuable for me. I would perhaps not recommend this procedure if you care very much about the data on the disk. In that case it may be better to pay up. You can definitely make things worse. Don’t say I didn’t warn you.

Note that these instructions only apply if the disk beeps like in this audio clip. If the disk makes a more mechanical noise then the error is caused by some other issue and you should not follow these instructions as they could worsen the situation.

When the disk is beeping with a steady period (typically around 1Hz) it typically means that the disk head is not in its parked position when the disk is about to spin up. Normally the head moves away from the disk before the disk is shut down and does not move in over the platters until they are spinning at full speed. The rotating disks create an air flow that acts as a cushion for the heads so that they do not touch the surface. If the heads are over the platters when the disk is off then the disk will just refuse to spin up.

To fix the issue one just needs to open the hard drive and gently move the head to its parking position while at the same time turning the platters counter-clockwise.

The lid covering the internals of the drive is usually held in place by seven screws. Six of those are along the edge and readily visible. The seventh is in the centre of the disk head arm and normally covered by a sticker.

You may be concerned about opening up the disk outside of a proper clean room. While it is true that the internals of the disk are delicate you should not be too concerned. The disk is constructed to be able to handle small amounts of dust that could be released from the internals of the disk during operation. The white item in the bottom right on the photo is a filter that is there to catch dust particles. The heads do not leave their parking position until the disk it at full speed and their speed creates an air flow that should remove any dust from the disk and deposit it on the filter.

When you move the head back it may feel like it is stuck at first due to static electricity. Just rotate the disk counter-clockwise while you gently move the arm back and you should be fine. I found that a toothpick is a good tool for this. The image below shows how the arm should be positioned when you are done. Then just put the lid back on and keep your fingers crossed.

If it worked then congratulations. But make sure to copy the data to a new disk and consider the old disk used, never to be trusted again.

HD OK

Watch out for Apple Watch

Almost exactly eight years ago the late Steve Jobs presented the iPhone at MacWorld 2007. “It’s a widescreen iPod with touch control, a revolutionary mobile phone and a breakthrough Internet communications device”. The audience was enthusiastic, yet very few fully realised the impact this would have on an entire industry. As a phone and compared with what we have today it was lacklustre. There was no app store, that was to come much later. And as far as connectivity goes it was inferior to other phones, having only 2G connectivity. You could not copy and paste text when texting or writing email, nor attach photos. Which was probably just as well, since the camera was only 2MP and produced rather ordinary photos and no video. And, like the T-Ford, you could have any display background you wanted as long as you wanted black.

We all know what happened. The iPhone improved by leaps and bounds. An app ecosystem virtually exploded around it. The connectivity has since vastly improved and the performance is now hugely better thanks to Moore’s law. In the process it completely obliterated a number of industries and companies. Nokia, the biggest phone manufacturer at the time the iPhone was introduced has since succumbed due to their inability to see and act on the shift in their industry. But the impact of the iPhone was not limited to the mobile phone industry. The iPhone is today the go-to-camera for most people and there is now very little need for a standalone GPS to find your way.

Apple Watch

This spring Apple will release the Apple Watch to the world. And even though it mostly likely is a magical device that will find its place on the arms of many people (mine included) it is probably wise to see the future evolution of Apple Watch in the light of the history of the iPhone. It may not take eight years for the Apple Watch to find its true form but we will no doubt look back on 2015 a few years from now and realise the shortcomings of this, the first generation of the Apple Watch.

The Apple Watch of 2020 will no doubt be very much thinner than the first generation, charge seamlessly and run for weeks on a charge, be connected with everything around you and have a colour display that is always on. The first generation will require a phone to run apps but it is not hard to imagine that this requirement will be dropped in later revisions. When this happens it will be the beginning of the end for other watch-like offerings for runners, golfers etc.

Make no mistake. The release of the Apple Watch this year is not just for a watch but of a new product segment that will profoundly change several industries just like the iPhone has done before it. Many companies that fail to transform their business will go under but many other companies will flourish based on applications that we have yet to imagine.

Now, I just hope that spring comes early this year.

Ubuntu wallpapers

For every version of Ubuntu there is a set of wallpaper images. Each version has its own set and doesn’t include the old ones. However, it is very simple to install all previous versions by running:

apt-cache search ubuntu-wallpapers- | awk '{ print $1; }' | xargs apt-get -y install

As of today (January 2015) this will install the wallpapers from:

  • Karmic (9.10)
  • Lucid (10.04)
  • Maverick (10.10 LTS)
  • Natty (11.04)
  • Oneiric (11.10)
  • Precise (12.04 LTS)
  • Quantal (12.10)
  • Raring (13.04)
  • Saucy (13.10)
  • Trusty (14.04 LTS)

If you want to use them for other purposes you will find the images in /usr/share/backgrounds/. I use them as wallpaper in OS X. In return I may just use the Yosemite wallpapers in Ubuntu to really confuse people.

Broken unison brew on Yosemite

I rely on Homebrew for many of the command line tools I use on my computers. One such tool is unison, a powerful synchronisation application for keeping files in synch. I use it as a way to allow me to work on any one of my computers with maintained security and without having to send my files to a cloud provider. These days there are several alternatives with Bittorrent Sync as probably the best option.

One caveat with unison is that it requires all peers to use the same version of the binary. But with a limited number of peers this is not a major issue.

For a long time I just used precompiled binaries for OS X and Ubuntu using the same unison version. Then, as I reinstalled the Ubuntu server and got a newer version I realised that this was the same version (2.40.102) that was installed with brew so I ditched the previous binaries and installed unison using brew instead. That worked for two OS X computers but on the third one I got an error when synchronising the files:

Uncaught exception Failure("input_value: bad bigarray kind")

This exception occurred on a completely reinstalled Macbook. The exception seems to be caused by unison using an incompatible version of ocaml compared with the ones on my other computers (the brew version is compiled against ocaml v4.02 while my other clients were using 4.01).

As I see it there are two potential solutions to this problem:

  1. Upgrade all peers to the new ocaml version
  2. Build a version of Unison using the older (<4.02) version of ocaml

For this article I chose the latter alternative.

First, I needed to install version 4.01 of ocaml. Brew will by default use the most recent stable version (right now 4.02) but can be made to install older versions if required. To list the existing versions run:

$ brew versions ocaml

4.02.1   git checkout a772c80 /usr/local/Library/Formula/objective-caml.rb
4.01.0   git checkout 924387b /usr/local/Library/Formula/objective-caml.rb
4.00.1   git checkout b04e346 /usr/local/Library/Formula/objective-caml.rb
4.00.0   git checkout e2140fd /usr/local/Library/Formula/objective-caml.rb
3.12.1   git checkout df16522 /usr/local/Library/Formula/objective-caml.rb
3.12.0   git checkout 0476235 /usr/local/Library/Formula/objective-caml.rb
3.11.2   git checkout ed51a5b /usr/local/Library/Formula/objective-caml.rb

If the versions command above shows ‘Error: Unknown command’ then just run

$ brew tap homebrew/boneyard

After that, run the versions command again and it should work. This will display a warning that brew-versions is unsupported. Ignore this for now and notice the line with version 4.01.0.

$ cd `brew --prefix`/Library
$ git checkout 924387b /usr/local/Library/Formula/objective-caml.rb
$ brew install ocaml

Now we should have ocaml v4.01.0. Then, compile unison from source in a temporary directory that you can remove afterwards:

$ cd /tmp
$ wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-2.40.102/unison-2.40.102.tar.gz
$ tar -xvzf unison-2.40.102.tar.gz
$ cd unison-2.40.102
$ make UISTYLE=text
$ sudo cp unison /usr/local/bin/

Now you should have a working unison installation using ocaml 4.01.0

Featured photo by Giuseppe Milo (https://www.flickr.com/photos/giuseppemilo/15602907800).

Android and iOS version distributions

When writing apps for Android and iOS it is important to keep in mind the different versions of each system. You want to use new cool features that are available in later versions but you do not want to alienate too many users by using features that are not compatible with their phones.

The Android documentation recommends developers to ensure that the app is compatible with at least 90% of active devices. For Android this currently means that the app must support all versions going back to Ice Cream Sandwich (version 4.0.x). This is the fifth latest release including Kitkat (version 4.4)

Android version distribution

Version Codename API Distribution
2.2 Froyo 8 0.5%
2.3.3 -2.3.7 Gingerbread 10 9.1%
4.0.3 -4.0.4 Ice Cream Sandwich 15 7.8%
4.1.x Jelly Bean 16 21.3%
4.2.x 17 20.4%
4.3 18 7.0%
4.4 KitKat 19 33.9%

Meanwhile, when developing for iOS targeting iOS 7 means that 96% of users can run your app as of today. This also means that iOS developers can focus on a more modern UI and not having to create separate look-and-feel to cater for very different operating systems. Android 4.0.3 was released in October 2011 while iOS 7 was released almost two years later in September 2013.

iOS version distribution

Data is current as of January 4th 2015. For more information and up-to-date statistics, check the developer pages for Android and iOS.