Category Archives: Code

Redcarpet errors when using Yard or Changing Yards markup provider

* Note, I’m not going to talk about how to make Redcarpet work. Instead I’m going to explain how to get Yard generating documentation again with a redcarpet alternative.

Maybe I’ve just been unlucky but I’ve had a number of run ins with Redcarpet when using Yard over the years. I’ve learned that Yard can use a number of markup-providers besides the Redcarpet gem.

For search purposes, here’s the verbage for my current scuffle with Redcarpet:

[error]: Missing ‘redcarpet’ gem for Markdown formatting. Install it with `gem install redcarpet`

To replace that redcarpet dependency:

1) generate a /.yardopts file if it doesn’t already exist. Any configuration you provide in there will be picked up regardless if you run yard directly or some Rake task calls yard with additional parameters.

2) Append a parameter to change the markup-provider.

--markup-provider <some markup-provider>

Screen Shot 2015-03-05 at 10.39.01 AM

More options for a markup-provider beyond rdiscount are listed at: http://www.rubydoc.info/gems/yard/YARD/Templates/Helpers/MarkupHelper

3) Finally, ensure your Gemfile lists your new markup-provider.

Screen Shot 2015-03-05 at 11.47.04 AM

Posted in Code, Ruby | Leave a comment

Mount a filesystem over SSH on OSX (sshfs)

1) Download & install FUSE for OSX.

2) Create an empty local folder to act as a mount point.

3) Mount the filesystem over SSH.

Syntax:

sshfs <username>@<IP or URL>:<remote path> <path to local mount point>

Example:

sshfs bilbo@theshire.com:/var/www/bagend ~/Desktop/mnt

I’m not a huge fan of using Vim or Nano/Pico for lengthy editing sessions on remote servers. This allows me to use Sublime Text (or whatever your editor of choice). I’ve not encountered any latency issues and it’s much smoother than forwarding X (which I never have installed on a webserver anyway).

 

Posted in Code, Linux, OS X, Uncategorized | Leave a comment

OS X Command Line Tools no longer a part of Xcode.

Apple has again changed how its command line tools are packaged. Whereas it was once bundled into Xcode and then later you had to instead manually download it from within Xcode, it is now separated from Xcode altogether.

In some earlier versions of Xcode 5 you could run a command in the terminal and still get the download option to show up in Xcode but that no longer seems to be an option. At least as far as Xcode 5.1.

Now you need to download the command line tools from Apple’s developer site.

dl_cli_tools

Posted in OS X, Xcode | Leave a comment

Vagrant error: Your VM has become inaccessible.

If you’ve deleted a virtual machine file still referenced by one of your projects, you’ll run into the following error when you try and instantiate the VM via vagrant up.

Your VM has become “inaccessible.” Unfortunately, this is a critical error with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox and clear out your inaccessible virtual machines or find a way to fix them.

Vagrant creates a hidden folder within your project directory named .vagrant with files that refer to specific VM IDs.

.vagrant

Simply delete the .vagrant folder within your project and rerun vagrant up. Vagrant will rebuild the .vagrant directory with the correct files and ID.

For giggles, here’s a Github issue page regarding this with a few more details.

Posted in Code, Devops, Vagrant, Virtualization | 37 Comments

Skipping tests in specific browsers or Phantom.js / Grunt.js build scripts

I’m working on a project that I’ve built a very comprehensive Javascript test suite for with QUnit. I run tests a few times in a few different ways before subjecting the world to my code.

First I load the QUnit test page in multiple browsers to ensure I’m not going to be bitten by a cross-browser compatibility bug (IE). 

qunit

Afterward, when I run my Grunt build script to check, concatenate, and minify my JS, it re-runs those tests before concatenating, after concatenating, and finally on the minified version as well.

Occasionally I run into some false positives (failed tests) that are tied to some browser quirk like Chrome not allowing file cookies (unable to set cookies when the URL is local: file:///…) or the fact that PhantomJS isn’t a true browser so it isn’t able to handle cookies gracefully. Don’t skip writing tests for troublesome bits, instead just conditionally skip those tests based on user agents.

For example, I have two test helpers in a file test_helpers.js:

var helpers = {
	// Determine if tests are running in Chrome
	is_chrome: navigator.userAgent.toLowerCase().indexOf('chrome') > -1,

	// Determine if tests are running in PhantomJS.
	is_phantom: navigator.userAgent.toLowerCase().indexOf('phantom') > -1,
};

I include test_helpers.js file into my QUnit test page(s). Then I wrap any tests that succumb to environment issues in an if statement:

test('Session creates a session & cookie upon instantiation (TEST SKIPPED IN CHROME! WILL NOT PASS).', function(){
	if(!helpers.is_chrome && !helpers.is_phantom){
		// Test that runs only outside of Chrome and Phantom.js
	}
});

My troublesome QUnit tests will run in all clients except those I’ve explicitly avoided. My tests run green in both Chrome and my Grunt build script.

grunt_qunit

Posted in Code, Grunt.js, JavaScript, QUnit.js, Uncategorized | Leave a comment

RVM error on OSX: Can not find compiler and ‘make’ tool

Running afoul of the following error when trying to install rubies with RVM despite having installed Xcode?

Can not find compiler and ‘make’ tool – make sure Xcode and/or Command Line Tools are installed.

With newer versions of Xcode the command line tools RVM expects are not automatically installed alongside Xcode.

Open Xcode and navigate to: Xcode > Preferences > Downloads and click Install for Command Line Tools.

Posted in Code, OS X, Ruby | Leave a comment

Xcode can’t be installed because Mac OS X Version N or later is required.

So, say you need Xcode installed (or updated) because you need GCC and/or other development support tools on your OS X 10.7 machine. So, you launch App Store expecting to install (or update) Xcode easily enough but are met with one of two messages telling you that you’re SOL.

no-install
No install
no-update
No update

At this point it seems like you’re forced into paying to upgrade OS X but there’s an alternative. Albeit, not an obvious one. You can download older version of Xcode if you have or create an Apple developer account. The direct link to the Xcode downloads page is: https://developer.apple.com/downloads/index.action?q=xcode

Note: If you’re running OS X 10.7 you’ll need (as of this writing) to install Xcode 4.6.3 as Xcode 5 requires OS X 10.8.

xcode download page

It just works, right?

Posted in Code, OS X, Uncategorized | Leave a comment

Vagrant error on OSX: Command: [“hostonlyif”, “create”]

I’ve found I occasionally run into an odd Vagrant error every now and then:

There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

Command: [“hostonlyif”, “create”]

For me, this sometimes happens when I try to re-instantiate a virtual machine after my laptop’s battery has died and OSX has attempted to restore state. Other people seem to encounter this error under different conditions; even immediately after installing Vagrant and attempting to spin up a virtual machine for the first time.

Run the following command to bounce VirtualBox:

sudo /Library/StartupItems/VirtualBox/VirtualBox restart

and now running:

vagrant up

should go off without a hitch.

Posted in Code, Devops, OS X, Vagrant, Virtualization | Leave a comment

Python Properties Not Working Correctly?

Today I was trying to implement the observer pattern in Python, updating the observer with property methods, but my code was acting wonky. Specifically, my setter wasn’t calling a method it was supposed to be calling.

TL;DR version


If properties aren’t functioning like they should, ensure that your classes are inheriting from object. Your classes don’t automatically inherit from object (or the featured base class) in Python like in some other languages (in python this is for the sake of backwards compatibility). Use:

class MyClass(object):

instead of

class MyClass:

Long version


Here’s the basic observer pattern in Python (Notice not inheriting from object):

class ObjectOfInterest():
  def __init__(self):
    self.observers = []
    self._name = None

  def register_observer(self, observer):
    self.observers.append(observer)

  def _get_name(self):
    return self._name

  def _set_name(self, name):
    self._name = name
    self._update_observers()

  # I prefer this method of setting up properties over the @ syntax
  name = property(_get_name, _set_name)

  def _update_observers(self):
    for observer in self.observers:
    observer.update()

class Observer():
  def __init__(self, thing_to_watch):
    self.thing_to_watch = thing_to_watch
    self.thing_to_watch.register_observer(self)

  def update(self):
    print("updated.")

Pretty straight forward, right? However, _update_observers() is never called. You will not see “updated.” printed to the console. Everything seems like it’s working; the value of name is being updated. So WTF?!

thing_to_watch = ObjectOfInterest()
observer = Observer(thing_to_watch)

print(thing_to_watch.name) # None

thing_to_watch.name = 'Bilbo'
print(thing_to_watch.name) # Bilbo

thing_to_watch.name = 'Frodo'
print(thing_to_watch.name) # Frodo

Remembering to inherit from object gets properties working right. Here again is the code with output but this time my classes do inherit from object and everything is right with the world.

thing_to_watch = ObjectOfInterest()
observer = Observer(thing_to_watch)

print(thing_to_watch.name) # None

thing_to_watch.name = 'Bilbo' # updated.
print(thing_to_watch.name) # Bilbo

thing_to_watch.name = 'Frodo' # updated.
print(thing_to_watch.name) # Frodo

This is a sloppy mistake that had me guessing for a good bit. Nothing was out of place and yet my results were borked.

Posted in Code, Python | Leave a comment

Error: “Association named ‘spree_roles’ was not found; perhaps you misspelled it?”

ActiveRecord::ConfigurationError:
Association named ‘spree_roles’ was not found; perhaps you misspelled it?

I ran into this error while developing an extension for Spree 1-3-stable and writing request specs to run on the dummy test app generated via bundle exec rake test_app. You may have also run into this error on a normal Spree app if you installed Spree in your Rails apps using just your Gemfile and bundler instead of spree install <my_store>.

Regardless, this is an issue with Spree not setting the correct user model in the spree initializer during install. To correct this, update config/intializers/spree.rb to use:

Spree.user_class = "Spree::User"

instead of

Spree.user_class = "Spree::LegacyUser"

If you’re having this issue with the dummy test app in spec/dummy, just do the same for the dummy app’s initializer: spec/dummy/config/initializers/spree.rb

For more information:
See the issue for dummy test_apphttps://github.com/spree/spree/issues/1966
See the issue for regular Spreehttps://github.com/radar/spree_auth_devise/issues/1

Posted in Code, Ruby, Spree | 2 Comments