VMWare Fusion: Assigning IP Addresses for NAT-Configured VMs via DHCP and Port Forwarding

In VMWare Fusion, when using NAT, you often times want the IP addresses for the VMs to always be the same, so that you can connect to them from the host using the same IP address every time (and probably assign an entry in your /etc/hosts file). You may also want to connect to the host from the guests using a constant IP address. And finally, with VMs that use NAT, you may want to setup port forwarding so that machines outside of the host can connect to services on your VM (and this relies on the IP addresses remaining the same).

The configuration files for doing this reside in /Library/Application Support/VMware Fusion/vmnet8/ (the NAT interface is called "vmnet8" hence why configuration for it is here), specifically dhcpd.conf and nat.conf. These files may be read-only (even for root), so make sure to give root write permission before you edit them.

Any changes to these files requires that the following be executed before they take effect:

sudo "/Library/Application Support/VMware Fusion/boot.sh" --restart

Prompt Before Closing Emacs

I developed a bad habit of quitting Emacs from my earlier days of using Emacs mostly in a terminal session (where even there quitting it is not the best idea). Now that I use GUI versions of Emacs, I sometimes find myself hitting C-x C-c and wishing I didn't because I really intended to kill the current buffer, not completely close Emacs. So what I have done to deal with this is, when running a GUI version (which can be detected by checking the window-system variable), I always prompt to ask if I really want to quit. Here is the code I use:

(defun ask-before-closing ()
  "Ask whether or not to close, and then close if y was pressed"
  (interactive)
  (if (y-or-n-p (format "Are you sure you want to exit Emacs? "))
      (if (< emacs-major-version 22)
          (save-buffers-kill-terminal)
        (save-buffers-kill-emacs))
    (message "Canceled exit")))
 
(when window-system 
  (global-set-key (kbd "C-x C-c") 'ask-before-closing))

I do this only for the GUI version, but you could remove the check for window-system if you want it to work in the terminal version as well. I use when instead of if in this case, because I do other things if I am running the GUI version, like (server-start), which I have excluded from this code sample.

SVN in Eclipse: Subversive and SVNKit for Subversion 1.6

Previously I had blogged about using JavaHL in Linux. JavaHL is the bindings to the native Subversion libraries which uses JNI, and it sometimes requires a bit of effort to get working. I no longer find using JavaHL necessary as I no longer have problems with the pure Java library SVNKit (formerly known as JavaSVN). I also have switched to Subversive instead of Subclipse because I have found it to be less problematic.

Despite being an official Eclipse project now, Subversive won't install from Eclipse 3.4's default repository, and you still need to get some plugins directly from Polarion. If you want to use the latest Subversive and SVNKit that supports Subversion 1.6, add the following update sites:

And then install the following from those update sites:

  • Subversive SVN Connectors (2.2.0)
  • Subversive SVN Team Provider (0.7.8)
  • SVNKit 1.3.0 Implementation (2.2.0)

Note that the version numbers will change in the future, but these are the current versions that work with 1.6.

URL Shortener Web Application Using Django

I created a URL shortener web application using Django (a Python web framework). I have made the source code available on GitHub and it is under an open source license (MIT license).

The shortened URLs use the base 62 value of ids of the model they are stored in, using the code from here (it uses A-Z, a-z, and 0-9), which should be fairly compact for a long time. A count of how many times the URLs are used is kept. The main page shows the 10 most recent and 10 most popular URLs.

You can see a running instance at n1l.us (which I am using to link to this blog and other links to my own content) and uu4.us (which I am using for all other URLs). I currently don't allow public submissions of URLs on either of those sites, but I will be opening it up for uu4.us at some point (perhaps once I add some defenses against spammers). The application itself has a configuration option to be able to require or not require login to be able to submit URLs (the REQUIRE_LOGIN setting in settings.py). Note that if you require logins, you have to use the admin app (at /admin/) as I have not created a separate login page.

I've so far done the bare minimum as far as HTML/JavaScript is concerned (and there is no CSS to speak of yet). Just enough to get things working. So don't expect a good looking site with this yet. It does produce a functional bookmarklet, assuming that you set SITE_NAME correctly for your site. Though I should probably make the bookmarklet check for rev=canonical to be a good web citizen.

The biggest issue with Adobe Flash Player

The biggest issue with Flash Player at the moment is that there is no way to create a top-level exception handler. What this means is that there will be exceptions (errors) that you simply cannot trap in your application code, even if you put try/catch all over your code (and especially if you are using Flex's MXML). This means that creating things like an error reporting tool are impossible for applications that run in the Flash Player (that includes AIR apps, too, not just browser apps). If you are running the debug version of the Flash Player, you will see uncaught exceptions, but the typical user is not going to be running the debug version. In the regular version of the Flash Player, uncaught exceptions just fail silently (often causing strange behavior), giving no indication to the user that an error occurred.

There is an issue in Adobe's issue tracker for this:

http://bugs.adobe.com/jira/browse/FP-444

It is the highest-voted issue specifically for the Flash Player. It is only surpassed by the request to keep developing Flash Builder for Linux, which I think is an important issue, but this issue is much more important. If you haven't already, create an account on Adobe's issue tracker and vote for this issue.

Database of hidden settings for Mac OS X

Pretty nice list of hidden settings for Mac OS X:

http://secrets.blacktree.com/

Bash Completion

The Bash shell does tab completion executables, bash commands, and files/folders out of box. But it's completion can be extended to support even more types of completion including arguments for commands and things like hostnames through the use of programmable completion.

There is a package called bash-completion which includes a set of completions for various utilities. For example, for Subversion, if you type svn <tab><tab> (replacing with actually pressing tab) it will give you a list of all the svn subcommands that are available. If you type svn rev<tab> it will complete it to svn revert. For ssh, if you type ssh <tab><tab> it will list all the hostnames and IP addresses it knows about (it looks like it uses a combination of what's in /etc/hosts and ~/.ssh/known_hosts). You can of course do ssh username@<tab><tab> if you are using a specific username.

Once the bash-completion package is installed, you can copy additional completion scripts to /etc/bash_completion.d and they will be automatically included. I did this with the Maven 2.x completion script.

Git has a completion script that is included in its standard distribution. Find out where you have Git installed, and source the script <i>GIT_INSTALL_DIR</i>/contrib/completion/git-completion.bash in your .bash_profile. For example, I have Git installed via the binary installer for OS X Leopard, and thus I added this line to my .bash_profile:

source /usr/local/git/contrib/completion/git-completion.bash

Note that this is independent of the bash-completion package described above and does not require it (since we are sourcing it directly).

Django also has bash completion script included in its distribution. Replacing $DJANGO_DIR where you have the release extracted (or checked out from version control):

source $DJANGO_DIR/extra/django_bash_completion

With this, you get completion for django-admin.py and manage.py. For manage.py you need to set execute permissions and run it as ./manage.py on the command line rather than python manage.py in order to get completion for it.

Suppress unchecked warnings on method calls in Java

Let's say you have a method call like this:

List<Object> list = (List<Object>) beanWrapper.getPropertyValue(key);

And beanWrapper.getPropertyValue returns an Object. If you have the "Unchecked generic type operation" compiler setting set to warning, you will get the following warning:

Type safety: Unchecked cast from Object to List<Object>

If you are using Eclipse, it will give you a quick fix to add a @SuppressWarnings(value = "unchecked") annotation, but only give you the option to add it to the current method.


(the current method in this case is getBean())

But we may not want to suppress warnings for the entire method. We can just put the annotation on the method call itself:

@SuppressWarnings(value = "unchecked")
List<Object> list = (List<Object>) beanWrapper.getPropertyValue(key);

CXF SOAP client built using Maven

I recently created some SOAP web service clients using Apache CXF (which is a project that resulted from the merging of XFire and Celtix). Rather than hunt down all the jar files I needed and write an Ant script to do the build, I decided to use Maven for this. It worked nicely and saved me some time (I can't say the same for some of the more complex projects I've tried to use Maven with).

I found the following blog entry very useful for setting this up:

How to create a WSDL-first SOAP client in Java with CXF and Maven

One thing I did different was use a property to specify the CXF version in one place:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cxf.version>2.2.1</cxf.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
    </dependency>

Pay attention to what it says about the cxf.xml file. I used the Maven Eclipse Plugin to generate my Eclipse project files. If you do this, but forget the cxf.xml file, your client may still work fine in Eclipse, but when you try to use the Maven-built jar file, you will get an error like this:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:314)

Use web applications more like desktop apps with Prism (or Fluid)

Many web applications these days work more like desktop apps and/or are applications that you use throughout your day. Using the applications through your regular browser presents a problem: to get to the application you have to switch to your web browser, find the window that you have webapp open in (or open a new window or tab if you're launching it for the first time), and possibly switch to the tab it is in. The steps it takes to get to an already open webapp vary depending on the current state of your browser and what windows and tabs you have open.

Instead, it would be much nicer if the webapp had its own entry in your operating system's taskbar or dock (or possibly in the tray if you are on Windows). With the help of Mozilla's Prism you can achieve just that. If you are using Mac OS X, you also have the option of using Fluid which uses the same rendering engine as Safari (Webkit).

Syndicate content