Configure IPython5 to have IPython3’s readline, tab-completion, (lack-of) syntax highlighting, etc? (self.IPython)

Start by creating a default iPython profile. From your shell, type:

$ ipython profile create

That should give output similar to this:

[ProfileCreate] Generating default config file: u'/home/mmphego/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: u'/home/mmphego/.ipython/profile_default/ipython_kernel_config.py'

Open the newly created file with your favorite text editor, in the above example shown as:

vim /home/mmphego/.ipython/profile_default/ipython_config.py

Add the following lines at the bottom:

c.TerminalInteractiveShell.display_completions = 'readlinelike'

Save the file.

Previous

Screenshot_2017-12-18_17-12-15

New

Screenshot_2017-12-18_17-13-11

Advertisements

Python’s Virtualenv working with Jenkins

If you use virtualenv to isolate your python project’s environment, and want your code tested automatically — read on, else ignore.

virtualenv isolates your project’s python environment

virtualenv makes sure you lock down your project’s main directory and all subdirectories of it. This ‘lockdown’ means that you never touches your global python binary, or any globally installed libraries (like “sudo pip install ipython” ).

Once locked down, you install all packages again, even those you have globally installed. This enables you to have one version of flask globally installed, but another version in your project. All dependencies can be listed in a separate file and validate a precise environment for you to work with. Tightly controlled dependencies is key to a deployment without surprises.

Jenkins checks the health of your project for each change

Jenkins is a CI server which means it does a lot of repeating stuff so you can focus on doing more important stuff. More specifically, it listens for changes to your project’s version control system (like git).

When changes are detected, the project is built and the test suite is executed. If any step fails, the CI server tells you that it did.

Setup Jenkins, and make it use virtualenv

Jenkins needs some massaging before it handles the hijacked environment of virtualenv. This is how I did it for my local git repository:

  • Download and install Jenkins
  • Start it, it should be up on http://localhost:8080
  • Install the Git Plugin
  • Setup a new project with these properties:
    • Source Code Management: add the URI to your local repository,
    • /Users/you/Sites/asdf in my case. Make sure the jenkins user can read this directory, otherwise the Jenkins GUI will tell you something random about invalid git repo, without a hint about a permissions error.
    • Build Triggers: Poll SCM (with an interval like 0 * * * *). This is needed because
      you’re too lazy to build manually; and
      you can not trigger builds with a git post-commit hook otherwise
    • Build > Execute shell. I’ve used two steps, one for setting up the environment and one for the actual tests:

# Setup a proper path, I call my virtualenv dir "venv" and
# I've got the virtualenv command installed in /usr/local/bin
PATH=$WORKSPACE/venv/bin:/usr/local/bin:$PATH
if [ ! -d "venv" ]; then
        virtualenv venv
fi
. venv/bin/activate
pip install -r requirements.txt --download-cache=/tmp/$JOB_NAME

and


. venv/bin/activate
which python

# reply should be
/home/user/.virtualenv/bin/python

Smart Doorbell using Raspberry Pi

About a year ago, I had to do a project titled Smart Home Automation using a Raspberry Pi and Arduino, part of the project  incorporated a doorbell but not just any doorbell but a Smart doorbell.

Why do I call it a Smart Doorbell?

A classic doorbell can be defined as a signalling device typically placed near an entry door to a building. When a visitor presses a button the bell rings inside the building, alerting the occupant to the presence of the visitor.

The smart doorbell, works in that manner however when a visitor presses the doorbell button it notifies the occupant with an images of the visitor and also sends an email, sms and push notification (to an smart device) to the occupant in case they are not able to hear the bell ringing.

If the button is pressed a pre-recorded voice notification is played for the occupant to check the door as there might be someone, this happens concurrently with an sms notification while a picture of the visitor is captured and sent to both email and push notification. Initially there was a feature to enable 2-way real-time video communication but due to network latency and high resource usage the feature was deprecated.

Click For A Demo

Comment if you need the code

See code snippets(Initial Revision): https://mmphego.wordpress.com/2015/01/11/smart-doorbell-using-rpi-with-voice-and-email-notification/

Sublime Text useful python snippets

For the past few months, I have been trying to move from using Geany to using Sublime Text as my primary text editor.

I find myself repeating some repetitive operations dozen times a day when coding in python, such as import IPython;IPython.embed() and etc.

So here are some of my Sublime Text snippets to enhance my productivity, and simplify my life.

Sublime Text 3 makes it super easy to create a snippet. You simply select Tools > Developer > New Snippet from the toolbar menu and you’re off to the races!

1. IPython debugger

Type ipyt and press tab to automatically insert IPython debugger under current pointer.

<snippet>
    <content>
        <![CDATA[import IPython;IPython.embed()]]>
    </content>
    <tabTrigger>ipython</tabTrigger>
    <scope>source.python</scope>
    <description>Interactive IPython debugger</description>
</snippet>

2. Docstring

Type docstring and press tab to automatically insert a numpy-style valid
docstring pattern right after your function definition

<snippet>
    <content><![CDATA[
"""${1:One liner description}
Parameters
----------
${2}
Returns
-------
${3}
"""
]]></content>
    <tabTrigger>docstring</tabTrigger>
    <scope>source.python</scope>
    <description>Adds a docstring skeleton to function</description>
</snippet>

and save your snippets with the .sublime-snippet file extension in /home/$USER/.config/sublime-text-3/Packages/User

Bachelor’s project demo

So after completing my diploma, and it becoming redundant in the working industry. I had to set my eyes on a Bachelor’s degree.
Trust me it was not easy, in the sense of being a part-time student, full-time employee, a father, a fiance and being stuck on some island for 15 months then when you come back you’re residing in Cape Town and the university in Pretoria.
I think I can write a book with my life’s story.

Long story short, I managed to complete my degree within 3.5 years instead of 2 – which was a bonus, And now I have set my eyes on a Master’s degree just to challenge myself one thing for sure, one doesn’t need to be stagnant in life.
I believe in continuous improvement of oneself.

Let me stop yapping and show you a demo of my Bachelor’s project

If you like give thumbs up.

Raspberry Pi – using GPIO / WiringPi without root (sudo) access

Dissection by David blog

Just needing to get this down quickly and succinctly…

The Raspberry Pi is super-fun for me as it’s a full OS (Linux, which I really like a lot) with Pins!  Current project: make a (private) website that will let me open/close and check my garage door.  Maybe more on this later.

SUPER frustrating is the inability for a web-server to control the GPIO pins on my Raspberry Pi because the web-server is not running as root.  Really?!?

View original post 336 more words

The Zen of Python, by Tim Peters

While browsing around the Interweb I found a little python poem – Words to-live-by in this world of Pythoning/Pythonian/Pythonization/Pythology or whatever its called.

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!