Padawan coder

Getting from zero to hero...

Decrypting Thinking Sphinx

| Comments

3 things to be aware of when installing Thinking Sphinx


My key takeaway from installing the Thinking Sphinx gem for a project, is that Thinking Sphinx is extremely finickety.

The steps seem simple enough on the Thinking Sphinx documentation website, but many errors and hours later, I can attest that it is full of pitfalls for the unwary, or the plain unlucky.

Our initial steps to install Thinking Sphinx for Rails 3.1 and above - which threw a bunch of errors - were to do the following:
1) brew install sphinx
2) brew install mysql
3) added the following to the Gemfile
- gem ‘mysql2’
- gem ‘thinking-sphinx’

Things I learnt from my experience are as follows:

1) You need to have a specific (older) version of MySQL installed (5.5.28)

Initially Sphinx threw its toys out of the pram because it couldn’t find the correct version of MySQL because brew had automatically installed the latest version of MySQL (5.6.10)

We downloaded 5.5.30 from dev.mysql.com. Or alternatively, you can follow the instructions on this gist to install older versions of mysql using Homebrew. This ushered in the next set of fairly obscure errors.

2) When using Thinking Sphinx with a Postgres database (which we are doing for our project), install Sphinx with both the mysql and postgres flags

The next set of errors from our attempt to debug and install TS, were mostly variants of: ‘ERROR: source ‘location_core_0’: unknown type ‘mysql’ ; skipping’, ‘Can't connect to MySQL server [or client or lib]’

Although the docs say that Sphinx will automatically detect whether you have MySQL of PostgresSQL, that wasn’t the case for us.

And the only combination that worked was brew install sphinx -–mysql -–pgsql (we had tried all the other permutations before this one finally worked, sort of).

3) Follow the gem version to the letter

After the installation of sphinx, bundling of gems, and running of rake ts:index and rake ts:start, we ran our search in rails console, which returned a Thinking Sphinx object #<ThinkingSphinx::Search:0x3fc3d2550958>, which resulted in the error undefined method `next_result' for #<Mysql2::Client:0xac86a54>

We eventually found the solution in Thinking Sphinx’s github issues. Our mistake had been to assume that Thinking Sphinx would work with the latest releases of mysql and thinking-sphinx gems, which is why we had not included the specific gem version in our Gemfile.

But Thinking Sphinx was pernickety enough to require the exact version ‘0.3.12b5’ of ‘mysql2’ (yes, down to ‘b5’!).

Resources:
http://pat.github.io/thinking-sphinx/
https://github.com/pat/thinking-sphinx

Exception Notifications in Production

| Comments

Source: XKCD

The last couple of weeks at Flatiron School, we have been split into groups to work on group projects. Anthony, Eugene, Jane, and I have been working on Handrai.se, an in-class question-workflow-management app. In the process of deploying our group’s app, we’ve come to realise that what works perfectly in development, doesn’t always work quite so smoothly in production, because real-life users don’t behave the way we assume they do in our seed file and development testing.

And unlike in development, in production, Rails errors are completely cryptic and uninformative:

To get a more informative error message, you would need to log into the server, and into the ‘current’ folder and type in: tail -f log/production.log

But what if you don’t personally encounter the error?

Avi suggested using an ‘Exception Notifier’ gem to get automatically notified each time an error is triggered in production.

Rails 3 Authentication for N00bs

| Comments

Progressing my ToDoList app - making it work, making it right

Source: On picking a perfect password by Euroscientist

Since I have a sieve-like memory, I really need to take detailed notes and practice practice in order to remember how to do things. Hence, I am trying to apply what we’ve learned through lectures in my ToDoList ‘practice’ app, especially on areas that I haven’t had a chance to personally code in our current group ‘Hand Raise’ project.

At the end of my previous blog post on my ToDoList app, my next steps were to:
1) Change the navigation links so they are conditional
2) Add authorization for Users to create, edit and delete tasks

But before authorizing users, we first need to authenticate users, and this will be the main body of my post (making it work). The remainder of my post (making it right) is about refactoring, conditionally displaying links and some validation pitfalls that tripped me up.

Front-end Form Validation - My Top 3 JQuery APIs

| Comments

Last week, we had Jonathan Grover guest lecture us for a week on Javascript and JQuery.

It was a really interesting week during which we learnt how useful Javascript is in improving the user interface and experience, how JQuery resolves issues around Javascript cross-browser compatibility, and applied Javascript and JQuery in many contexts, including interacting with Twitter, Flickr and Google Maps APIs.

One of the practical applications of Javascript / JQuery was in form validations, which we combined with back-end Rails validation. While back-end validation is used to ensure data integrity, front-end validation is used to provide end-users with timely feedback to create a more positive user-experience.

My Top 4 Rails Tricks in My First Rails App

| Comments

Make it work, make it right, …

We began learning Rails last week at the Flatiron School, with lectures and a couple of guided Rails labs / tutorials.

In this post, I will outline the key development stages* of my first ever non-guided , albeit simple, Rails app (a ToDoList app) and my top tricks & workarounds for the current version of the app.

TL;DR:
Top 4 tricks: f.select ; f.hidden_field, to_param, button_to

The Full Monty…

Thinking of Learning to Code?

| Comments

My perspectives – why I’m learning to code at the Flatiron School

Thinking of learning to code, and wondering if it’s worth the trouble, or if you should go solo or sign up to a course?

I’ve wrestled with these questions before and this post outlines my thought process and why I’m learning to code at the Flatiron School:
global imperative – coding is the new literacy
personal imperative – empowerment rocks, impotence enrages
optional – exponential learning

All Equalities Are Equal…

| Comments

…but some are more equal than others

I started on this trail because I’m a pedant about spelling, and got stuck on Ruby Monk’s first Boolean exercise.

Why was the following solution invalid >> name.equal?("Bob")
and this solution valid instead? >> name.eql?("Bob")

This set me off researching Ruby equality operators.
There seems to be four types of equality operators:-
’==’
‘.eql?’
‘.equal?’
’===’

And so it would seem, to misquote George Orwell, that some equalities are more equal than others.

Hello World

| Comments

Starting from zero.

Avi gave a talk on the History of Code at today, and one of the programmers he quoted was Larry Wall, who once said, tongue-in-cheek, that:

The three chief virtues of a programmer are: Laziness, Impatience and Hubris.

On that basis, I definitely qualify! ;)