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

3D/GPU-related display problems with Atom editor on Xubuntu 16.04 VM

Was having a problem with Atom editor on a new Ubuntu/Xubuntu 16.04 virtual machine. Launching Atom using the --disable-gpu option seems to fix the problem:

$ atom --disable-gpu

Via discuss.atom.io.

Next, need to figure out how to modify the application launch item in the Whisker Menu so that it executes that command instead of the vanilla $ atom command.

 

Audio quality peculiarities on mobile YouTube app

I noticed a weird thing today, watching Harvard i-lab | Startup Secrets Part 1: Value Proposition – Michael Skok, and that weird thing was that the audio for this video sounded really bad when played through my iPhone 6S speaker but sounds totally fine when I plug my headphones in. There is definitely audible compression-related distortion even through the headphones but it’s not at all a problem for listening comprehension. In contrast, the audio is extremely difficult to understand when played through the iPhone speaker. I wonder if this is app shenanigans or if it is an interesting hardware (i.e. speaker + drive electronics) interaction with the raw audio signal from the YouTube stream. I am kind of hoping for a weird corner case where the speaker’s frequency response is emphasizing the distortion in the audio signal.

To be continued… hopefully…

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

 

CUPS and network printing on Linux

CUPS and network printing on Ubuntu GNOME 16.04, to be specific. CUPS is an open-source printing system for Mac OS, Linux and UNIX which I don’t know much about yet but appears to be pretty widely used judging by my limited googling.

Via Ask Ubuntu, a CUPS web dashboard can be accessed via the URL http://localhost:631/

Continue reading “CUPS and network printing on Linux”

Resetting a Brother HL-5250DN printer to factory default settings

I have an old Brother HL-5250DN black and white laser printer that I found via Craigslist. I want to set up the printer as a network printer on my home network — the first step is to factory reset the printer so that I can regain access to the admin control panel!

Continue reading “Resetting a Brother HL-5250DN printer to factory default settings”

Concatenating M4V files on Ubuntu 16.04

Hat tip My Web Experiences blog.

This is pretty neat. If you have two (or perhaps more) .m4v files that you want to concatenate, there is an open source package called gpac available for Ubuntu and Debian. Debian packages are available at the project website, and the source code is on a github repo.

The package is also available via the Ubuntu apt package manager. As of 2016 Dec 18, the latest release available via apt is 0.5.2, which is a bit behind the latest project release, 0.6.1.

While the package is called gpac, the command provided by the package used to concatenate M4V files is called MP4Box, and the syntax is:

$ MP4Box -cat video1.m4v -cat video2.m4v -new combinedvideo.m4v

This took maybe 5 minutes to combine two approx. 1 GB files on my Intel i5 from 2008.

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.