OSX 10.6.5 breaks Apachectl

Trying to run:
sudo apachectl restart

Are you getting:
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

Edit your /usr/sbin/apachectl on line 65 from:

ULIMIT_MAX_FILES="ulimit -S -n ulimit -H -n"

to:

ULIMIT_MAX_FILES=""

and try again. It should now be working agian

For more information checkout Deversus

Learn More

Blog’s back up! (and a little update about Anlek Consulting)

I’m happy to say that the blog is back!

Sorry for how long we were down but Anlek Consulting has moved offices and the local server (which was running this blog) was taken down and couldn’t be brought back up. So now we have a new home which should give us a better up time.

A little update on what’s going on at Anlek Consulting. I (Andrew) will be doing a trip around Canada and the USA, hoping to be working on the road with my cell phone and free wifi spots. In light of this, I’m going to probably blog a bit more about the challenges and adventures of working on the road. Stay tuned for some fun posts!

Learn More

Stripping ASCII colour from a ruby string

I spent a few good hours trying to figure out how to strip a coloured ruby string:

Coloured Ruby String

which comes out as this:

>> p t
"2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"
=> nil

Now I tried to gsub the string and remove the colour using a RegEx like this:

> t.gsub(/\e[(d+)m/, "")
=> "2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"

But as you can see, nothing changed. After reading a whole lot of docs on Ruby, Googling around and reading the Ruby String class I came to this conclusion:

>> b = "e[33m"
=> "e[33m"
>> b.each_byte{|c| puts c}
27
91
51
51
109
=> "e[33m"
>> "" << 27 #The only way I know how to add ASCII codes to string
=> "e"

Now what this allowed me to do is figured out the ASCII code for the e character. However because normally you escape the back slash on regular expressions, once I figured out e was a valid character, I got this:

>> "e[33m".gsub(/e[(d+)m/, '')
=> ""

I hope this saves someone a few hours!

Learn More

MongoMapper – undefined method ‘reflect_on_association’

Information Tidbit:

If you’re using reflection_on_association with ActiveRecord and need to use it with MongoMapper, here is what you want to do:

undefined method `reflect_on_association' for User:Class

ActiveRecord:
User.reflect_on_association(:posts).klass.new

MongoMapper:
User.associations[:posts].klass.new

Mongoid:

User.associations['posts'].klass.new
notice the posts is a string, it will not work with a symbol

UPDATE – (Apr 2011) Mongoid now follows ActiveRecord’s style naming:

User.reflect_on_association(:posts).klass.new

Learn More

Getting Paperclip to work with MongoMapper

Last night I was trying really hard to get MongoMapper to work with Paperclip via GridFS and failed. It seems right now Paperclip or even CarrierWave are not ready to be used with the latest MongoMapper drivers and GridFS (and I needed to use the latest drivers due to Scopify).

After giving up using GridFS, I wanted to use Paperclip with MongoMapper with the normal file system and I found this article from Ben Curtis, however with the latest version of Paperclip (version 2.3.1.1) and MongoMapper (version 0.7.6) I was unsuccessful, kept getting:

Anonymous modules have no name to be referenced by

After reading the backtrace and diving into the paperclip source code I noticed that it was trying to use the ActiveRecord.logger and since I’ve removed ActiveRecord from my app, it was failing (with the odd error).

After some tweaking of Ben’s code, I came up with this: http://gist.github.com/424158

Learn More