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. :)


Saturday, July 27, 2013

python-shell-enhancement - Add History and Tab Completion to the Default Python Shell

I decided to take the blog post I wrote earlier this month, Add History and Tab Completion to the Default Python Shell, and commit code to github under the name


I updated the script with feedback I got from the blog and reddit and fixed tab completion to work correctly on a mac by default.

Friday, July 26, 2013

Double Window Sniper Bonk

This is a blatant geek post because playing Team Fortress 2 is one of favorite hobbies. Anyone who knows me (gaming-wise), knows I like playing the Double Cross map. On this map there is a underhanded tactic called window sniping where a sniper stands sideways in he window and is able to shoot into the enemy courtyard. The other day, two snipers were hanging out in the window and I managed to get this screen cap of me taunt killing them both. Double Bonk!

Tuesday, July 23, 2013

Introducing virtualenvwrapper-django

I recently took one of my previous posts entitled "Never Have to Type "python manage.py" with Django Again", and combined it with another bash function to auto set DJANGO_MODULE_SETTINGS by interrogating a Django project's directory. I then rolled everything together into github as


Its a little rough I admit, and I welcome any feedback for improvements.  As a result, I'm now able to run commands like the following anywhere once I have my virtual environment loaded.

(spock)jbisbee@tacquito:~/src/spock$ manage dbshell
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.5.31-0ubuntu0.12.04.2 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Edit: I've gotten some feedback and I realize I didn't sell the real reason behind dynamically setting the DJANGO_SETTINGS_MODULE variable. I use Django at work and we have moved from the generic one file settings.py to a settings directory which looks something like this

  settings/
    base.py
    dev.py           # imports from base.py
    test.py          # imports from base.py
    production.py    # imports from base.py
    jbisbee.py       # imports from dev.py

This way you can have cascading Django settings with overrides at multiple levels. This bash function I wrote finds the settings directory and will set DJANGO_SETTINGS_MODULE to the user's specific dev settings (or dev if the user can't be found)

DJANGO_SETTINGS_MODULE=projectname.settings.jbisbee

This way in jbisbee.py I can override my database, turn on crazy debugging, or do anything else I want and be able to commit those settings without affecting others.

Disclaimer: If you manage your Django project's settings differently let me know. I'd love to make the determine_django_module_settings more flexible and patches are more than welcome!