Friday, April 11, 2014

Vagrant can't mount shared folder in VirtualBox 4.3.10 Fix

Setting up Virtualbox/Vagrant today on a new Windows 7 PC and ran into this problem while that my host directory wouldn't mount /vagrant during vagrant up.

jbisbee@jbisbeewin7:~/vagrant/test$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
GuestAdditions seems to be installed (4.3.10) correctly, but not running.
stdin: is not a tty
Starting the VirtualBox Guest Additions ...done.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/cygwin64/home/jbisbee/vagrant/test
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

First thing I did was ssh to the vm and run the commands:

vagrant@precise64:~$ sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount: Protocol error
vagrant@precise64:~$ sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant
mount: Protocol error

After just getting "Protocol error", I looked at the syslog and seeing "sf_read_super_aux err=-71".

Apr 11 17:56:40 precise64 kernel: [   18.253255] sf_read_super_aux err=-71
Apr 11 17:56:40 precise64 kernel: [   18.344137] sf_read_super_aux err=-71

Now googling this error, I found Vagrant Bug #3341 from 15 days ago and the missing symlink that caused it all

vagrant@precise64:~$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

Success! :)

jbisbee@jbisbeewin7:~/vagrant/test$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
GuestAdditions 4.3.10 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/cygwin64/home/jbisbee/vagrant/test
==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it



Tuesday, April 8, 2014

Getting Started with pylint


Being somewhat new to Python, I figured I'd give pylint a try. In Perl we have perlcritic which serves a very similar function (although in Perl files are parsed in a DOM-like way because as some of us painfully know, the only thing that can truly parse Perl is Perl).

Setting Up

First things first, let's setup a test virtualenv so we don't clobber anything. If you want to install globally or already have a project you'd like to lint, skip this step.

jbisbee@beni:~$ mkvirtualenv test
New python executable in test/bin/python
Installing
Setuptools.............................................................................................done.
Installing
Pip....................................................................................................................................done.

Now pip install pylint

(test)jbisbee@beni:~$ pip install pylint
Downloading/unpacking pylint
...
Successfully installed pylint logilab-common astroid
Cleaning up...

So out of the box I get a warning message saying I don't have a default configuration. Before I start looking at the output, I figure I should probably figure out where the defualt rcfile is stored (~/.pylintrc) and what format its in.

jbisbee@beni$ pylint sample.py
No config file found, using default configuration
...

Generate Your ~/.pylintrc File

Lucky for us, the authors have included the handy --generate-rcfile switch that will generate one for you. The rcfile generation option also takes into account all switches you pass into pylint and will include those in your resulting file. The rcfile is printed to standard out which you can just redirect to your .pylintrc file in your home directory.

(test)jbisbee@beni:~/src/test$ pylint --generate-rcfile > ~/.pylintrc

Explore and Tweak To Your Liking

The resulting file is pretty lengthy, but I'd like to highlight some of the various options and sections that I took interest in. I took some of the descriptions directly from the documentation. disable=
Disable the message, report, category or checker with the given id(s). If you or your team ends up choosing not to enforce certain errors or warnings that pylint produces, just add the error number (or in later versions, the human readable string) to disable the messages from showing up.

output-format=colorize
Set the output format. Available formats are text, parseable, colorized, msvs (visual studio) and html. You can also give a reporter class, mypackage.mymodule.MyReporterClass. Going to default to colorize.

reports=no
Tells whether to display a full report or only the messages. No reports by default for me.

max-line-length=120
Maximum number of characters on a single line. I'm going to set this from 80 to 120. Purists out there, all I have to say is, "Haters gonna hate." :)

generated-members=objects
List of members which are set dynamically and missed by pylint inference system. Django ORM's 'objects' is only value I have presently. Feel free to suggest other common generated members.

Similarities Section
Similar lines in %s files Indicates that a set of similar lines has been detected among multiple file. This usually means that the code should be refactored to avoid this duplication. I love the idea that pylint does this and I'd like to get some feedback for folks who encountered this error and how accurate it was.

Design Section
This sections is my favorite. It points out possible design flaws in your code based on a set of rules you can tweak. I consider my OO design to be pretty darn good, but as I was quickly porting a simple all in one command line program into classes, I got flagged with 'max-attributes' error. The error states if that you have more than 7 attributes you're most likely doing something wrong. (I had 8) It pointed out 5 of those attributes belonged in a separate class of their own and made my design cleaner (which never really hurts)

IDE/Editor Support

One of the coolest things about pylint is the IDE/editor integration that can give you real time feedback as you're coding. Visit the IDE integration page on the pylint website for more information. Going attempt to setup pylint.vim soon. :)

Would Love Your Feedback

Hey guys, I'm writing these blog posts as an exercise to teach myself and hopefully have others who are in my position, stumble upon my blog posts and actually do them some good. If you have some valuable input, point out pitfalls, or just to say thank you, I would greatly appreciate it.

Sunday, April 6, 2014

Fix for iTerm2 Numeric Keypad Not Working


I'd had to fix this a couple of times now on various computers and figured I'd just post the answer in case I ever have to do it again.
By default the numeric keypad sends function key codes. You can turn that off by selecting the "xterm with numeric keypad" preset in Preferences > Profiles > Keys.
https://code.google.com/p/iterm2/issues/detail?id=2000
For those of you who don't use iTerm2, I highly recommend it. One of my favorite features is enabling semi-opaque transparency and blur so I can still code and not be distracted the background artifacts. The settings can be found in Preferences > Profiles > Window


And these settings end up looking like this

Saturday, April 5, 2014

Speed Up Key Repeat Input on Your Mac

So I'm happy to be blogging again and I though I'd start by sharing a hack I ran across a couple of months ago.  It involves adjusting the OSX Key Repeat setting to a lower value that what the GUI allows.  This setting is great for developers like me who sometimes navigate through code using arrow keys or like to quickly delete something by holding down the delete key.

System Preferences > Keyboard



Now the GUI presently allows you to set Key Repeat to a minimum value of 2, which for many folks, doesn't seem to be fast enough. We can change the value to 1, but before we do, take note of your current setting with the following command.


jbisbee@beni$ defaults read NSGlobalDomain KeyRepeat
30

Now to set the value to 1, we can use the following command. Unfortunately, you will need to reboot to have the change take affect.

jbisbee@beni$ defaults write NSGlobalDomain KeyRepeat -int 1

In the event you don't like the result, simply run the command again with your initial value.

jbisbee@beni$ defaults write NSGlobalDomain KeyRepeat -int 30

If someone knows the mac command to reinitialize, please share. :)