tiistai 16. kesäkuuta 2015

How to join the Django's Cookiecutter-based project and get it up and running in Ubuntu Vagrant?


Django's cookiecutter project template is really nice package of the commonly used best practices. It makes some of the boring stuff which usually consumes few days when you're creating a project.

If you have followed the Speeding up the Vagrant-instructions, you'll get the Cookiecutter project up and runnign by using these instructions.


Install Postgresql & virtualenv
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install python-virtualenv
Create a virtualenv
virtualenv venv

Create your user & the database
sudo su - postgres psql CREATE USER vagrant WITH PASSWORD 'vagrant'; CREATE DATABASE databasename OWNER vagrant; \q
exit

Add your db-details to venv/bin/activate and activate it
export DATABASE_URL=postgres://vagrant:vagrant@localhost:5432/databasename
source venv/bin/activate

Get files from the repository
git clone https://yourusername@repourl.git


Go to your repository and install OS & Python-dependencies

sudo ./install_os_dependencies.sh install
sudo ./install_os_dependencies.sh install

And you're done almost done! Run the last command and see if it works by browsing to 192.168.50.100:8000.
python manage.py runserver_plus 0.0.0.0:8000

maanantai 15. kesäkuuta 2015

Vagrant & Windows - Terrible slow - How to cure the sluggishness?


Honestly, I hate Windows CMD and from developer's point of view the Windows is no fun from many different aspect. Most of the fancy guru's are using Linux / Mac for completing their task and I don't wonder why.

Why Vagrant?

Since I got a new laptop and I don't hate Windows 8, but I still want to use familiar Linux for my development environment I decided to use vagrant instead of many other options.

Vagrant brings all the benefits of the unified dev-environment in to your Windows without sacrificing the battery life / peripheral-device support, which might happen when you'd install Linux.

Why it's better than basic Virtualbox? 
It won't install any UI for you, unlike basic virtual box installations, which makes it work much faster. Also you can install your packages from your WINDOWS CMD! <3

Installation of the Vagrant is really easy. You just install the preferred package from https://www.vagrantup.com and install virtual environment from your CMD.

WHY VAGRANT IS SO FRIKKIN SLOW????!

Everything seemed to be working nice'n easy at the begining, but after a while I grew pissed off for the unexplained sluggishness of the development.

Rebooting the Django-server toke 60 second or so... and development started to remind me more and more Java-coding than agile Python coding, no offence Java-coders.

I started digging out the issues and couldn't exactly pinpoint the cause for this problem.

Finally I found a nice article, which proposed that I should try to use Samba-file sharing instead of NFS. I didn't realize that the slow booting cycles were causer by slow file sync procedures.

Fix slow Vagrant in Windows with Samba


1st log in to Vagrant:

vagrant up && vagrant ssh

Install Samba
sudo apt-get install samba

Edit samba's config
sudo vim /etc/samba/smb.conf

Add the following pieces in the end of the smb.conf
[shared]
comment = Local Dev Server – /var/www
path = /var/www
browsable = yes
guest ok = yes
read only = no
create mask = 0777
force user = root
force group = root
#[shared] End

Restart Samba:
sudo service nmbd restart
sudo service smbd restart

Add static IP in to your Vagrant-file
config.vm.network "private_network", ip: "192.168.50.100"

Now everything should be in place and you should be able to access to \\192.168.50.100. Just copy your files there and stop slacking!

tiistai 26. toukokuuta 2015

Master of the Gits! - Feature Branch Workflow


Git is overly complicated!

Git used to be a bit... mmm overly complicated ball of fur, back in the days, but those days are long gone. Here's what Mr. Torvalds thinks about that:
Interviewer: People have said that Git is only for super smart people. Even Andrew Morton said Git is "expressly designed to make you feel less intelligent than you thought you were." What's your response to this?
Torvalds: So I think it used to be true but isn't any more. There is a few reasons people feel that way, but I think only one of them remains. The one that remains is fairly simple: "you can do things so many ways."
10 Years of Git: An Interview with Git Creator Linus Torvalds, 26th May, 2015


Git is awesome, honestly

Nowadays git works really well even for non-super-nerd-kind-of-software-developers. So, basically I really recommend in starting to use that, even though you'd have background in other SVNs. Git doesn't really have any childish problems, it doesn't rely on your internet connection and it really gives you some nice tools for improving your team and your code quality.

However if you're using git as you'd using SVN you really should consider to use Feature Branch Workflow instead. Since when using the git as SVN it won't really justify the existence of the software.

If you're using Git without branches, please reconsider

If you're just developing your application by using the master branch, you really should try feature branch workflow. It gives you a number of benefits over the basic workflow.
So what are exactly the benefits?

  • All features are encapsulated.
  • Pull requests -> bump up your team's communication, learning and quality.
  • Pull request, yes again. If you get stuck with your code, asking help is really easy. Just make a new PR and yell for help.
  • Master branch will (hopefully) never break.

Here are some solid basic settings for your git (in Ubuntu)


1. Install git bash autocompletion
Autocompletion is a breeze, you'll love to find your branches and git features when you keep banging your tabulator.

sudo apt-get install git bash-completion

2. Add to your ~/.gitconfig
Everyone loves colors!

[color]
    branch = auto
    diff = auto
    status = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan

3. Add your personal settings
Add your username, email, default editor, simple push, and timeout for your credentials.

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor vim #All cool guys loves vim!
git config --global push.default simple #make sure that you're only pushing the active branch
git config --global credential.helper 'cache --timeout=27000' # remember credentials for 7.5h

Pretty good basic workflow for anyone

Get the copy of the repository, only needed on 1st run:
git clone https://your-repo # make a local copy of the repository
Start working with a new branch:
git checkout -b name_of_the_feature master #-b creates a new branch if it's not existing
Make some work and commit your results to local repository. Lather, rinse and repeat:
git add <file_name>
git commit # Check out how to write good commit messages
Keep the copy of your branch in central repository only needed on 1st run:
git push -u origin name_of_the_feature #push the feature branch to the central repo.
Finish your work:
git rebase -i <first-commit-hash-of-the-branch> #Squash commits in to logical sections
git checkout master; git pull; git <feature_branch> #update the master
git rebase master #if someone has merged some new branches in to master.
git push

Where does the learning take place?

The learning and static QA-process starts now! When the feature is finished and new branch is about ready to be merged in to the master. The name of this phase is pull request.

Pull request

Pull request really give you a great set of tools for code review, learning from the code and collaboration around the specific feature branch.

Pull requests are amazing. They're really pushing your team and your code quality towards.

Here's how it goes: