Archive for the ‘Uncategorized’ category

Rails + WordPress (at the same time)

June 1st, 2010

It is a Sin to be a “Rails programmer” and not use a blogging engine you wrote yourself and especially in Rails, but there are cases when one’s available time is more important than one’s soul.

This particular case assumes you use shared hosting.  That’s probably another bad thing, but whatever.  Also, you need access to your public_html folder’s .htaccess file.  In fact, this whole setup is so host-specific that you might find it worthless.

Starting over.  Shared host.  public_html folder. Apache. Your host routes traffic to your app by rewriting your requests via a proxy to a specific port.

Now let’s say you have the domain www.domain.com.  Your host does something like:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$

RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12%{REQUEST_URI}" [P,QSA,L]

Note: port numbers have been changed to protect the innocent.

This basically just says “if a request hits me and the host matches your domain, I’m gong to proxy it on to myself on a different port.”  The webserver runs a request against itself on a different port, which presumably is picked up by whatever handles your Rails application.

Well, you want your blog to be at http://www.domain.com/blog.  That unfortunately does contain your domain in the HTTP_HOST.  Which means Rails will try to serve up your blog.  Which means it will fail or, if you actually have your blog in your app’s public folder, will serve up your .php files as raw text downloads.

Solution:

RewriteCond %{REQUEST_URI} !^/blog/(.*)$
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12%{REQUEST_URI}" [P,QSA,L]

We add an additional condition to our rewrite requiring that the actual path requested (Apache’s REQUEST_URI expands to that) NOT match “/blog/” followed by pretty much anything.  This will get your webserver to handle all of these requests as if your Rails app weren’t there, which is what you’re going for anyway.

This isn’t limited to WordPress.  And note that whatever you are trying to run needs to be in your Apache DOCUMENT_ROOT folder.  That could be like “public_html” or something.  I don’t know the answer to that for you.  You CAN work around that with other directives, but that is beyond the scope of this entry.

Rails 2.3.5 doesn’t play well with Rack 1.1.0

February 16th, 2010

Ever get this gem when running a Rails 2.3.5 application with Thin?

/Users//config/../vendor/rails/railties/lib/initializer.rb:271:in `require_frameworks': can't activate rack (~> 1.0.1, runtime) for [], already activated rack-1.1.0 for ["thin-1.0.0"] (RuntimeError)
from /Users//config/../vendor/rails/railties/lib/initializer.rb:134:in `process'
from /Users//config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from /Users//config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /Users//config/environment.rb:13
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/rack/adapter/rails.rb:31:in `load_application'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/rack/adapter/rails.rb:23:in `initialize'
... 6 levels...
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:139:in `run!'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/bin/thin:6
from /usr/bin/thin:19:in `load'
from /usr/bin/thin:19

Disappointing to be sure, but there’s a simple fix I found here.  Thin will try to load the latest version of Rack that you have installed, but Rails specifically asks for 1.0.1.  You can’t have 2 versions of it running at the same time, so RubyGems pukes.

The simple solution is to uninstall Rack 1.1.0.  If that isn’t an option for you, dang.  There’s always this rails ticket you could go fix and make a big name for yourself in the community. ;)

How to freeze gems in Rails

February 1st, 2010

http://blog.logeek.fr/2008/12/23/how-to-freeze-gems-with-rails-2-1

shoulda and factory_girl not cleaning up db between tests

December 22nd, 2009

Wow, this one was a doozy. I recently (yesterday) had my first introduction to shoulda and factory_girl for testing. I’m torn as to whether or not fixtures are the root of all evil, as I haven’t really encountered problems with them and find them very simple to use and maintain, but that isn’t the point of this post.

The point is that just starting a new job I figured a good thing to do was first run the unit tests to make sure I had set up the app properly. I was treated to many failures and investigated why. I found many failures caused by a polluted database. Previous tests weren’t cleaning up after themselves, so later tests had bad state (duplicate records and that sort of thing). While that may be a plug for database level enforcement of that kind of rule, that task was beyond the scope of what I was doing.

I scoured Google looking for answers, and a day later I finally found it. Just to stretch you along even further, here’s what it wasn’t:

  • shoulda not running implicit teardowns
  • transactional fixtures being turned off

No, it was a great deal dumber than that, and a thanks to Eric Artzt, whoever you are, for providing the solution. The table that was giving me fits is a MyISAM table, which doesn’t support transactions. Which means there are no rollbacks to clean up my DB state. Which means I either have to explicitly put calls to do that into an explicity-defined teardown method or switch the engine on the table in question.

Apple never ceases to amaze me

April 30th, 2009

I can’t actually post screenshots, because it’s a work project again.  I got some html documents from our graphic designer, and I wanted to incorporate them into our code base.  Wanting to just get at the html code, I figure a simple text editor would do that for me.  I used Apple’s cra… amazing text editor TextEdit, foolishly thinking that like notepad or writepad on Windows I would see, you know, the text of that file.

This idiotic Apple piece of software tried interpreting the html document and rendering it as would a web browser.  I don’t see any mode switcher which would allow me to actually see the html either.

With absolutely 0 toolbars or the like for editing the content in a WYSIWYG manner, I’m dumbfounded.  How could that possibly be the best way to open this document?  If I used Dreamweaver, I could understand, because Dreamweave actually supports graphical development of html documents.  But it also has a simple and easy-to-find mode switcher to let me go back and forth.  And in that case, I still find the visual designer useless.

“Text”Edit has 0 graphical support that I can see (because Apple things are supposed to “just work” and be “intuitive,” I feel fine setting the bar that high) and no visible way of switching to “text edit” mode.

1 more example of Apple not living up to the hype surrounding.  In the 1 year+ I’ve been using the Mac platform I have been so underwhelmed.  It is every bit as frustrating as Windows, just in different areas.  If you like Apple’s stuff and can get work done with it, great.  Continue to do so.

The actual hardware is prettier though.  It’s nice that the Eye on the laptop’s lid lets everyone know how creative and unique I am.

And so I don’t lose the email, a link to a git recipe: renaming your ‘master’ branch

April 27th, 2009

http://www.dmo.ca/blog/20080307124544

Git recipe: creating a new local branch and getting it pushed to remote repo

April 27th, 2009

There may be better ways.  “Recipe” implies process given to me, and it gets the job done.  I have better things to do (i.e. projects) than play with SCM.  Azeroth isn’t going to save itself…

1. Create new branch locally

git branch <new branch name> <old branch name>

2. Push new branch to server

git push origin <new branch name>

3. Make sure changes to new local branch go to remote version (unsure if this step is necessary, as I’ve never tested not doing it)

git branch -D <new branch name>

4. Check out the new branch again

git checkout -b <new branch name> –track origin/<new branch name>

Adding a project to cruisecontrol.rb with git and on a different branch

December 18th, 2008

While I’m at it…

./cruise add <project name> -r <repository url> -s git -b <branch name>

Apple strikes again

December 18th, 2008

This time it’s with TextEdit, which is probably WAAAAAY better than Notepad, because Micro$oft didn’t write it.

Well, true to Apple’s form of thinking its users are too dumb to know how to use a computer, I found out that TextEdit does not let you choose what extension to put on a file.  I’m doing a MySQL create table statement, and copying/pasting the results of a show create table statement was overloading the terminal window– really weird text was coming out, and MYSQL couldn’t make sense of it.  So I decided to paste it into a simple text editor, save that as a .sql file, and then import that into the database via the command line.

Now, I know that file doesn’t have to have a .sql extension.  I like it that way though, and seeing how I’m the user, the computer should listen to me.

So what happens when one goes to specify one’s own extension on a file in TextEdit?  One is treated to the following dialog box (which is modal, of course):

An Apple staple

It isn’t particularly difficult to save a file with a different extension, and Apple’s philosophy of hiding any sort of file-system-level issues from ALL users weakens TextEdit’s usefulness.  When I’m using a Windows machine and need to quickly test something in HTML (for example), I load up Notepad, quickly enter the snippet under test, and then save it as an HTML document.  I would not have any such luck as a TextEdit user.

Am I left the option of changing the extension in Finder after?  Sure.  But that requires leaving TextEdit, finding the file, praying that I can even see the extension, and so forth.  Not the gold standard of usability.  Do I have a more able text editor on the machine?  Yes, TextMate, but it’s a bloated monstrosity (ever done a ‘Find in Project?’) without the power of Visual Studio, and it doesn’t come to mind for quick editing tasks.  And yes, in this particular example, the extension didn’t actually matter because thankfully mysql is better software than TextEdit.  The point is, I should be able to use a different file extension if I want to. Not all users are as scared of the file system as you think Apple.  Leave us the option!

This is yet another reason why I would never spend any of my own money on an Apple computer.

Edit: So, I got mad and wrote the post.  Then I gave the file the extension I wanted and tried importing it into my database, only to be greeted by the following error: ERROR 1049 (42000) at line 1: Unknown database ‘tf1ansiansicpg1252cocoartf949cocoasubrtf350′.  I thought, “I sure don’t remember specifying database tf1ansiansicpg1252cocoartf949cocoasubrtf350.”  TextEdit is serious when it says it only does .rtf files.  That polution of a .sql script is quite normal for an .rtf.  So Apple does not provide a plain text editor, or if TextEdit does do plain text, it isn’t readily apparent.

2nd edit: apparently it does other file formats, if you choose them from a drop-down menu on the save dialog box.  However, you’re still locked into the extension associated with the format.  And it doesn’t have a plain-text option.  TextEdit still loses.

Last night’s VP debate

October 3rd, 2008

I’ll have some other topics to post after this one, but I just wanted to address 1 issue quickly– the debate moderator.  I’ve seen a fair share of debates, what with the primaries and all, but I just have to say I have never been so impressed with the moderator.

I was fearful like I’m sure many conservatives were that Ms. Ifill would favor Biden, seeing how she has The Book coming out on Innauguration Day.  I saw no bias.  And above and beyond that, I liked her style of asking questions.  I’ll have to edit this post with more details once I’ve rewatched the debate.

So hats off to you Gwen.  The questions were informative, fair, and kept the debate lively.