Bower install / NPM install behind a proxy

Often when you work in a company network your are using a proxy to connect to the internet and it is not uncommon that you receive the following error when trying to execute bower install or npm install

ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/jquery/jquery.git", exit code of #128

The proxy is blocking the connection to Github because most proxy do not allow git://-urls. The solution for this is very simple. Just change the git urls to https and everything will work. This command changes all github urls to https:

git config --global url.https://github.com/.insteadOf git://github.com/

Not enough physical memory is available to power on this virtual machine with its configured settings.

Virtual Machines are more or less commodity for modern development environments. I have been very happy with VMWare Workstation for a long time. I have several SharePoint (and other) setups running and never had a problem.

Recently, I got the message

Not enough physical memory is available to power on this virtual machine with its configured settings.

whenever I tried to start a virtual machine. But my workstation had more than enough free memory available. Even restarting did not solve the problem. Google told me that a windows update could be the problem but I found only very old KB’s as potential causes.

By accident I stumbled upon a post that pointed to VMWare config.ini. Just add this line:

vmmon.disableHostParameters = "TRUE"

to the end of the file and VMWare starts working again. I am not exactly sure what the cause of the problem was, but at least I know how a workaround.

gulp-nodemon: Object # has no method ‘spawnSync’

gulp-nodemon is a nice tool if you want to restart your node process when your source code changes. It is very easy to use. Just take this snippet from their sample code and modify the script to your needs.

gulp.task('develop', function () {
  nodemon({ script: 'server.js'
          , ext: 'html js'
          , ignore: ['ignored.js']
          , tasks: ['lint'] })
    .on('restart', function () {
      console.log('restarted!')
    })
})

Just fire up “gulp develop” and the server will start.

You might receive the following error: Object #<Object> has no method ‘spawnSync’

In this case check your node version (e.g. mine was 0.10.26). As stated in the release notes (here) you need to use Node.js version 0.12 in order to use it. You either use an older version of gulp-nodemon or upgrade your Node.js installation to the correct version.

Error: ENOENT, stat ‘C:\Users\Username\AppData\Roamin\npm’

Today I installed Node.js on a new Windows 8.1 machine. I downloaded the latest version from nodejs.org and tried to use npm. I got the following exception:

Error: ENOENT, stat 'C:\Users\Username\AppData\Roamin\npm'

The solution is very simple: Just create the folder: C:\Users\Username\AppData\Roamin\npm Afterwards node (and npm) works as expected.

This behavior is a bug in the recent version of the node installer (see here for more details).

pip install lxml – Permission denied

When using Python you mostly rely on pip to install necessary libraries. Recently I ran the following command on my Mac:

pip install lxml

The result was the following output:

error: could not create '/Library/Python/2.7/site-packages/lxml': Permission denied

Obviously, writing to the folder /Library/ is not possible for a normal user account. There are several possible options to overcome this problem.

  1. You can use the command sudo pip install lxml to install the package
  2. You can use the command STATIC_DEPS=true sudo pip install lxml to install the package. This will download libxml2 and libxslt and build the source distribution afterwards.
  3. You use virtualenv to install the package only locally in your current project directory. See here for a good tutorial of virtualenv.

From my perspective option 3 is the cleanest way to install and manage lxml.

XmlSerializer – Check if property was present in XML

Recently I was parsing a large amount of XML files using the XmlSerializer class. While implementing the parser I came across a requirement where I had to check if a given property was null because it was specified as null or because the value was not present in the XML.

At first this caused me some headache because accessing the underlying XML file violates the abstraction provided by the serializer. Luckily, I recognised that the generated entity class (generated from XSD.exe) contains a lot of properties with the name <PropertyName>Specified. This is a very neat feature of the XmlSerializer. If you add a property with that name scheme it automatically sets the property to true when the corresponding element is present in the XML.

The property could look like this:

[System.Xml.Serialization.XmlIgnoreAttribute]
public bool MyPropertySpecified { get; set; }

Note: XmlIgnore is necessary to avoid having the artificial property serialised into XML when using the XmlSerializer to write XML. More details on the behaviour can be found in the class documentation here.