Archive for category Ruby on Rails

Full text search on Heroku

If you want to have full text search capability on Heroku, you should definitely use texticle or acts_as_tsearch. It is possible to use acts_as_farret on Heroku, but since you can only write to /tmp directory and your index file will be deleted sooner or later, you should not use it.

I first used texticle, and later switched over to acts_as_tsearch because I wasn’t happy with performance. Acts_as_tsearch is working really fine for me, and since your database on Heroku is already Postgres, there should be minimal configuration required. I even switched my local database from MySQL to Postgres to make both development and production environments consistent.

Post to Twitter

Tags: , ,

Path of enlightenment to Ruby

For all those who are learning Ruby, please do yourself a favor and follow the path described below.

http://github.com/edgecase/ruby_koans

Post to Twitter

Tags:

My answer to text-dynamo

As an exercise to practice Ruby, you can try to compete a random text generator using an underlying Markov chain model. The codes in the following github account are incomplete. You are supposed to fill in or create methods that will create randomly generated texts given seed texts.

http://github.com/eandrejko/text-dynamo

Markov chain is like a state machine, but the key is the what causes state transition only depends on the current state. In this case, how do you determine probability of selecting which word next? It’s quite simple. You go through the seed text and count frequency of next words, and that determines the frequency. For example, “am” is likely to folllow “I” most frequently. Next might be “do” or other verbs.

Read the rest of this entry »

Post to Twitter

Tags: , , ,

How to convert from MySQL to Postgres

I have been using MySQL for probably as long as I could remember. For Bloglation, search capability is an important feature since it’s hard to browse each post one by one. I will probably implement tagging functionality, but even so, it’s important to be able to search the contents with a keyword(s). While Ultrasphinx works well, Heroku only supports WebSolr… I was using acts_as_ferret using /tmp for index files, but the problem using the /tmp directory is that ferret index files most likely to disappear at some point.

Then, I found out that Postgres supports full-text search and since Heroku uses Postgres, I could use other plug-ins like acts_as_tsearch or texticle for free. Free is important to me, since it’s not making any money.

Searching online, there are various ways to do it like Pivotal Labs’ script or Heroku’s Taps gem, but I wanted to do it in an old way like AEdifice to check everything is going alright at each step.

1. First thing to do is to backup MySQL

For me, it was important to backup preserving encoding, since it had many different languages. First I pulled db from Heroku thinking that I Read the rest of this entry »

Post to Twitter

Tags: , , , , ,

To mock or stub ‘open’ method

Don’t fool with Kernel call. Just use OpenURI.open_uri.

OpenURI.expects(:open_uri).returns("some content")

Post to Twitter

Tags:

Installing acts_as_ferret with pagination and deploying on Heroku

OMG!

This shouldn’t have been this difficult, but it has because while there are many cool tutorials are out there, they are mostly outdated, and for some reason, the instruction on Heroku was not accessible.

While I picked acts_as_ferret because Heroku supports it, many seemed to prefer Thinking Sphinx. So, if you are not constrained (like me with Heroku), you should try that out too.

1. Install acts_as_ferret

Full instruction is outlined on github, so you should check it out. You can also find the installation instruction and complete list of methods here, too.

While the instruction asks you to put version name, since Heroku only has version 0.4.3 installed, specifying a version will break it.

Read the rest of this entry »

Post to Twitter

Tags: , , , , , ,

Counting rows and modifying MySQL to work with Postgres or Heroku

Now I am moving on to Open Translation Project. I’ve done some translation work before, including one of Paul Graham’s essay – Why to not not start a startup. BTW, he finally made a link from the essay to my translation. I used Google Translate as base, but I couldn’t believe how bad the translation was. Yahoo’s Babel Fish was a little better, but not as much. That’s where I got the idea of creating this possibly massive project.

Anyhow, I wanted to find a way of selecting an article or blog that was translated the most. I had one model that stored basic information of original article/blog. Then its children are translations. So, I need to count rows of children with the same parent. In MySQL, I had the following statement in Rails.

@top_origs = OrigPost.find(:all,
                              :select => 'orig_posts.*, count(posts.id) as post_count',
                              :joins => 'left outer join posts on posts.orig_post_id = orig_posts.id',
                              :group => 'orig_posts.id',
                              :order => 'post_count DESC',
                              :limit => 5)

Read the rest of this entry »

Post to Twitter

Tags: , , ,

Duck Tape Programmer

I’ve first read Jamie’s response to Joel’s writing on him on Coders at Work. I didn’t think much of it, and then I had a chance to read Joel’s actual writing. It sort of coincided with another discussion I had with an aspiring entrepreneur I met yesterday. And I decided I like the term, duck tape programmer.

The aspiring entrepreneur I met had his opinion about certain Rails programmers, and that’s exactly who Joel described as “someone with a coffee mug”.  I don’t think it’s a matter of right or wrong, but about the whole approach towards programming. The entrepreneur said that he has met many smart programmers who can talk up the latest movement and fads in programming world, but when it’s time to deliver, they are stuck in their world, trying to come up with best looking code using the latest techniques. However, the kind of programmers most value to startups are those who just get things done.

Some of the cool things he said were,

Peter asked Zawinski, “Overengineering seems to be a pet peeve of yours.”

“Yeah,” he says, “At the end of the day, ship the fucking thing! It’s great to rewrite your code and make it cleaner and by the third time it’ll actually be pretty. But that’s not the point—you’re not here to write code; you’re here to ship products.”

My hero.

Duct tape programmers are pragmatic. Zawinski popularized Richard Gabriel’s precept of Worse is Better. A 50%-good solution that people actually have solves more problems and survives longer than a 99% solution that nobody has because it’s in your lab where you’re endlessly polishing the damn thing. Shipping is a feature. A really important feature. Your product must have it.

I think what Joel referred as duct tape programmers are hackers in Paul Graham’s definition. Just as I concur with Paul, I do with Joel on this. Hacker or duct tape programmer, I aspire to be the one who just gets things done.

I am going to buy that book, which has very similar cover as Founders at Work.

Sweet!

Post to Twitter

Tags: ,

Featured on Clickpass blog

Alright!

My tutorial blog about integrating Clickpass with a rails app was featured on Clickpass’ official blog. :)

http://blog.clickpass.com/2009/09/22/new-rails-tutorial-on-installing-clickpass/

Post to Twitter

Tags: ,

How to integrate Clickpass (and OpenID) with a Rails app

I saw Clickpass in action at the Hacker News, and I thought it was another great way to reduce another login account. I wanted to implement it for my Open Translation project.

However, when I tried to find tutorials for using Clickpass with a Rails app, I couldn’t find any! How could it be! The pesudo code example Clickpass provided was for Java, I think, and thus it wasn’t any help to me. I was completely lost.

Then I realized that in the core underlying architecture of Clickpass is OpenID. Then it all made sense to me. I found a great tutorial on OpenID and Authlogic on a Railscasts episode (I am not using Authlogic for my site, though, but for the Open Translation project, I probably will.). So the following is a mixture of the Railscasts episode, ruby-openid gem, open_id_authentication plugin and Clickpass setup.

1. Install the gem and the plugin.

sudo gem install ruby-openid

Read the rest of this entry »

Post to Twitter

Tags: , ,