Archive for the ‘software’ category

Paperclip/ImageMagick/RMagick error: “is not recognized by the ‘identify’ command”

December 30th, 2009

If you’re using the above combination, and you’re getting the above error, make sure that you’ve configured Paperclip to find ImageMagick in the right place.  Create an initializer file, RAILS_ROOT/config/intializers/paperclip.rb, and put “Paperclip.options[:image_magick_path] = ‘path/to/image_magic’” inside of it.  On Mac or a *nix system, type “which identify” to find the right folder.

Big thanks to avit on this forum for the solution.

Installing Ruby gems that require building native extensions on Snow Leopard

December 18th, 2009

I haven’t tested this on all “machines” running Snow Leopard, but on the brand new one I had to get today for work, I found that the default Ruby / Gems install doesn’t support installing gems that require building native extensions. The error message I was treated to contained the following:

MacBook-Pro-de-Ethan-Garofolo:~ juanpaco$ sudo gem install thin
Password:
Building native extensions. This could take a while...
ERROR: Error installing thin:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install thin
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10/ext/gem_make.out

The solution was hyper-intuitive. Install XCode. Because of course that's the first thing you think of.

Renaming a database in Rails

December 14th, 2009

Hooray for a non-rant post!

The heart of this method works outside of Rails, but there’s one particular convenience method that Rails provides.  Find some way to mimic that behavior, and the rest would apply.  Also, this is a MySQL-specific solution.  I haven’t tried it with any other DB systems.

We “rename” a database by moving all of its tables into a new database.  We do so via MySQL’s RENAME TABLE command.  Basically, create an empty database with the new name.  We then use our ActiveRecord connection’s “tables” method to loop over all the tables in our database, executing a RENAME TABLE from the old to the new with each iteration. “Tables” is the convenience method I mentioned above. Encapsulating this in a method we get:

def rename_database(old_db_name, new_db_name)
    ActiveRecord::Base.connection.execute "CREATE DATABASE #{new_db_name}"
    ActiveRecord::Base.connection.tables.each do |table|
        ActiveRecord::Base.connection.execute
            "RENAME TABLE #{old_db_name}.#{table} TO #{new_db_name}.#{table}"
    end
    ActiveRecord::Base.connection.execute "DROP DATABASE #{old_db_name}"
end

Error checking is left as an (important!) exercise to the reader.  Also, you may prefer to monkey patch this into ActiveRecord itself as opposed to some odd method floating around in global space.

This presupposes that the new database destination will be on the same server.

Another way to rename a database is to mysqldump the old one to a file and then reimport it to the renamed database.  The method presented in this article is advantageous if your database has a large amount of data.  Renaming a table is almost instant.  Dumping millions of rows and reimporting them is not so instant.

SubSonic Post 1

November 29th, 2009

I’m trying out SubSonic for my personal finance management tool, Budgeteer, that I’m creating.  The experience thus far has been frustrating. I’m quite keen on straightforward documentation.  The creators of SubSonic are not.  They are quite keen of being “clever.”

Take for example the first bit you’re likely to read at SubSonic’s webpage, bit which I presume is meant to explain what SubSonic does.  “SubSonic is A Super High-fidelity Batman Utility Belt that works up your Data Access…”  I like Batman, especially since Christopher Nolan rebooted the franchise.  But I don’t care about Batman with relation to software projects.  I still don’t really know what SubSonic is after having read that.  Is it an ORM?  Is it a set of functions similar to MySQL access in PHP?  I don’t know, and they don’t seem to want to tell me.

I can stomach cleverness to about the same degree I can stomach horseradish.  It ought to enhance the content, and it can in the right hands.  The SubSonic authors WAY overdo it, and their writing style hides all the content behind a shroud of utter nonsense.  Hopefully they code better than they write English (a common engineering foible shared by this author as well).

They also use a LOT of screencasts.  Screencasts have their place, when done well (example).  However, the 1 that I’ve looked into up to this point goes on about how easy it is to set up SubSonic while scrolling past the code the author is adding after about 1 second.  Screencasts don’t have the best pause mechanism, so it’ s pretty easy to miss what the author is typing.  You also can’t copy/paste from a screencast.

More will follow.  Since there isn’t actually anything useful on how to set SubSonic up in a client application, and that’s what I’m writing, I’ll do that once and if I figure it out.  The frustration had risen to a point where I needed to vent, and where better than the solitude of a blog?

Monty Python has nothing on Russia or Taking issue with Akismet

September 19th, 2009

Akismet has been rocking my socks in spam prevention, but at present I’m finding it a bit lacking. A swarm of spam messages has been attempting to find its way onto my fair pages. Because I care so much about all 1.7 of you who come here on average and the integrity of Google’s search engine, I want to make sure those comments don’t see the light of day.  All comments from someone who hasn’t yet had a comment posted here require my approval.  Given my large volume of readers with the never-ending stream of comments, I realize what a labor of love it is for me to devote my every waking moment to filtering out spam, but I’m just that kind of guy.

So what’s the issue?  Well, all of the spammers post pretty much the same message.  It shows up in my browser as “??????? ?? ???????? ?? ?????,” or something like that, and all the associated URLs end in .ru.  Now, I don’t speak Russian– let’s get that right there– so what I say next doesn’t carry the same authority it would if those URLs ended in “.fr.”  For some reason I imagine written Russian having more than a single character at its disposal as opposed to this Morse code variant.  Perhaps some of you non-spammer Russian speakers out there can confirm this.

Why can’t Akismet pick up on this?  Russian link farm with no message content– seems like a no-brainer to me. The only thing I can figure is that the messages contain more than just question marks, but I don’t have the right alphabet installed on my computer. Which is just as well. I don’t want to learn how Viagra ads are written in Russian until and if I learn Russian for real.

For the time being I’ve shut down comments on my Apple Strikes Again post to see if that can exorcise the demon, comrade.

Deserves a pizza #3

August 27th, 2009

For helping me figure out why YourSQL stopped working (giving me a “No document could be created” error), my hat is off to oae.  It’s a Java thing. YourSQL doesn’t play well with Java 6, which I had set my computer to use.  The only thing I could add to oae’s post is that to change the Java settings on OSx, go to Applications->Utilities->Java->Java Preferences.  Then drag Java 5 to the top of the list.

So hopefully the 5 visitors I’ve had here will lend me enough Google street cred that this link to your blog brings you .3 visitors.

If you wonder why I was using your sequel or whether or not you had even written the first work requiring a sequel, then I can say with at least .9 certainty that this post doesn’t apply to you.

i(Tunes | Pod) deficiency or Deserves a Pizza #2

July 31st, 2009

Apple, the reigning champion of “intuitive” design, strikes again has another winner.

“Podcast” is a useless, branded neologism for audio files that come out on a regular basis.  Nevertheless, audio files that come out on a regular basis are enjoyable.  I “subscribe” to the Dave Ramseypodcast.”  I also bike to work.  Those may seem unrelated, but in fact the latter is the cause of the former.

Biking to work falls into the high-risk class of activities, but is closer to the moderate-risk class than, say, sky diving without a parachute.  Folks who don’t bike to work don’t much notice those who do. I’m all for live and let live, but this lack of attention can sometimes break that pattern for bikers.  The point is that just how a pregnant woman has to eat for 2, I have to pay attention for 2, or 3, or 4, depending on how many motorized vehicles cross my path during my commute.  That payment of attention only requires a visual debit, leaving many spare brain cycles during which my mind sits idle.  I like to fill that with sound.  Sound where I learn something is even better.

Enter audio files that come out regularly.  But sometimes I don’t listen to the Dave Ramsey audio files that come out on a regular basis, giving me a backlog.  This means that there’s more than that I haven’t heard.  Now, the genius of mp3 players is that they hold more than 1 song, and mp3 players can, generally, play all their contents without user attention between each track.

Enter the iPod.

Audio files that come out regularly are a magical class of audio file for the iPod.  The iPod, by default, cannot play 1 such audio file and then go on to the next without user interaction.  In fact, at the end of 1 such track, it repeats the same track, even though the menu is showing a list of all availabe Dave Ramsey audio files that come out on a regular basis.  Now, I realize that desiring this feature just means I’m using the iPod wrong, because only holiness emanates from Cupertino.  Nonetheless, academic freedom dictates that I must challenge such dogmas and question all authority.

Assuming all cows are perfect spheres, this as a default behavior makes perfect sense.  And it gets better!  If we define “intuitive” as “difficult” or “requires somewhere-above-average-but-less-than-expert knowledge of system to use,” then Apple has provided an intuitive way to overcome this problem.  This blog post describes the solution.  I mean, who wouldn’t have thought to create a “Smart Playlist” to do something so basic complicated as playing the next track?  Who actually uses their mp3 player that way anyway?

However, if not all cows are, in fact, perfect spheres and we define “intuitive” the same way that Merriam-Webster does, then to get the next track to play, one should just have the next track on the device.  Ergo, this is an Apple fail.

Conclusions:

  1. danandchoka deserve a pizza.
  2. The fact that goole has just over 400k hits for “ipod podcast play next” seems to indicate that I’m not alone in this problem.

Besides venting another Apple-related spleen, I wrote this post to bump up danandchoka’s post.  I really did appreciate finding the answer to this problem.

Deserves a pizza inaugural post

July 17th, 2009

A new category of post.  People who deserve a pizza.

For helping my out of my can’t-install-mysql-gem problem, I present to you http://marcgrabanski.com/article/installing-mysql-ruby-gem-mac-media-temple-dv.

Use of a mac will be forgiven for pure awesomeness.

I was getting errors along the lines of:

Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no

uninitialized constant Thin::Server::Forwardable

July 2nd, 2009

I may be getting batty in my old age here, but for whatever reason Thin decided to just stop running on my system.  When trying to invoke thin to further development on the code behind my awesome website, I was treated to the following:


ethan:ethang juanpaco$ thin start
/Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:51: uninitialized constant Thin::Server::Forwardable (NameError)
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:38:in `initialize'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/bin/thin:6:in `new'
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

I didn’t like that.

I went to the line number where the error occurred (/Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:51), and found:
extend Forwardable

Not knowing what Forwardable was, and for giggles, I went to irb and typed “Forwardable” thinking I’d get the class object.  Not defined.  So I try “require ‘forwardable’.”  There was no period in what I typed, but I haven’t figured out how to get Ruby and English to play well together.  Anyway, that worked, and a subsequent typing of “Forwardable” returned the object. So then I tried putting require ‘forwardable’ at the top of server.rb in thin’s gem.

And then it worked.

I’m not sure why it used to work and then suddenly didn’t.  This was after several install/uninstall, swear off programming moments.  Weird.  So, if you’re struggling with this same problem, perhaps the above can be of service.

Deleting a remote branch it git

December 18th, 2008

This is another “command I always forget and want a reference to” post.

To delete a remote branch, type: git push origin :<branch name>.