Archive

Archive for September, 2018

Githooks

September 28, 2018 Leave a comment

Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature – no need to download anything. Git hooks are run locally.

These hook scripts are only limited by a developer’s imagination. Some example hook scripts include:

* pre-commit: Check the commit message for spelling errors.
* pre-receive: Enforce project coding standards.
* post-commit: Email/SMS team members of a new commit.
* post-receive: Push the code to production.

https://githooks.com

Categories: git, Interesting

Using Version Control Hooks

September 27, 2018 Leave a comment

Flake8 can be integrated into your development workflow in many ways. A default installation of Flake8 can install pre-commit hooks for both Git and Mercurial. To install a built-in hook, you can use the flake8 –install-hook command-line option.

https://flake8.readthedocs.io/en/latest/user/using-hooks.html

Categories: Interesting Tags: ,

Tips for using a git pre-commit hook

September 26, 2018 Leave a comment
Categories: git, Interesting

Welcome to Hypothesis!

September 25, 2018 Leave a comment

Hypothesis is a Python library for creating unit tests which are simpler to write and more powerful when run, finding edge cases in your code you wouldn’t have thought to look for. It is stable, powerful and easy to add to any existing test suite.

https://hypothesis.readthedocs.io/en/latest/

Categories: Interesting

Creating a Simple Recommender System in Python using Pandas

September 24, 2018 Leave a comment

Introduction
Have you ever wondered how Netflix suggests movies to you based on the movies you have already watched? Or how does an e-commerce websites display options such as “Frequently Bought Together”? They may look relatively simple options but behind the scenes, a complex statistical algorithm executes in order to predict these recommendations. Such systems are called Recommender Systems, Recommendation Systems, or Recommendation Engines. A Recommender System is one of the most famous applications of data science and machine learning.

A Recommender System employs a statistical algorithm that seeks to predict users’ ratings for a particular entity, based on the similarity between the entities or similarity between the users that previously rated those entities. The intuition is that similar types of users are likely to have similar ratings for a set of entities.

Currently, many of the big tech companies out there use a Recommender System in one way or another. You can find them anywhere from Amazon (product recommendations) to YouTube (video recommendations) to Facebook (friend recommendations). The ability to recommend relevant products or services to users can be a huge boost for a company, which is why it’s so common to find this technique employed in so many sites.

In this article, we will see how we can build a simple recommender system in Python.

https://stackabuse.com/creating-a-simple-recommender-system-in-python-using-pandas/

Source:
https://us4.campaign-archive.com/?u=9735795484d2e4c204da82a29&id=a7ee3fb2e4

Different tabs for different files

September 14, 2018 Leave a comment

Problem:

Needed to have different tabs for different files when editing with vim. Eg in python tab == 4 spaces, in a MakeFile tab == tab.

Solution:

Added this to ~/.vimrc

" Use different indentation for yaml files
 autocmd FileType yaml,yml setlocal tabstop=2 expandtab shiftwidth=2 softtabstop=2

 " In makefiles, don't expand tabs to spaces, since actual tab characters are
 " needed, and have indentation at 8 chars to be sure that all indents are tabs
 autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0

Source:
https://superuser.com/questions/632657/how-to-setup-vim-to-edit-both-makefile-and-normal-code-files
https://github.com/spf13/spf13-vim/issues/789#issuecomment-118369177

Categories: vim Tags:

pycodestyle.py:113: FutureWarning: Possible nested set at position 1

September 11, 2018 Leave a comment

Problem:

You get the following error when running flake8

$ flake8 sample.py
/usr/local/lib/python3.7/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
sample.py:7:1: E302 expected 2 blank lines, found 1

Solution:
# Uninstall flake8

$ pip3 uninstall flake8
Uninstalling flake8-3.5.0:
  Would remove:
    /usr/local/bin/flake8
    /usr/local/lib/python3.7/site-packages/flake8-3.5.0.dist-info/*
    /usr/local/lib/python3.7/site-packages/flake8/*
Proceed (y/n)? y
  Successfully uninstalled flake8-3.5.0

# Install the working version

$ pip3 install -e git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8 --src /usr/local/lib/python3.7/site-packages
Obtaining flake8 from git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8
  Cloning https://gitlab.com/pycqa/flake8 (to revision 9631dac5) to /usr/local/lib/python3.7/site-packages/flake8
  Did not find branch or tag '9631dac5', assuming revision or ref.
Collecting pyflakes<2.1.0,>=2.0.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/44/98/af7a72c9a543b1487d92813c648cb9b9adfbc96faef5455d60f4439aa99b/pyflakes-2.0.0-py2.py3-none-any.whl (53kB)
    100% |████████████████████████████████| 61kB 460kB/s
Collecting pycodestyle<2.5.0,>=2.4.0 (from flake8)
  Using cached https://files.pythonhosted.org/packages/e5/c6/ce130213489969aa58610042dff1d908c25c731c9575af6935c2dfad03aa/pycodestyle-2.4.0-py2.py3-none-any.whl
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /usr/local/lib/python3.7/site-packages (from flake8) (0.6.1)
Requirement already satisfied: setuptools>=30 in /usr/local/lib/python3.7/site-packages (from flake8) (40.0.0)
Installing collected packages: pyflakes, pycodestyle, flake8
  Found existing installation: pyflakes 1.6.0
    Uninstalling pyflakes-1.6.0:
      Successfully uninstalled pyflakes-1.6.0
  Found existing installation: pycodestyle 2.3.1
    Uninstalling pycodestyle-2.3.1:
      Successfully uninstalled pycodestyle-2.3.1
  Running setup.py develop for flake8
Successfully installed flake8 pycodestyle-2.4.0 pyflakes-2.0.0

Source:
https://github.com/PyCQA/pycodestyle/issues/728#issuecomment-405341335

Categories: python Tags: ,

Dougal Matthews – Effective Code Review

September 10, 2018 Leave a comment

Developers usually state that finding defects is the primary
motivation for doing code reviews. However, research has shown that
the main benefits of code reviews are; knowledge transfer, team
awareness and finding alternative solutions.

Code reviews when done well are more than just finding defects; it
should be a discussion and conversation with other developers about
finding the best solutions. We will talk about re-framing code review
to encourage open discussions.

—–

This talk is for everyone that is already involved in regular code
review and those hoping to start. I will talk through the code review
process with the aim of making it a better and more useful experience
for both the authors and the reviewers.

The talk will follow the following rough outline:

– Introduction
– Why do code reviews
– What are we aiming to get out of it
– Submitting code for review
– How can you help reviewers?
– What should you avoid doing?
– Removing ownership of the code
– Reviewing code
– How should you give feedback?
– What should you look for?
– How can you encourage people to review more?
– How to avoid and remove bike-shedding
– Code review tools and how they impact on the process.
– Wrap up and conclusion

Categories: Interesting Tags:

How to Write a Git Commit Message

September 4, 2018 Leave a comment

The seven rules of a great Git commit message

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

https://chris.beams.io/posts/git-commit/

Categories: git, Interesting

Create a Development Environment with Docker Compose by Mark Ranallo

September 3, 2018 Leave a comment
Categories: Interesting Tags: ,