Getting autocomplete-python Atom plugin to work on Windows with WinPython

I stumbled around for a little bit with this one. The path to the Python executable must be set in the configuration settings for the Atom autocomplete-python package, and the part of the path with the executable filename must include the .exe filename extension.

For example, the full path to my WinPython executable is C:\Users\UserName\WinPython-64bit-3.5.3.1Qt5\python-3.5.3.amd64\python.exe. Entering this path exactly as shown here worked.

How to set the IPython/Jupyter Qt Console font size on WinPython

TL; DR: create a file called jupyter_qtconsole_config.py under .jupyter\ in the WinPython settings directory (e.g. C:\Users\user\WinPython-64bit-3.5.2.3Qt5\settings\.jupyter\jupyter_qtconsole_config.py) and write the line c.ConsoleWidget.font_size = 12, where the number is what you want the font size to be, in points.

On my Windows machine, for my Python setup, I use WinPython because it is super easy to set up, it’s self-contained, and, if I muck up anything, it is very easy to delete the install and start over. IDEs like JetBrains PyCharm can also be easily set up to point to the WinPython interpreter as well (File > Settings > Project > Project Interpreter) so you can benefit from all the IDE code completion, module analysis, introspection etc etc.

WinPython also comes with a ton of useful modules and “plugins” — Jupyter, IPython (and Qt Console), Spyder, and all the Scientific Python libraries: Numpy, Scipy, Pandas, Matplotlib, etc etc. Python is already “batteries included” — Winpython is like “nuclear reactor included.”

How to reload a Python module

Reloading a Python module can be useful if you are doing interactive testing and development. For example, say you are making incremental changes to a function and with each change you want to poke at it in an interactive console. Or, perhaps you are working in a Jupyter notebook rather than an interactive console. Same idea.

In Python 3.4 and greater, do this:


import importlib
import my_great_module
importlib.reload(my_great_module)

In Python 3 prior to 3.4 do this:


import imp
import my_great_module
imp.reload(my_great_module)

In Python 2, do this:


import my_great_module
reload(my_great_module)

A word of caution from the importlib.reload documentation:

When a module is reloaded, its dictionary (containing the module’s global variables) is retained. Redefinitions of names will override the old definitions, so this is generally not a problem. If the new version of a module does not define a name that was defined by the old version, the old definition remains.

This effect can be demonstrated by calling dir() on a loaded module before and after removing some module variables and reloading the module.

Here are some useful references:

  1. http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module
  2. http://stackoverflow.com/questions/5516783/how-to-reload-python-module-imported-using-from-module-import
  3. https://docs.python.org/3.5/library/importlib.html#importlib.reload

Using git config to fix settings and stuff

I am a bit of a git noob so I had to poke around a bit to figure out how to fix my user.email setting. Here are some snippets of useful git config commands and options to illustrate behavior.

Initialize empty git repo in dummy directory:


$ git init

Initialized empty Git repository in /home/mrmagoo/foogit/.git/

List all config items. These were created automatically when we executed the git init command because at some point in the past I had set them using git config --global --add:


$ git config -l

user.name=Mr Magoo
user.email=mr.magoo@mrmagoo.com
push.default=simple
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Remove the user.email global setting:


$ git config --global --unset user.email

$ git config -l

user.name=Mr Magoo
push.default=simple
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Re-add the user.email global setting but give it a different value this time:


$ git config --global --add user.email mr.magoo@gmail.com

$ git config -l

user.name=Mr Magoo
user.email=mr.magoo@gmail.com
push.default=simple
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Add a local user.email setting:


$ git config --add user.email mr.magoo@yahoo.com

$ git config -l

user.name=Mr Magoo
user.email=mr.magoo@gmail.com
push.default=simple
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.email=mr.magoo@yahoo.com

 

Bytes in Python 3.5

I’m working with os.urandom and I was puzzled by this output:

>>> x = os.urandom(16)
>>> print(x)
b'cCIp>\xfebUe\x02c\xc9\xbf5P\xe2'
>>> type(x)
bytes
>>> len(x)
16
>>> x[5]
254
>>> x.hex()
'634349703efe6255650263c9bf3550e2'
>>> x[0]      # ASCII code for 'c' is 99 (decimal)
99
>>> hex(x[0]) # ASCII code for 'c' is 63 (hexadecimal)
'0x63'
>>> hex(x[5])
'0xfe'

This question on StackOverflow clears things up greatly.

print(x) displays a “mixed hexadecimal/ascii” representation of the bytes object x. Bytes that correspond to ASCII characters are displayed as ASCII characters, and bytes that do not are displayed in hexadecimal notation. Which is a little bit confusing if you aren’t expecting it.

Curated lists on Github

There are a large number of list repositories on Github spanning dozens of subjects. There is a sort of in-joke in the naming convention: they are for the most part named “awesome-{topic}” e.g. awesome-sysadmin. Someone (bayandin) on Github totally beat me to this, but here’s a partial list (unfortunately in no particular order at this time):

sysadmin
python
awesomeness 
java 
node.js 
javascript
tools of the trade
iOS
shell
vim and tmux
ruby
android
android (JStumpp)
big data
php
swift
swift (Wolg)
react
courses
electron
go
data science
svg
flask
machine learning
.NET
front-end development
public datasets
vue.js
django
R
web performance optimization
algorithms
tensorflow
elixir
images
computer vision
networking
mac OS
npm
working remotely
rails
C (not github)
MaterialDesign (google UI visual design philosophy)
UI motion library animations
emacs
READMEs
interview questions
REST
bioinformatics, machine learning, data science, related languages
security
application security
hacking
sci-fi
rust
windows
talks
natural language processing (NLP)
swift education
nodejs (vndmtrx)
internet of things (IoT)
opengl
information security (infosec)

Installing Visual Studio Code on Ubuntu 16.04 using dpkg

Yesterday I posted a note about manually installing the Atom editor on Ubuntu 16.04 using dpkg. A friend recommended that I try out Visual Studio Code for Python development, and I was pleased to discover that it is available in a .deb package for install on Linux. I used the same command to install the VS Code .deb:

foo@manchoo:~/Downloads$ sudo dpkg -i code_1.4.0-1470329130_amd64.deb 
[sudo] password for foo: 
Selecting previously unselected package code.
(Reading database ... 303742 files and directories currently installed.)
Preparing to unpack code_1.4.0-1470329130_amd64.deb ...
Unpacking code (1.4.0-1470329130) ...
Setting up code (1.4.0-1470329130) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160415-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
foo@manchoo:~/Downloads$ 

 

Virtualenv, a python tool

From the docs:

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtualenv can help you. It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).