Saturday, October 26, 2013

Turning your Mac into an Ubuntu server

I have the original Mactel Pro 1,1. It has been a very trustworthy machine, even better than my MBP 8,2 which has fan issues... However, with OS X support stopping at Lion and a 32-bit EFI, the writing is on the wall. So I decided to turn it into an Ubuntu file and media server.

Linux has come a long way both in maturity and adoption since my first aborted effort with RH Linux eons ago. I love that you essentially don't need Microsoft or Apple anymore except that Apple still makes the best hardware for your money. Anyway, back to topic...

Dual-boot your Mac

The first thing you have to do is to make your Mac dual-bootable. With Macs, and with old Macs, this can be challenging. However, here is it distilled (in a Frankenstein-ish sort of way):
  1. In Mac OS, open a terminal window and type: "ioreg -l -p IODeviceTree | grep firmware-abi". If is says EFI32 like mine does, you can only install a 32-bit version of Ubuntu. I wasted a few DVD-ROMs before figuring this one out.
  2. Get Ubuntu and burn a bootable disk onto a DVD-ROM. I used 13.10 desktop. Follow these instructions to make your disk.
  3. Follow the directions here under "Dual Boot" > "Quick steps". Remember to first install rEFIt while still in Mac OS. It's brief but easy to follow. Mid-way through it becomes inaccurate. Some helpful hints here:
    • 13.x doesn't seem to have the "System" menu (or at least I couldn't find it...). Click on "Search your computer...", type "Terminal", open that, and type "sudo gparted". Helpful hint: gparted seems to only be available in the "Try Ubuntu" stage. If you want partition management after fully installing, you need to install it using "sudo apt-get install gparted"
    • When prompted, select "Something Else" then move to my next step...
  4. Once you're in gparted, the previous post breaks down quickly. Pick up the instructions here and scroll down to the first comment, which is the "accepted" answer.
  5. Ease on through the setup and when prompted to automatically download updates or sign into Ubuntu One, decline everything possible. A hang-up in any step will force you to do a hard reset and restart the installation process.
Most importantly, remember that Command-C is now Control-C. Gar.

Install Samba

I want to share my filesystem with other computers including (gag) Windows.  I typically run Windows-only software in VMWare Fusion and would like the files to be commonly accessible to all computers.

This document is a good summary of how to make that work and no re-booting is required to test it.  The limitation is that it doesn't include user-specific authentication, which is essentially part 2.

Install SSH

Of course, you will want to be able to administer a headless system.  This post describes it very succinctly.

Setup VNC

VNC is not recommended unless you are sure of your firewall, and only then, it should be between computers within your network.  If that's true, then enable "Desktop Sharing" by searching for "vino" (in Ubuntu).  A common Mac OS VNC client is Chicken of the VNC.

That's the basics!  In my case, I converted a second Mac OS hard drive to be used as a backup filesystem (since this is a file server after all...) but those details are not in the scope of this entry.

Friday, December 23, 2011

Getting started with Grails (again)

Well, it's been a while since I had looked at Grails. In addition to being busy and not having a need for it, I was worried about Grails' future given Spring Roo's existence. However, I am no longer worried (for now). Grails 2.0.0 RC3 is now available and it seems that VMWare is committing itself to both Grails and Roo with the acknowledgement that they provide solutions for different audiences.

I have been updating this post to keep the information in one place so it has grown substantially. It should be a great reference for anyone who is new to Grails and looking to create a site from scratch.


  1. Download SpringSource Tool Suite 2.8.1 if you haven't already done so. It's free! I've found that the embedded vFabric tc Server works better on Linux than on Mac OS. Not sure why...
  2. Install Groovy, Grails, and make sure you have JDK 1.6

Getting Started

  1. Follow this beginners' tutorial. It's easy to follow and is relevant. In particular, I like how he introduces BootStrap.groovy, which is a way to pre-populate your data between recompiles
  2. This is another beginners' tutorial but it's wordier and harder to follow if you have little patience
  3. When learning how to do unit testing, simply remember that the tests automatically generated for you will fail. You need to edit populateValidParams() with at least one valid record. Also, this page is a concise tutorial on unit and integration testing
  4. If you are interested in using HAML, you need to install the plugin for each Grails project. Simply type, "grails install-plugin haml". Here is some more information. If your page is normally called "list.gsp", your HAML file should be named "list.haml".
  5. Here is an HTML to HAML converter. It works well but there may be a few bugs. I found it doesn't handle the "page import" statement or ternary operators well.
  6. All things Groovy... Ever seen a closure? Did you know that Groovy has a full API doc? Also, there are a few differences between Groovy and Java but not many.

Rich Internet Application

  1. A great way to incorporate user security (login/logout/authentication) is by using the Grails plugin for Spring Security. I chose to create my own User class by extending the SecUser class and Static URL rules.
  2. When you want to extend your controller output to provide XML or JSON (say you're building an API...) then this is a great tutorial. To test your controller, use curl:
    curl -v -L http://localhost:8080/Grails1/user/show/1.json
  3. As of Grails 2.0.0, the default JavaScript library is jQuery, not Prototype. This is a good tutorial on using AJAX with Grails and this post suggests the correct way to configure jQuery for Grails 2.0.0


  1. Heroku is a great way to setup a development server, and if your needs are limited, then it's free! To get started with Heroku, follow these setup directions. To deploy a Grails application, use the Grails Heroku plugin. I discovered that, for these instructions to work, you should initialize your Grails app using the command line, not by creating a "New" > "Grails Project" in STS. There is a supplemental instruction here to configure your Grails app to use a Postgres database.
  2. To publish your app to Heroku, you will need to use Git. I highly recommend Git in any case as a cheaper alternative to Perforce, SVN, and CVS. There is a learning curve but it is available out of the box if you have installed SpringSource ToolSuite (STS) on Ubuntu and there is a lot of good documentation. Here is a tutorial and a quick reference. An added bonus is that STS comes pre-installed with EGit -- the Git plugin for Eclipse.
  3. Heroku's signature database service is PostgreSQL. If you want to test your Grails application locally using the same database, this is a great beginner's tutorial to install and set up a Postgres server on your Ubuntu machine.
  4. If you want to use MySQL, install a local server using
    Be certain to provide a root password because MySQL Workbench does not permit blank passwords. This post describes how to set up MySQL with your Grails app and this post describes how to use the ClearDB addon. Follow these instructions for your DataSource.groovy

Thursday, November 24, 2011

Android: java.lang.IllegalStateException: Target host must not be null, or set in parameters.

I must admit that I spent more than 20 minutes on this issue. Oddly enough, this exception does not occur when launching a Widget for the first time -- it only happens after you remove the widget then restore it. That is why I'm a little perplexed as to why it happens in some cases but not in others. Anyhow, this post describes the problem and the resolution accurately. After reading this blog, the issue went away in, oh... 30 seconds.

Monday, November 21, 2011


This was a vexing issue with a simple solution. Basically, I attempted to install an APK on a real device and received, "". Since I had never installed it previously, I was perplexed, but I tried renaming the APK, using "adb uninstall", all without success.

Then, this solution simply suggested that you install over the previous installation (as absurd as that sounds). Fortunately, it worked like a charm.

Wednesday, October 12, 2011

Using Pointers to Pointers for Linked Lists

I was reading up on Linked Lists and came across a great description on the meaning of Pointers to Pointers. As pointers and I have a love/hate relationship, I found this post very insightful and easy to understand. In the code I wrote to create and print a Linked List, I found it necessary to use a Pointer to a Pointer because the pointer to the "head" node of a singly linked list needs to be defined (and accessible) by the main() routine.
#include <iostream>
#include <cstdlib>

using namespace std;

typedef struct Node {
    int value;
    struct Node *next;
    struct Node *prev;
} NodeType;

void addNode(struct Node **head, int value);
void printList(char *listName, struct Node *head);

int main() {
    NodeType *head;
    head = (struct Node*)NULL;

    addNode(&head, 1);
    addNode(&head, 10);

    printList("myList", head);

    return 0;

void addNode(struct Node **head, int value) {
    NodeType *temp;
    NodeType *cur;

    temp = (NodeType*)malloc(sizeof(NodeType));
    temp->next = NULL;
    temp->prev = NULL;
    if(*head == NULL) {
        *head = temp;
        temp->value = value;
    } else {
        for(cur = *head; cur->next != NULL; cur = cur->next);
        cur->next = temp;
        temp->prev = cur;
        temp->value = value;

void printList(char *listName, struct Node *head) {
    NodeType *temp;
    cout << listName << endl;
    for(temp = head; temp != NULL; temp = temp->next) {
        cout << temp->value << endl;
    cout << "End" << endl;

Monday, August 15, 2011

Mac OS - Opening a new browser window from within a WebKit WebView

If you Google "createWebViewWithRequest", "WebView open new window", "decidePolicyForNewWindowAction" or check out the Apple Developer Documentation on Opening Multiple Windows using WebKit, there is a lot of chatter on the difficulty of getting such a supposedly simple thing to occur.

The objective is this: You programmatically create a WebView and load standard HTML/JavaScript/CSS into it. You want to click on a link in your WebView which launches a new browser window to any URL of your choosing.

Amazingly, I haven't seen a single post that gave a simple answer to such a simple question...

Here it is in a nutshell:
  • No, you don't need to specify the WebPolicyDelegate as follows:
    @interface MyIAppDelegate : NSObject <NSApplicationDelegate, WebPolicyDelegate> {
    Some delegate are assumed and don't need to be declared. In fact, you get a compiler error if you try
  • Create your WebView in IB, add this line to MyAppDelegate:
    @property (assign) IBOutlet WebView *webView;
    and "connect" the IBAction to IB
  • In applicationDidFinishLaunching:, add this line:
    [webView setPolicyDelegate:self];
  • Add this delegate method:
    - (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener {
        [[NSWorkspace sharedWorkspace] openURL:[request URL]];
  • In the HTML file, make sure your anchor tags contain 'target="_blank"'. For example:
    <a href="" target="_blank">click on this link</a>
You should be able to compile, click on a link in your WebView, and have it launch a new browser window to Google.

Tuesday, June 21, 2011

C++ static variables

This blog says it so well, that I'll just link to it. As an extension, if you define your own type, the rule also applies to your typedef. For example,
typedef map ConfigType;
ConfigType HelperUtils::config;