Thursday, 5 May 2016

Why use AngularJS

Why use AngularJS when there are several other JS frameworks already there.

AngularJS is an open source MVC framework developed by google.

Quick benefits are:-

1. Two way data binding between the Model and View, i.e. if one change, other is also changed !

2. Dependency injection made a piece of cake.

3. Great importance is given to unit testing

4. MVC architecture.

Do not improvise your website development by using whatever comes in hand to program it,
but use something promising like AngularJS to have better perfomance by writing minimun code !

Tip: use CND link to include angular js in your html source instead of downloading and dumping the js file in your project.

Monday, 2 May 2016

Linux Restart Wifi

Many times is observed wifi cant be restarted esp. on ubuntu.

Here are quick commands to fix this:-

sudo service network-manager stop
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start


My approach is to create a funciton in .bashrc as

Copy following code and paste it at the end of your bashrc file

network_restart()
{
    sudo service network-manager stop
    sudo rm /var/lib/NetworkManager/NetworkManager.state
    sudo service network-manager start

}

Hope this tip helps you !!!

django quick start tips

Make virtualenv

$ mkvirtualenv -p /usr/bin/python2.7 djprojman


Install Django

    $ pip install Django==1.8.4

    ERROR: No module named MySQLdb
    $ pip install mysql-python

 - checking django version:-

    $ python -c "import django; print(django.get_version())"

 - creating a project

    $ django-admin startproject mysite

    $ python manage.py migrate


 - create an app
    $ python manage.py startapp polls

    $ python manage.py makemigrations work


 - pip installing packages from requirements file:-
    $ pip install -r /path/to/requirements.txt


ADMIN

    create admin
    $ python manage.py createsuperuser

    admin user can have any username - admin, myadmin, abcadmin etc

    change password for any user
    $ python manage.py changepassword admin


UNIT TESTS

    $ python manage.py test --keepdb
    $ python manage.py test papu.tests.test_api_order_statuses --keepdb


MIGRATION

    $ python manage.py migrate --fake
    (if table already exists, do the fake migration)

git quick hacks

This is a bare bones quick hack tutorial for git.


Checking current system configuration

$ git config --list

This will show:-
user.name=ABCSmith
user.email=abcsmith@gmail.com

Setting configuration on current system

git config --global user.name "XYZ John"
git config --global user.email "johnxyz@gmail.com"

Quick tip

To avoid filling password, write the information in .netrc file on Linux and Mac systems, for windows, use cygwin for this.

Sample of .netrc is as follows:-
machine bitbucket.org
    login ABCSmith
    password mypass1234

Checking server url

git remote -v

Branching

- Show list of all branches
  git branch -a

- Create a feature branch named feature1 from development branch

   first checku development branch, then create the feature1 branch.

   git checkout development
   git branch feature1
 
- Create a local branch in develop
    $ git checkout develop
    $ git branch -b develop_navjot develop (will create develop_navjot branch in develop)
    $ git checkout develop_navjot

- Merge the branch locally
    $ git checkout develop
    $ git merge develop_navjot   (will merge develop_navjot into develop)

- Push local branch to remote/server
    $ git checkout develop
    $ git push origin develop_navjot (will push develop_navjot into develop onto remote/server)

UNDOING

 - undo last push

    $ git -f push origin 9fed600afffca7a4df15c84dcdda44b154dc4f8a:master

 - undo last push
    git reset --hard HEAD@{1}
    git push -f

 - undo last Commit
      $ git reset --soft HEAD^
            or
        $ git reset --soft HEAD~1

More Tips

- list all files under version control:-

    git ls-files

 - list all deleted files that are in version control:-

    git ls-files --deleted

 - removed all deleted files in version control from version control:-
    (for git rm)

    git ls-files --deleted | xargs git rm 

 - add all modified files in version control (for git add ...)

    git ls-files --modified | xargs git add

- delete a branch

    git push origin --delete <branchName>