How to install a local package via pip

Assuming you have set up your setup.py script in your local package sitting on your machine and you want to install this package in another project using pip, then first you can build an archive of your package using the following command:

python setup.py sdist

This will create a dist folder in your package and put the archive inside it.

Next, switch to the virtualenv of the destination project if applicable and install the package using a command like:

pip install /srv/pkg/mypackage/mypackage-0.1.0.tar.gz

Reference

1. Installing Python packages from local file system folder with pip – Stack Overflow. http://stackoverflow.com/questions/15031694/installing-python-packages-from-local-file-system-folder-with-pip

How to Perform an Action on Key Press in Angular JS

Here’s a quick way to perform certain operations on key press in an input field while working with AngularJS. E.g. say you want to prevent non-digitsĀ from being accepted in an input field.

<input name='foo' id='foo' ng-model='foo' ng-keypress="isNumber($event)" />

Then in your controller, you can do something like:

$scope.isNumber = function (event) {
    var charCode = (event.which) ? event.which: event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        event.preventDefault();
        return false;
    }
    return true;
};