30 April 2017

Node.js Install Secific from NPM or Git

Whilst carrying out an upgrade of an Angular2 to v4 andfollowing  instructions on the Angular blog "Updating to 4.0.0" I ran the npm install command to update Angular2 to 4:
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save

However you get the error:
npm WARN @angular/core@4.1.0 requires a peer of zone.js@^0.8.4 but none was installed.

Trouble is the latest version of zone.js on Git was v0.8.9 when we need 0.8.4

Install Specific Version From NPM

You can install a specific version from npm:
npm install <package>@<version>
npm install zone@0.8.4 --save

Install Specific Version from Git

To install the specific tag from Git directly run:
npm install git+https://github.com/angular/zone.js.git#v0.8.4 --save

Note the format: git+; then the github normal clone url; a hash; a v; the tag name; and --save to set it in project.json

12 April 2017

Windows: Clear Disk Space

Left to its own devices, Windows will happily fill up whatever drive you put it on. Latest versions are better, but still leave unnecessary bloat around e.g. Windows Updates. Cleaning up these files is particularly important when you are running virtuals.

Where Is Space Being Used

Use a program like TreeSize Free to find where your space is used up.

Clean Up Disk

Use "Disk Cleanup" program included in Windows to clear space on drive C. 
NB You'll need to run it twice: once as normal used, then select 'Clean up System Files' to run it again and review the options.

Clean Up WinSxS

Windows keeps removable files in C:\Windows\WinSxs which is often quite large.
Using a command prompt as admin:
Dism.exe /online /Cleanup-Image /StartComponentCleanup

13 March 2017

Mac: Dual Boot With Windows 10

NB: This procedure has the potential to render your machine useless. Make sure you have external backups of your data and OSX install media before you begin.

Run Disk Utils Disk First Aid

You need to do this to check for errors. If there are any you'll have to fix them first.
In my case that meant:

  • Running at boot time via restart with Cmd R held down. 
  • Restoring from my Airport Extreme Time machine backup
  • Re-installing MAC OSX from the local backup as I'd excluded Applications from the TM backup.
Boring but still, after all that my machine was back up.

Install Windows

  • Open Bootcamp and run through the procedure to 
    • Download and create a bootable Windows USB drive
    • Introduce a new Windows partition
  • Once that's done, you can boot from the USB (Power on with Alt/Option key held down)
  • Install Windows, delete the Bootcamp partition and create new partitions using Windows' Setup (create's two: Drive 0 Partition 4 and Drive 0 Unallocated Space). See the note below.
A note on partitions: After installing Windows I found the install failed with a message about being unable to write to the Boot partition. Some people online suggest doing the procedure twice: Bootcamp partition, install, fail to write, 2x PRAM reset, destroy the partition using Bootcamp, re partition. I can't be sure as I had to repeat the process anyway.

Enable Virtualisation in Windows

If you need HyperV then you might find you don't get it on the Windows side:
To avoid: "Could not set boot device property: 0xe00002bc":
Back in OSX:
  • Download and extract rEFind
  • Edit the config: sudo vi refind/refind.conf-sample
    • Un-comment enable_and_lock_vmx and set to true
    • You might want to reduce the timeout
  • Install it: sudo ./refind-install
Re-enable SIP.

12 March 2017

Mac: Create Bootable SD from ISO

Using Ubuntu as an example: https://www.ubuntu.com/download downloaded to Downloads folder.

Download Ubuntu and Create img file


Create Bootable SD from img file

  • Disk Utility: Erase the SD Card (not sub partition) select:
      Name: (Optional) e.g. UBUNTU
      Format: MS-DOS (FAT)
      Scheme: GUID Partition Map
  • Unmount any partitions, but leave the drive itself mounted
  • Terminal: cd to location of downloaded img
    cd Downloads (ls to check)
  • List disks:
    sudo diskutil list
  • Note identifier of SD card found by disk size e.g. disk3s2
  • Unmount:
    sudo umount disk3 && sudo umount disk3s1 && sudo umount disk3s2
  • Copy image across:
    sudo dd bs=4m if=ubuntu-16.04.2-desktop-amd64.img of=/dev/disk3
  • WAIT: It could take around 20 minutes with little indication it's happening.
Now try your boot: Reboot and hold down Alt/Option key to select the boot disk.



28 February 2017

Firefox Responsive UI

When designing and building websites we need to consider multiple screen resolutions and platforms e.g. iPhone Safari browser, or Pixel C Android tablet in landscape mode.

Resolution Design Mode
Firefox has an excellent Resolution Mode that allows you to select a variety of resolutions. You can also import more:

  1. In Firefox go to about:config and accept the risk
  2. Right click and select New, String, 'devtools.responsiveUI.presets'
  3. Enter the new values e.g. Thanks to Geoffrey Liu for this version
  4. Close any RDM tabs and re-open them to see the new options
User Agent
When changing the resolution we may need to also change the User Agent. Firefox has a plugin for that: written by Chris Pederick User Agent Switcher: download, install and add the list of user agents.
You can check your UserAgent at UserAgentString.com

14 February 2017

Digital Life: How to store your Photos, Files and Music

As a professional software engineer I'm often asked socially about computer problems. Most of them stem from not having their systems set up properly in the first place or a lack of understanding of the importance of doing that, hence this post.

Why

If you only have files (photos, music, spreadsheets etc) on your computer then you will ultimately loose them: hard drives have a fixed life span and one day it will fail: its not 'if', its 'when'. So you need to use an alternative place to store them. Previously we used to use 'local' backups: large disks at home that the computer will backup to, however, with the advent of smartphones and tablets it makes much more sense to use online services that are then available to all your devices.

Cloud Storage

All your files, e.g. letters written in Word or spreadsheets should all be kept in a secure online storage solution e.g. Google Drive (https://drive.google.com). In the same way as for the photos, there is an application to install on your computer to keep a folder in sync with this online storage:
https://www.google.com/drive/download/
In this way. when your computer dies, you still have all your files.
If you're neurotic, there are solutions like ownCloud that keep your files away from Google etc.


Backup

NB: Cloud Storage solutions like GDrive or Dropbox are a syncing solutions NOT a backup, so when you delete the file on your computer its deleted online too. For backup, other cloud services like https://www.crashplan.com exist.

Passwords

Passwords should not be re-used: if one service is compromised (hacked) as we see in the press almost weekly, then its likely your email/password combination will be traded online with everyone else's, and then used to try defraud you e.g. steal your identity. Once this happens its very difficult/costly to 'go back'.
I recommend using a 'Password Safe' program in which to store your credentials. This is then a single password to enter that 'safe' and all your passwords are within. You can store this on a cloud storage (e.g. Google Drive see 'Cloud Storage') and access it from all your devices (phone, ipad, computer)
KeePass: http://keepass.info/download.html
An alternative is to use an online service where you store all your passwords like http://www.lastpass.com/ The advantage is it's easier to setup and use, the disadvantage is that all your passwords are on their servers so you are trusting that they are keeping them securely, will stay in business and won't be hacked.

Photos

If you're using mixed 'platforms' (e.g. Windows and Mac) then Apples iCloud won't work for you: it only really works within the Apple systems. Most alternatives offer some kind of application that you download to your computer which then uploads all your photos over time. You'll need to leave it on for a week or so for this to happen, depending on how many photos you have.

As most people have a gmail account you'll already have access to Google Photos and they offer an app to download here:
https://photos.google.com/apps
You'll likely need to tell it which folders to include/ignore and also to set it to 'upload original' not a reduced size version. There will likely be a cost implication (a few dollars a year) but the alternative is loosing your photos.



09 February 2017

.Net Core Project Files

I've spent he last few weeks playing around with the new project format (csproj) and VS2017 RC2 seeing if its possible to work with this format AND allow for Cross Platform development i.e. using VS2017 on Windows, [Visual Studio Code](https://code.visualstudio.com/) on a Mac and also [VS2015](https://www.visualstudio.com/) or command line (Windows, Mac, Linux). Here are my notes from this work.

Project File Format

As of writing (9/2/2017) there are three possible formats:
* csproj: The new project format of csproj files BUT cannot be built on Mac [see this issue](https://github.com/Microsoft/vsts-tasks/issues/3311). The tooling just isn't there yet.
* xproj: project.json replacement using in VS2015. We can have project.json and xproj in same project, although not ideal as obviously they need to be kept in sync.
* project.json: Less features than the other two (e.g. not full msbuild support) and will be deprecated in favour of csproj
NB: As of writing if you open a project.json or xproj in VStudio2017 it will transform the project files into csproj moving the old to a 'backup' folder. Not all the tooling supports csproj yet.

Building

* dotnet restore
* dotnet build (optional, build will also happen when it's run)

Testing

* VSCode: Run individual tests using the C# Extension OmniSharp
* Command line: dotnet test [path/project Name NOT project file]

Running

* VSCode: Use the Debug Panel
* Command line:
  * dotnet build */**/project.json
  * [Project path] > dotnet run [path/project Name NOT project file]