Skip to content

Instantly share code, notes, and snippets.

View terenceponce's full-sized avatar

Terence Ponce terenceponce

View GitHub Profile
@terenceponce
terenceponce / a_problem.md
Created November 11, 2012 04:24
Content appears in my browser, but not in my test

I can see the content fine in my browser, but it doesn't appear in the the test. I checked the page with save_and_open_page and the categories that I created isn't in the generated page. What am I missing here?

This is the error that I'm getting:

  1. Categories index page when the user is signed in should be able to see a list of categories Failure/Error: page.should have_content category1.name expected there to be content "category-1" in "Gastos\n\n\n\n\n\n\n\n\nGastos\n\n\nHome\n\n\nAbout\n\n\nContact\n\n\n\nLogged in as\nfoo2@example.com\n\nEdit profile\nSign Out\n\n\n\n\n\n\n\nBrowse Categories\nName\n\n\n\n"

    ./spec/requests/categories_spec.rb:19:in `block (4 levels) in <top (required)>'

@terenceponce
terenceponce / instructions.md
Created September 26, 2012 08:25
Setting up Thinking-Sphinx on Mac OS X using Homebrew

Out of the box, Homebrew does a default installation on Sphinx:

$ brew install sphinx

However, if you're using MySQL, the thinking-sphinx gem won't work because it needs to use MySQL libraries.

If you managed to screw up the first time, uninstall sphinx first:

$ brew remove sphinx

@terenceponce
terenceponce / problem.md
Created September 5, 2012 07:30
Implementing a decent trending algorithm in Rails

I'm trying to implement a trending feature. The trending feature is based on searches that have become viral in a span of 4 hours. It will get the 6 latest popular searches.

Of course, to pull that off, I created a model called Search that has a keyword field. Every search done on the application will be stored as one row in the Search table.

At the moment, this is what I'm doing to retrieve the keywords to be classified as trending:

@popular_search = Search.where('created_at >= ?', 4.hours.ago).group(:keyword).order('count_keyword DESC').limit(6).count(:keyword)
@terenceponce
terenceponce / database.yml
Created August 27, 2012 05:24
Rails 3 PostgreSQL sample config
development:
adapter: postgresql
encoding: unicode
database: applicationname_development
host: localhost
pool: 5
username: postgres
password: postgres
test:
@terenceponce
terenceponce / something.rb
Created August 14, 2012 14:06
What's the best way to retrieve tweets that are on a given timeframe?
def live_tweets
tweets = Twitter.user_timeline(self.twitter_username, :include_entities => true)
max_id = nil
since_id = nil
last_id = nil
tweets.each do |tweet|
if tweet.created_at.utc <= self.time_end.utc
max_id = tweet.id
break
@terenceponce
terenceponce / problem.md
Created August 13, 2012 11:31
Twitter gem error: unauthorized

I can't follow/unfollow users with the Twitter gem because Twitter could not authenticate me.

I've written the Twitter app credentials in config/config.yml and I've loaded it in config/initializers/app_config.rb:

APP_CONFIG = YAML.load_file(Rails.root.join('config', 'config.yml'))

After I do Twitter.follow(username), I get a Twitter::Error::Unauthorized exception

Did I miss anything?

@terenceponce
terenceponce / index.html
Created July 19, 2012 05:52
jQuery Sortable issue in IE9
<!--
Error: Object doesn't support property or method 'attr'
-->
<div class='popover' id='playlist_menu'>
<ul class='toplay' style='overflow:auto'>
<li class='playlist_item' data-id='27' data-order='1' id='videos_27'></li>
<li class='playlist_item' data-id='1' data-order='2' id='videos_1'></li>
<li class='playlist_item' data-id='52' data-order='3' id='videos_52'></li>
</ul>
@terenceponce
terenceponce / database.yml
Created May 17, 2012 08:34
Rails 3 MySQL2 sample config
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: projectname_development
pool: 5
host: localhost
username: username
password: password
@terenceponce
terenceponce / _article.html.erb
Created April 10, 2012 08:56
Having trouble in testing CanCan
<% if can? :update, article %>
<%= link_to 'Edit', edit_article_path(article) %>
<% end %>
<% if can? :destroy, article %>
<%= link_to 'Destroy', article_path(article), :confirm => 'Are you sure?', :method => :delete %>
<% end %>
@terenceponce
terenceponce / _article.html.erb
Created April 6, 2012 04:59
Link appears in the browser, but the test says it's not there
<% if user_signed_in? %>
<% if current_user.id == article.author.id %>
<%= link_to 'Edit article', edit_article_path(article) %>
<% end %>
<% end %>