Running Thinking Sphinx, with Mysql and Postgres on OSX Snow Leopard

Having installed Thinking Sphinx for a project that used postgres, I had trouble running it with mysql. I tried editing some configuration files, both for my project and even tried the global config for TS but to no avail, it kept complaining that it didn’t know the type = mysql.

This led me to think(coupled with the answer for my SO question) that I must’ve compiled my TS before specifically for postgres only so I set off to recompile said thing for both.

./configure ran fine though, but it had problems when I tried make, because it was complaining I wasn’t using the right architecture. I then realized the mysql installed in my machine was x86, when in fact what I needed was the 64-bit version.

I then downloaded the 64-bit version for macosx and installed. I then tried to make TS again and voila! It installed perfectly. Now I was itching to index my database, but a new error popped out:

ERROR: index 'prospect_delta': sql_range_query: Out of sort memory; increase server sort buffer size

Using some google-fu, I finally nailed it down to this command:

sudo mysqld_safe --key_buffer_size=16M --sort_buffer_size=1M

which sets your buffer size a bit higher for the indexing. Whew!

Alphabar on Rails

I am working on this little project right now using Ruby on Rails and I ran into some trouble with the alphabar plugin. First, alphabar uses the with_scope method which, since Rails 2.0 I believe, has been protected, giving me some errors since I froze my Rails version. I was able to overcome this obstacle by using the send method instead. Just change the last part of the find method of the plugin from:

model.with_scope({:find => {:conditions => conditions}})
{model.find :all}


model.send(:with_scope, {:find => {:conditions => conditions}})
{model.find :all}

After I finally got that to work the plugin was very useful, although the alphabar was limited to letters and blank which is useful if you don’t need numbers. To accomodate numbers just add this to the alphabar helper:

('0'..'9').to_a.each do |i|
slots << i

Theoretically it should work for any character but I haven’t tried it yet.

So there you have it. Hoepfully somebody having trouble with this plugin will find this post useful.

nl2br in RoR

I recently found out that line breaks are not recognized when displaying a large block of text on the view (e.g. a post body). In PHP this was handled by the nl2br method but I had no luck finding a similar function in RoR. So I did what any sane person would do, create one myself. I placed this method in our model to format a particular field but it seems a better choice to put it in a helper.

def nl2br(text)

return text.gsub(/\n/, ‘<br/>’)


And there you have it, your very own nl2br method. Either you just found something really useful or I just wasted 2 minutes of your time. If anyone has a better solution or if I missed a function for this let us know by dropping a comment.

Small But Terrible

I’m pretty sure most of us have been in a situation where we have been trying to fix a bug for hours and finally seeing that there had just been some tiny typo or maybe even a commented line of code. I’ve been through a lot of those experiences before, especially when I was still learning to code, and most of the time, I just breathe out a huge sigh of relied or just plainly laugh at myself.

Reminiscing about those ‘good old days’ could be fun too. Here’s some of those ‘what the hell/oh come on/I knew it was just a simple mistake!’ scenarios that I have experienced or just know of:

These are just some of the mistakes that we can encounter while coding and minimizing the chances of these happening can help in coding a lot faster and having more time dealing with bugs that matter.