software engineering

Version ranges for node package dependencies

By Adam K Dean on

I've lifted this from, but here at least I'll find it again.

version Must match version exactly
>version Must be greater than version
>=version etc
~version "Approximately equivalent to version"
^version "Compatible with version"
1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
http://... See 'URLs as Dependencies' below
* Matches any version
"" (just an empty string) Same as *
version1 - version2 Same as >=version1 <=version2.
range1 || range2 Passes if either range1 or range2 are satisfied.
git... See 'Git URLs as Dependencies' below
user/repo See 'GitHub URLs' below
tag A specific version tagged and published as tag path/path/path See Local Paths below

For example, these are all valid:

{ "dependencies" :
    { "foo" : "1.0.0 - 2.9999.9999"
    , "bar" : ">=1.0.2 <2.1.2"
    , "baz" : ">1.0.2 <=2.3.4"
    , "boo" : "2.0.1"
    , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
    , "asd" : ""
    , "til" : "~1.2"
    , "elf" : "~1.2.3"
    , "two" : "2.x"
    , "thr" : "3.3.x"
    , "lat" : "latest"
    , "dyl" : "file:../dyl"

Git urls can be of the form:


Read more:

How to replace master branch in git, entirely, from another branch?

By Adam K Dean on

If you want to completely replace a branch by merging over another, the follow trick will help you, as it has helped me:

git checkout yourbranch  
git merge -s ours master  
git checkout master  
git merge yourbranch  

Remove .DS_Store from git repository

By Adam K Dean on

The following will help you remove .DS_Store from your git repository.

$ find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
$ echo ".DS_Store" >> .gitignore
$ git add .gitignore
$ git commit -m ".DS_Store removed from repository"

Now you can relax.

Using another private key with git

By Adam K Dean on

It's quite normal to have different private keys for different git servers, but how do you provide a different identity file like you do with SSH?

The answer comes in a text file; config.

Create a text file in your ssh directory, which is usually .ssh:

$ touch ~/.ssh/config

Then open it with your favourite text editor, for me, this is currently atom:

$ atom ~/.ssh/config

Now, we can use this file to configure different hosts. The following should be pretty self explanatory. For your information, in case you're a bit confused, the identity file is your private key.

    User git
    IdentityFile /Users/adam/.ssh/yourkey
    IdentitiesOnly yes

You'll notice the host and hostname are different. This means you can have a host configured for which actually points to another hostname, such as a source control server, e.g.

boot2docker DNS not working

By Adam K Dean on

If you're using Docker on OSX, then you'll be using a VM to run your Docker service on, as it needs Linux, not Unix. The most popular of these seems to be boot2docker, though dvm also seems to be quite popular. Other solutions are available.

I have a problem where sometimes boot2docker's DNS just doesn't seem to work.

I found some instructions on how to fix it though:

$ boot2docker ssh
$ sudo udhcpc
udhcpc (v1.22.1) started
Sending discover...
Sending select for
Lease of obtained, lease time 86400
deleting routers
route: SIOCDELRT: No such process
adding dns    
$ sudo /etc/init.d/docker restart
$ exit

Now if you attempt to ping Google, it should work!