adamkdean

software engineering

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!

Remove branch from remote git repo

By Adam K Dean on

To remove a branch from a remote git repository, you have to push an empty branch.

$ git push origin :branch-name
- [deleted]        branch-name

If you want to also remove it from the local repo, delete the branch:

$ git checkout master 
Switch to branch 'master'

$ git branch -D branch-name
Deleted branch branch-name (was abcd123)

We change branch as you can't delete the branch you're on.

RegEx match all words with a prefix

By Adam K Dean on

Here is a snippet to match all words that begin with a specified prefix.

/\bprefix\S+/g

JavaScript implementation:

"test tbl_test1 tbl_test2 test".match(/\btbl_\S+/g)

Or

/\btbl_\S+/g.exec("test tbl_test1 tbl_test2 test")

Which is the same as:

var regex = /\btbl_\S+/g;
    matches = [],
    match;

while (match = regex.exec(line)) {
    matches.push(match[0]);
}

If you want a dynamic prefix, use RegExp:

var regex = new RegExp('\\b' + prefix + '\\S+', 'g'),
    matches = [],
    match;

while (match = regex.exec(line)) {
    matches.push(match[0]);
}