Setting up Bower and Gulp in Windows

Doing things manually is fine once but if you can automate things it’s better. With little tools you can speed up development and reduce recursive mundane tasks such as starting a project or setting up boilerplate code. I recently came across Bower which is a package manager for the web. With Bower you can fetch and install packages from all over, and it takes care of finding, downloading, and saving the stuff you’re looking for. The other interesting tool to help you get going is Gulp which enables you to automate and enhance your workflow. Let’s see how to put things together on Windows, nothing special just steps to get you started.

Gulp tasks

Install Git

Bower needs Git to work so first install Git if you don’t have it. I chose Git for Windows which gives you BASH emulation used to run Git from the command line, graphical user interface for using Git and Shell integration.

Just click through the installation.

Install Node.js

Bower depends on Node.js and NPM so you need to get Node.js. Just download the installation package from Node.js site and click through it.

Install Bower

After you have Node.js installed we can install Bower with npm. You might need to restart your Windows to get all the path variables setup so Npm can find them.

Open up the Git Bash or Command Prompt and Bower is installed globally by running the following command.

$ npm install -g bower

Once you have Bower installed you then can install packages and dependencies using these commands:

# Using a local or remote package
bower install <package>
 
# Using a specific version of a package
bower install <package>#<version>
 
# Search packages
$ bower search <package>

By default packages will be put in the bower_components directory which can be changed if you prefer. If you want your packages downloaded into js/libs you can achieve this by creating a .bowerrc file

.bowerrc

{
    "directory": "js/libs"
}

You can also create a bower.json file which allows you to define the packages needed along with dependencies and then simply run bower install to download packages. In our example we setup a simple Backbone.js application which uses Bootstrap.

bower.json

{
    "name": "Foobar",
    "version": "0.1.0",
    "dependencies": {
          "jquery": "~2.0.3",
          "underscore": "~1.5.0",
          "bootstrap": "~3.3.2",
          "backbone": "~1.1.2"
    }
}

Our bower.json describes that we want some JavaScript libraries and as we have defined the version with ~ it can have bigger minor versions, e.g. jquery version can be between 2.0.3 < 2.1.0. Read more about semantic versioner for npm.

Now after creating that file inside the app directory you can run the following command:

$ bower install

After that you should see all your JavaScript packages under bower_components folder.

Install Gulp

To automate and enhance your workflow you can use Gulp for example to copy the files where you want them. There are nice recipes to show how to benefit of Gulp.

Install Gulp globally with npm:

$ npm install --global gulp

Install Gulp also in your project devDependencies:

$ npm install --save-dev gulp

Now we can setup our Gulp dependencies which pull from npm. Create a new package.json file in your project root and just add an empty object, {} and save it.

Next we install gulp-bower plugin which we can use to install Bower packages.

$ npm install --save-dev gulp-bower

This will install all the needed dependencies in a node_modules folder and also automatically update our package.json file with these dependencies.

Finally we need to setup the gulpfile.js which defines our tasks we want to perform. First we define what we installed in npm step above and create a config object to hold various settings. The bowerDir is just the path to the bower_components. Finally we add task for running bower and default task. Our bower tasks basically runs bower install but by including in the gulpfile other contributors only have to run gulp bower and have them all setup and ready.

gulp.js

var gulp = require('gulp'),
    bower = require('gulp-bower');
 
var config = {
     bowerDir: './bower_components'
}
 
gulp.task('bower', function() {
    return bower()
        .pipe(gulp.dest(config.bowerDir))
});
 
$ gulp.task('default', ['bower']);

The default task runs the bower task and all the user has to do to setup the needed packages is to run

$ gulp

In our case running gulp just runs our bower task which downloads the JavaScript packages we need. Pretty simple.

Gulp is powerful tool and has many use cases but also needs some to get all things working like you want and even then you might need to make compromises. One crafty task for Gulp and Bower is to customize your Bootstrap theme. Also Mark Goodyear has written good article about Getting started with gulp which shows some typical use cases.

Connecting Jabra HALO2 Bluetooth Headset with Windows 7

Recently I got Jabra HALO2 Bluetooth headset for teleconferences but had problems to get it work with Windows 7 and Dell Latitude E6530. Windows found the device and wanted to install drivers but couldn’t find any. The solution was easy: update your laptops’ Bluetooth drivers. I downloaded Dell Wireless 380 Bluetooth Application version 6.5.1.4000,A02 from Dell’s drivers page and got it working.

Jabra HALO2 is a wireless Bluetooth headset with dual microphone for noise filtering and can be paired with 2 Bluetooth-enabled devices. It can be also used with USB cable and 3,5mm cord and can control music player and sound volume. The battery last for 8 hours talk or music and 13 days on standby.

The wireless headset works with e.g. Windows 7 but some laptops like my Dell Latitude E6530 needs specific manufacturer’s Bluetooth drivers before Windows starts to play nice with them. At first I got the “Bluetooth peripheral device driver not found” error when trying to connect a Bluetooth device and as the Jabra HALO2 headset doesn’t need drivers it was time to look for them from Dell’s support.

Dell’s drivers page doesn’t have Bluetooth drivers directly so I figured to get the “Dell Wireless 380 Bluetooth Application” version 6.5.1.4000,A02 (31/10/2013) which provides an application for DW380 Bluetooth. After installing the 245 MB package Windows started to install the missing drivers and the Bluetooth headset’s hardware functions got found: AV, Hands-free, Headset and Remote Control. I can’t say that updating the drivers will help everyone but what I searched about this issue it was the solution which got these and other Bluetooth headphones working with different laptops.

The start with my new headset wasn’t the easiest but after I got it working the Jabra HALO2 Bluetooth headset works nicely and is pleasant to use for teleconferences with Lync and with my Lumia 800 mobile phone.

Jabra HALO2 bluetooth headset connected
Headset shown in playback devices
Headset’s Bluetooth services

Windows and X11 forwarding with Xming

Usually I prefer to do thing directly from the Linux terminal but sometimes there is a need for remote graphical tools and X11 forwarding. Linux supports X Forwarding with no extra software, on OS X you need e.g. XQuartz and on Windows you need two pieces of software: a secure shell program (ssh) to establish the remote connection and an X Server to handle the local display. Here we concentrate on Windows and use Xming and PuTTY for those tasks.

Using Xming for X11 forwarding on Windows

There are different tools to do X11 forwarding on Windows but Xming is small, fast and simple software for X Window System Server for Microsoft Windows. You also need program like PuTTY or FuTTY to create the remote connection.

After you have Xming installed and started check what the icon says on the taskbar. Mine says “Xming Server:0.0” so for PuTTY settings we get “0.0”. It might also be “0:0”.

Next open Putty and in the Category list go to

  • Connection > SSH > X11
  • Check X11 forwarding: [x] Enable X11 forwarding
  • Add to the “X display location” field: localhost:0.0

Choose Session in the Category list and add your Linux hostname and select SSH. Click Save and then Open the SSH connection to your remote host.

On the remote machine check that the X11 forwarding works with e.g. -bash-3.2$ xeyes &

X11 forwarding as other user

That’s the typical use case but if you change to another user and try the same command you get error “MIT-MAGIC-COOKIE-1 data did not match”. Go back to previous user and check what the xauth list says. Take note of that line as you need it later.

-bash-3.2$ xauth list
your.linuxmachine.foo/unix:10  MIT-MAGIC-COOKIE-1  38dcf9f9fd5b587f3d5fa8d77281f66c

Login again as another user e.g. -bash-3.2$ sudo su - oracle and add the original users MIT-MAGIC-COOKIE to xauth.

-bash-3.2$ xauth add your.linuxmachine.foo/unix:10  MIT-MAGIC-COOKIE-1  38dcf9f9fd5b587f3d5fa8d77281f66c

After that the command -bash-3.2$ xeyes & as oracle should work.

If you get error, -bash-3.2$ Error: Can't open display:, correct the DISPLAY variable like:

-bash-3.2$ DISPLAY=localhost:10.0; export DISPLAY

Now you can run e.g. Oracle’s Database Configuration Assistant (DBCA) to setup a new database remotely with X11 forwarding:

Runnign DBCA remotely with X11 forwarding

Transferring Linux install media to USB thumb drive

Optical drives are nowadays less common on laptops which makes making bootable install medias a little easier. Yes, easier by requiring you to use USB thumb drives. There are different ways to achieve what you want and here is couple of examples how to transfer Linux install media to USB thumb drive on Windows and Mac OS X.

First you need to download the install media of your choice as ISO image which you want to transfer to your USB thumb drive. In theory you need a media which is meant for USB thumb drive or is a Hybrid ISO image but practically all modern distributions’ media are Hybrid ISO images.

Windows

Plug in the USB thumb drive and format it with FAT32 file system

Download UNetbootin and transfer ISO content to USB thumb drive using UNetbootin.

  1. Select Diskimage and click the “. . .” button to find and open the ISO file. Make sure Type is USB drive and the Drive letter is what your Windows detect and click OK. Your ISO content will be copied to USB thumb drive.
  2. Next you also need to copy the ISO file that you used with UNetbootin to the root of the USB thumb drive, e.g. the ISO file should be F:\linuxmint-16-cinnamon-dvd-64bit.iso

Now you can proceed to boot up the machine that you want to install with e.g. Linux Mint 16.

Linux

Creating bootable USB thumb drive in Linux is much simpler. You just need install media which is meant for USB thumb drive or is a Hybrid ISO image. With hybrid images, you can simply write the content of the ISO and make a bootable USB stick which can install Linux by using the ‘dd’ command.

You just need to have the ISO image and one command:

$ sudo dd bs=4M if=linux-image.iso of=/dev/sdX oflag=direct

Where sdX is the device where your USB thumb drive is, e.g. sdb. If your system doesn’t support ‘oflag=direct’, you can just leave it out as it is simply intended to speed up the process a bit. If you leave the bs-option off the default will be 512 bytes and takes forever.

Mac OS X

OS X’s DiskUtil can’t burn ISO images to USB and gives “Invalid argument” but fortunately just like with Linux also Mac OS X makes things easy for you. You just need the install media which is meant for USB thumb drive or is a Hybrid ISO image. With hybrid images, you can simply write the content of the ISO and make a bootable USB stick which can install Linux by using the ‘dd’ command.

$ dd if=linux-image.iso of=/dev/rdiskX bs=8192

Where rdiskX is the device where your USB thumb drive is, e.g. rdisk1. You can see the device (disk identifier) from DiskUtility.app by selecting your USB stick and checking the Device section.

It’s useful to notice that on OS X you can use the ‘/dev/rdiskX’ device which stands for raw disk and is much faster than the block level device ‘/dev/diskX’ which is buffered and where data undergoes extra processing. For example rdiskX gives “823132160 bytes transferred in 625.470137 secs (1316022 bytes/sec)” and diskX gives “823132160 bytes transferred in 1296.675998 secs (634802 bytes/sec)”.

If you get an error e.g. “dd: /dev/rdisk2: Resource busy” then you have to make sure the Mac OS X isn’t using it and thus unmount it’s partitions. Open the DiskUtility.app, and on your USB hard drive, unmount any of it’s partitions. Do not eject the USB hard drive.

Do a clean install of Windows 8 with an upgrade key

There are times when you have to do a clean install of your Windows 8 but if you have just an upgrade key you need to make couple of extra hoops before you can activate the new install. The upgrade key doesn’t prevent you installing to a clean disk but when you try to activate, you get an error 0x8007007B, saying your product key can only be used for upgrading. Another fine example how Microsoft makes things complicated for legitimate users.

Fortunately there’s a way to fix that issue as Lifehacker’s article tells:

  • Open the Registry Editor (Win + R, type regedit).
  • Navigate to “HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Setup/OOBE/” and change the MediabootInstall key’s value from 1 to 0.
  • Open the Command Prompt (Win + R, type cmd). Right-click on the Command Prompt icon and run it as an administrator.
  • Type slmgr -rearm and press Enter.
  • Reboot Windows.

After that is done and you get back into Windows, you should be able to run the Activation utility and activate Windows as normal, without getting an error.

Apparently you can also call Microsoft Support and they will walk you through the proper way doing this because they understand you may have bought a new drive. There is a dialog you can get to in system tools where it will ask you for a numerical code. The support personnel will give you the number, you click “OK” after typing it in, then go the activation again and it works. This process is likely doing the work around mention above, but through an approved administrative process.

By the way, restarting Windows 8 is most easily done by left-clicking once on an empty spot on the desktop and holding Alt + F4).