adamkdean

software engineering

Version ranges for node package dependencies

By Adam K Dean on

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

version Must match version exactly
>version Must be greater than version
>=version etc
<version
<=version
~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" : "http://asdf.com/asdf.tar.gz"
    , "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:

git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish

Read more: https://www.npmjs.org/doc/files/package.json.html

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.

Host example.com
    HostName git.example.com
    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 example.com which actually points to another hostname, such as a source control server, e.g. git.example.com.

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 10.0.2.15...
Lease of 10.0.2.15 obtained, lease time 86400
deleting routers
route: SIOCDELRT: No such process
adding dns 192.168.1.1    
$ sudo /etc/init.d/docker restart
$ exit

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